OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 172 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
173 typedef typename Traits::Type::Literal LiteralT; | 173 typedef typename Traits::Type::Literal LiteralT; |
174 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 174 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
175 typedef typename Traits::Type::StatementList StatementListT; | 175 typedef typename Traits::Type::StatementList StatementListT; |
176 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; | 176 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; |
177 | 177 |
178 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 178 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
179 v8::Extension* extension, AstValueFactory* ast_value_factory, | 179 v8::Extension* extension, AstValueFactory* ast_value_factory, |
180 ParserRecorder* log, typename Traits::Type::Parser this_object) | 180 ParserRecorder* log, typename Traits::Type::Parser this_object) |
181 : Traits(this_object), | 181 : Traits(this_object), |
182 scope_(NULL), | 182 state_(NULL), |
183 function_state_(NULL), | 183 function_state_(NULL), |
184 extension_(extension), | 184 extension_(extension), |
185 fni_(NULL), | 185 fni_(NULL), |
186 ast_value_factory_(ast_value_factory), | 186 ast_value_factory_(ast_value_factory), |
187 log_(log), | 187 log_(log), |
188 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | 188 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. |
189 parsing_module_(false), | 189 parsing_module_(false), |
190 stack_limit_(stack_limit), | 190 stack_limit_(stack_limit), |
191 zone_(zone), | 191 zone_(zone), |
192 scanner_(scanner), | 192 scanner_(scanner), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 enum VariableDeclarationContext { | 243 enum VariableDeclarationContext { |
244 kStatementListItem, | 244 kStatementListItem, |
245 kStatement, | 245 kStatement, |
246 kForStatement | 246 kForStatement |
247 }; | 247 }; |
248 | 248 |
249 class Checkpoint; | 249 class Checkpoint; |
250 class ObjectLiteralCheckerBase; | 250 class ObjectLiteralCheckerBase; |
251 | 251 |
252 // --------------------------------------------------------------------------- | 252 // --------------------------------------------------------------------------- |
253 // FunctionState and BlockState together implement the parser's scope stack. | 253 // FunctionState and BlockState together implement the parser's scope stack. |
adamk
2016/07/18 17:14:45
Please update this comment to explain what ScopeSt
| |
254 // The parser's current scope is in scope_. BlockState and FunctionState | 254 // The parser's current scope is in scope_. BlockState and FunctionState |
255 // constructors push on the scope stack and the destructors pop. They are also | 255 // constructors push on the scope stack and the destructors pop. They are also |
256 // used to hold the parser's per-function and per-block state. | 256 // used to hold the parser's per-function and per-block state. |
257 class BlockState BASE_EMBEDDED { | 257 class ScopeState BASE_EMBEDDED { |
258 public: | 258 public: |
259 BlockState(Scope** scope_stack, Scope* scope) | 259 V8_INLINE Scope* scope() const { return scope_; } |
260 : scope_stack_(scope_stack), outer_scope_(*scope_stack) { | 260 |
261 *scope_stack_ = scope; | 261 protected: |
262 ScopeState(ScopeState** scope_stack, Scope* scope) | |
263 : scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) { | |
264 *scope_stack = this; | |
262 } | 265 } |
263 ~BlockState() { *scope_stack_ = outer_scope_; } | 266 ~ScopeState() { *scope_stack_ = outer_scope_; } |
267 | |
268 Zone* zone() const { return scope_->zone(); } | |
264 | 269 |
265 private: | 270 private: |
266 Scope** scope_stack_; | 271 ScopeState** scope_stack_; |
267 Scope* outer_scope_; | 272 ScopeState* outer_scope_; |
273 Scope* scope_; | |
274 }; | |
275 | |
276 class BlockState final : public ScopeState { | |
277 public: | |
278 BlockState(ScopeState** scope_stack, Scope* scope) | |
279 : ScopeState(scope_stack, scope) {} | |
268 }; | 280 }; |
269 | 281 |
270 struct DestructuringAssignment { | 282 struct DestructuringAssignment { |
271 public: | 283 public: |
272 DestructuringAssignment(ExpressionT expression, Scope* scope) | 284 DestructuringAssignment(ExpressionT expression, Scope* scope) |
273 : assignment(expression), scope(scope) {} | 285 : assignment(expression), scope(scope) {} |
274 | 286 |
275 ExpressionT assignment; | 287 ExpressionT assignment; |
276 Scope* scope; | 288 Scope* scope; |
277 }; | 289 }; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 | 339 |
328 // We are inside a block in which tail call expressions are allowed but | 340 // We are inside a block in which tail call expressions are allowed but |
329 // not yet inside a return statement. | 341 // not yet inside a return statement. |
330 kInsideValidBlock, | 342 kInsideValidBlock, |
331 | 343 |
332 // Tail call expressions are not allowed in the following blocks. | 344 // Tail call expressions are not allowed in the following blocks. |
333 kInsideTryBlock, | 345 kInsideTryBlock, |
334 kInsideForInOfBody, | 346 kInsideForInOfBody, |
335 }; | 347 }; |
336 | 348 |
337 class FunctionState BASE_EMBEDDED { | 349 class FunctionState final : public ScopeState { |
338 public: | 350 public: |
339 FunctionState(FunctionState** function_state_stack, Scope** scope_stack, | 351 FunctionState(FunctionState** function_state_stack, |
340 Scope* scope, FunctionKind kind, | 352 ScopeState** scope_stack, Scope* scope, FunctionKind kind, |
341 typename Traits::Type::Factory* factory); | 353 typename Traits::Type::Factory* factory); |
342 ~FunctionState(); | 354 ~FunctionState(); |
343 | 355 |
344 int NextMaterializedLiteralIndex() { | 356 int NextMaterializedLiteralIndex() { |
345 return next_materialized_literal_index_++; | 357 return next_materialized_literal_index_++; |
346 } | 358 } |
347 int materialized_literal_count() { | 359 int materialized_literal_count() { |
348 return next_materialized_literal_index_; | 360 return next_materialized_literal_index_; |
349 } | 361 } |
350 | 362 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 void next_function_is_parenthesized(bool parenthesized) { | 441 void next_function_is_parenthesized(bool parenthesized) { |
430 next_function_is_parenthesized_ = parenthesized; | 442 next_function_is_parenthesized_ = parenthesized; |
431 } | 443 } |
432 | 444 |
433 bool this_function_is_parenthesized() const { | 445 bool this_function_is_parenthesized() const { |
434 return this_function_is_parenthesized_; | 446 return this_function_is_parenthesized_; |
435 } | 447 } |
436 | 448 |
437 private: | 449 private: |
438 void AddDestructuringAssignment(DestructuringAssignment pair) { | 450 void AddDestructuringAssignment(DestructuringAssignment pair) { |
439 destructuring_assignments_to_rewrite_.Add(pair, (*scope_stack_)->zone()); | 451 destructuring_assignments_to_rewrite_.Add(pair, this->zone()); |
440 } | 452 } |
441 | 453 |
442 V8_INLINE Scope* scope() { return *scope_stack_; } | |
443 | |
444 void AddNonPatternForRewriting(ExpressionT expr, bool* ok) { | 454 void AddNonPatternForRewriting(ExpressionT expr, bool* ok) { |
445 non_patterns_to_rewrite_.Add(expr, (*scope_stack_)->zone()); | 455 non_patterns_to_rewrite_.Add(expr, this->zone()); |
446 if (non_patterns_to_rewrite_.length() >= | 456 if (non_patterns_to_rewrite_.length() >= |
447 std::numeric_limits<uint16_t>::max()) | 457 std::numeric_limits<uint16_t>::max()) |
448 *ok = false; | 458 *ok = false; |
449 } | 459 } |
450 | 460 |
451 // Used to assign an index to each literal that needs materialization in | 461 // Used to assign an index to each literal that needs materialization in |
452 // the function. Includes regexp literals, and boilerplate for object and | 462 // the function. Includes regexp literals, and boilerplate for object and |
453 // array literals. | 463 // array literals. |
454 int next_materialized_literal_index_; | 464 int next_materialized_literal_index_; |
455 | 465 |
(...skipping 10 matching lines...) Expand all Loading... | |
466 Scanner::Location super_location_; | 476 Scanner::Location super_location_; |
467 | 477 |
468 FunctionKind kind_; | 478 FunctionKind kind_; |
469 // For generators, this variable may hold the generator object. It variable | 479 // For generators, this variable may hold the generator object. It variable |
470 // is used by yield expressions and return statements. It is not necessary | 480 // is used by yield expressions and return statements. It is not necessary |
471 // for generator functions to have this variable set. | 481 // for generator functions to have this variable set. |
472 Variable* generator_object_variable_; | 482 Variable* generator_object_variable_; |
473 | 483 |
474 FunctionState** function_state_stack_; | 484 FunctionState** function_state_stack_; |
475 FunctionState* outer_function_state_; | 485 FunctionState* outer_function_state_; |
476 Scope** scope_stack_; | |
477 Scope* outer_scope_; | |
478 | 486 |
479 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; | 487 ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_; |
480 TailCallExpressionList tail_call_expressions_; | 488 TailCallExpressionList tail_call_expressions_; |
481 ReturnExprContext return_expr_context_; | 489 ReturnExprContext return_expr_context_; |
482 ZoneList<ExpressionT> non_patterns_to_rewrite_; | 490 ZoneList<ExpressionT> non_patterns_to_rewrite_; |
483 | 491 |
484 ZoneList<typename ExpressionClassifier::Error> reported_errors_; | 492 ZoneList<typename ExpressionClassifier::Error> reported_errors_; |
485 | 493 |
486 typename Traits::Type::Factory* factory_; | 494 typename Traits::Type::Factory* factory_; |
487 | 495 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 static int Precedence(Token::Value token, bool accept_IN) { | 792 static int Precedence(Token::Value token, bool accept_IN) { |
785 if (token == Token::IN && !accept_IN) | 793 if (token == Token::IN && !accept_IN) |
786 return 0; // 0 precedence will terminate binary expression parsing | 794 return 0; // 0 precedence will terminate binary expression parsing |
787 return Token::Precedence(token); | 795 return Token::Precedence(token); |
788 } | 796 } |
789 | 797 |
790 typename Traits::Type::Factory* factory() { | 798 typename Traits::Type::Factory* factory() { |
791 return function_state_->factory(); | 799 return function_state_->factory(); |
792 } | 800 } |
793 | 801 |
794 LanguageMode language_mode() { return scope_->language_mode(); } | 802 LanguageMode language_mode() { return scope()->language_mode(); } |
795 bool is_generator() const { return function_state_->is_generator(); } | 803 bool is_generator() const { return function_state_->is_generator(); } |
796 bool is_async_function() const { | 804 bool is_async_function() const { |
797 return function_state_->is_async_function(); | 805 return function_state_->is_async_function(); |
798 } | 806 } |
799 bool is_resumable() const { return function_state_->is_resumable(); } | 807 bool is_resumable() const { return function_state_->is_resumable(); } |
800 | 808 |
801 // Report syntax errors. | 809 // Report syntax errors. |
802 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, | 810 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, |
803 ParseErrorType error_type = kSyntaxError) { | 811 ParseErrorType error_type = kSyntaxError) { |
804 Scanner::Location source_location = scanner()->location(); | 812 Scanner::Location source_location = scanner()->location(); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1160 bool IsConstructor() { | 1168 bool IsConstructor() { |
1161 return this->scanner()->LiteralMatches("constructor", 11); | 1169 return this->scanner()->LiteralMatches("constructor", 11); |
1162 } | 1170 } |
1163 bool IsPrototype() { | 1171 bool IsPrototype() { |
1164 return this->scanner()->LiteralMatches("prototype", 9); | 1172 return this->scanner()->LiteralMatches("prototype", 9); |
1165 } | 1173 } |
1166 | 1174 |
1167 bool has_seen_constructor_; | 1175 bool has_seen_constructor_; |
1168 }; | 1176 }; |
1169 | 1177 |
1170 Scope* scope_; // Scope stack. | 1178 inline ModuleDescriptor* module() const { return scope()->module(); } |
1179 inline Scope* scope() const { return state_->scope(); } | |
adamk
2016/07/18 17:14:45
No need for these "inline"s, unless you want to V8
| |
1180 | |
1181 ScopeState* state_; // Scope stack. | |
adamk
2016/07/18 17:14:45
scope_state_ seems like the right name here, at le
| |
1171 FunctionState* function_state_; // Function state stack. | 1182 FunctionState* function_state_; // Function state stack. |
1172 v8::Extension* extension_; | 1183 v8::Extension* extension_; |
1173 FuncNameInferrer* fni_; | 1184 FuncNameInferrer* fni_; |
1174 AstValueFactory* ast_value_factory_; // Not owned. | 1185 AstValueFactory* ast_value_factory_; // Not owned. |
1175 ParserRecorder* log_; | 1186 ParserRecorder* log_; |
1176 Mode mode_; | 1187 Mode mode_; |
1177 bool parsing_module_; | 1188 bool parsing_module_; |
1178 uintptr_t stack_limit_; | 1189 uintptr_t stack_limit_; |
1179 | 1190 |
1180 private: | 1191 private: |
1181 Zone* zone_; | 1192 Zone* zone_; |
1182 | 1193 |
1183 Scanner* scanner_; | 1194 Scanner* scanner_; |
1184 bool stack_overflow_; | 1195 bool stack_overflow_; |
1185 | 1196 |
1186 bool allow_lazy_; | 1197 bool allow_lazy_; |
1187 bool allow_natives_; | 1198 bool allow_natives_; |
1188 bool allow_tailcalls_; | 1199 bool allow_tailcalls_; |
1189 bool allow_harmony_restrictive_declarations_; | 1200 bool allow_harmony_restrictive_declarations_; |
1190 bool allow_harmony_do_expressions_; | 1201 bool allow_harmony_do_expressions_; |
1191 bool allow_harmony_for_in_; | 1202 bool allow_harmony_for_in_; |
1192 bool allow_harmony_function_sent_; | 1203 bool allow_harmony_function_sent_; |
1193 bool allow_harmony_async_await_; | 1204 bool allow_harmony_async_await_; |
1194 bool allow_harmony_restrictive_generators_; | 1205 bool allow_harmony_restrictive_generators_; |
1195 bool allow_harmony_trailing_commas_; | 1206 bool allow_harmony_trailing_commas_; |
1196 }; | 1207 }; |
1197 | 1208 |
1198 template <class Traits> | 1209 template <class Traits> |
1199 ParserBase<Traits>::FunctionState::FunctionState( | 1210 ParserBase<Traits>::FunctionState::FunctionState( |
1200 FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, | 1211 FunctionState** function_state_stack, ScopeState** scope_stack, |
1201 FunctionKind kind, typename Traits::Type::Factory* factory) | 1212 Scope* scope, FunctionKind kind, typename Traits::Type::Factory* factory) |
1202 : next_materialized_literal_index_(0), | 1213 : ScopeState(scope_stack, scope), |
1214 next_materialized_literal_index_(0), | |
1203 expected_property_count_(0), | 1215 expected_property_count_(0), |
1204 this_location_(Scanner::Location::invalid()), | 1216 this_location_(Scanner::Location::invalid()), |
1205 return_location_(Scanner::Location::invalid()), | 1217 return_location_(Scanner::Location::invalid()), |
1206 super_location_(Scanner::Location::invalid()), | 1218 super_location_(Scanner::Location::invalid()), |
1207 kind_(kind), | 1219 kind_(kind), |
1208 generator_object_variable_(NULL), | 1220 generator_object_variable_(NULL), |
1209 function_state_stack_(function_state_stack), | 1221 function_state_stack_(function_state_stack), |
1210 outer_function_state_(*function_state_stack), | 1222 outer_function_state_(*function_state_stack), |
1211 scope_stack_(scope_stack), | |
1212 outer_scope_(*scope_stack), | |
1213 destructuring_assignments_to_rewrite_(16, scope->zone()), | 1223 destructuring_assignments_to_rewrite_(16, scope->zone()), |
1214 tail_call_expressions_(scope->zone()), | 1224 tail_call_expressions_(scope->zone()), |
1215 return_expr_context_(ReturnExprContext::kInsideValidBlock), | 1225 return_expr_context_(ReturnExprContext::kInsideValidBlock), |
1216 non_patterns_to_rewrite_(0, scope->zone()), | 1226 non_patterns_to_rewrite_(0, scope->zone()), |
1217 reported_errors_(16, scope->zone()), | 1227 reported_errors_(16, scope->zone()), |
1218 factory_(factory), | 1228 factory_(factory), |
1219 next_function_is_parenthesized_(false), | 1229 next_function_is_parenthesized_(false), |
1220 this_function_is_parenthesized_(false) { | 1230 this_function_is_parenthesized_(false) { |
1221 *scope_stack_ = scope; | |
1222 *function_state_stack = this; | 1231 *function_state_stack = this; |
1223 if (outer_function_state_) { | 1232 if (outer_function_state_) { |
1224 this_function_is_parenthesized_ = | 1233 this_function_is_parenthesized_ = |
1225 outer_function_state_->next_function_is_parenthesized_; | 1234 outer_function_state_->next_function_is_parenthesized_; |
1226 outer_function_state_->next_function_is_parenthesized_ = false; | 1235 outer_function_state_->next_function_is_parenthesized_ = false; |
1227 } | 1236 } |
1228 } | 1237 } |
1229 | 1238 |
1230 | 1239 |
1231 template <class Traits> | 1240 template <class Traits> |
1232 ParserBase<Traits>::FunctionState::~FunctionState() { | 1241 ParserBase<Traits>::FunctionState::~FunctionState() { |
1233 *scope_stack_ = outer_scope_; | |
1234 *function_state_stack_ = outer_function_state_; | 1242 *function_state_stack_ = outer_function_state_; |
1235 } | 1243 } |
1236 | 1244 |
1237 template <class Traits> | 1245 template <class Traits> |
1238 void ParserBase<Traits>::GetUnexpectedTokenMessage( | 1246 void ParserBase<Traits>::GetUnexpectedTokenMessage( |
1239 Token::Value token, MessageTemplate::Template* message, | 1247 Token::Value token, MessageTemplate::Template* message, |
1240 Scanner::Location* location, const char** arg, | 1248 Scanner::Location* location, const char** arg, |
1241 MessageTemplate::Template default_) { | 1249 MessageTemplate::Template default_) { |
1242 *arg = nullptr; | 1250 *arg = nullptr; |
1243 switch (token) { | 1251 switch (token) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1341 // error that we might make in the future once we know the language mode. | 1349 // error that we might make in the future once we know the language mode. |
1342 if (this->IsEval(name)) { | 1350 if (this->IsEval(name)) { |
1343 classifier->RecordStrictModeFormalParameterError( | 1351 classifier->RecordStrictModeFormalParameterError( |
1344 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1352 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1345 if (is_strict(language_mode())) { | 1353 if (is_strict(language_mode())) { |
1346 classifier->RecordBindingPatternError( | 1354 classifier->RecordBindingPatternError( |
1347 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1355 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1348 } | 1356 } |
1349 } | 1357 } |
1350 if (this->IsArguments(name)) { | 1358 if (this->IsArguments(name)) { |
1351 scope_->RecordArgumentsUsage(); | 1359 scope()->RecordArgumentsUsage(); |
1352 classifier->RecordStrictModeFormalParameterError( | 1360 classifier->RecordStrictModeFormalParameterError( |
1353 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1361 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1354 if (is_strict(language_mode())) { | 1362 if (is_strict(language_mode())) { |
1355 classifier->RecordBindingPatternError( | 1363 classifier->RecordBindingPatternError( |
1356 scanner()->location(), MessageTemplate::kStrictEvalArguments); | 1364 scanner()->location(), MessageTemplate::kStrictEvalArguments); |
1357 } | 1365 } |
1358 } | 1366 } |
1359 if (this->IsAwait(name)) { | 1367 if (this->IsAwait(name)) { |
1360 if (is_async_function()) { | 1368 if (is_async_function()) { |
1361 classifier->RecordPatternError( | 1369 classifier->RecordPatternError( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1409 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || | 1417 } else if (next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || |
1410 next == Token::STATIC || (next == Token::YIELD && !is_generator)) { | 1418 next == Token::STATIC || (next == Token::YIELD && !is_generator)) { |
1411 *is_strict_reserved = true; | 1419 *is_strict_reserved = true; |
1412 } else { | 1420 } else { |
1413 ReportUnexpectedToken(next); | 1421 ReportUnexpectedToken(next); |
1414 *ok = false; | 1422 *ok = false; |
1415 return Traits::EmptyIdentifier(); | 1423 return Traits::EmptyIdentifier(); |
1416 } | 1424 } |
1417 | 1425 |
1418 IdentifierT name = this->GetSymbol(scanner()); | 1426 IdentifierT name = this->GetSymbol(scanner()); |
1419 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); | 1427 if (this->IsArguments(name)) scope()->RecordArgumentsUsage(); |
1420 return name; | 1428 return name; |
1421 } | 1429 } |
1422 | 1430 |
1423 template <class Traits> | 1431 template <class Traits> |
1424 typename ParserBase<Traits>::IdentifierT | 1432 typename ParserBase<Traits>::IdentifierT |
1425 ParserBase<Traits>::ParseIdentifierName(bool* ok) { | 1433 ParserBase<Traits>::ParseIdentifierName(bool* ok) { |
1426 Token::Value next = Next(); | 1434 Token::Value next = Next(); |
1427 if (next != Token::IDENTIFIER && next != Token::ASYNC && | 1435 if (next != Token::IDENTIFIER && next != Token::ASYNC && |
1428 next != Token::ENUM && next != Token::AWAIT && next != Token::LET && | 1436 next != Token::ENUM && next != Token::AWAIT && next != Token::LET && |
1429 next != Token::STATIC && next != Token::YIELD && | 1437 next != Token::STATIC && next != Token::YIELD && |
1430 next != Token::FUTURE_STRICT_RESERVED_WORD && | 1438 next != Token::FUTURE_STRICT_RESERVED_WORD && |
1431 next != Token::ESCAPED_KEYWORD && | 1439 next != Token::ESCAPED_KEYWORD && |
1432 next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { | 1440 next != Token::ESCAPED_STRICT_RESERVED_WORD && !Token::IsKeyword(next)) { |
1433 this->ReportUnexpectedToken(next); | 1441 this->ReportUnexpectedToken(next); |
1434 *ok = false; | 1442 *ok = false; |
1435 return Traits::EmptyIdentifier(); | 1443 return Traits::EmptyIdentifier(); |
1436 } | 1444 } |
1437 | 1445 |
1438 IdentifierT name = this->GetSymbol(scanner()); | 1446 IdentifierT name = this->GetSymbol(scanner()); |
1439 if (this->IsArguments(name)) scope_->RecordArgumentsUsage(); | 1447 if (this->IsArguments(name)) scope()->RecordArgumentsUsage(); |
1440 return name; | 1448 return name; |
1441 } | 1449 } |
1442 | 1450 |
1443 | 1451 |
1444 template <class Traits> | 1452 template <class Traits> |
1445 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( | 1453 typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseRegExpLiteral( |
1446 bool seen_equal, ExpressionClassifier* classifier, bool* ok) { | 1454 bool seen_equal, ExpressionClassifier* classifier, bool* ok) { |
1447 int pos = peek_position(); | 1455 int pos = peek_position(); |
1448 if (!scanner()->ScanRegExpPattern(seen_equal)) { | 1456 if (!scanner()->ScanRegExpPattern(seen_equal)) { |
1449 Next(); | 1457 Next(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1500 // '(' Expression ')' | 1508 // '(' Expression ')' |
1501 // TemplateLiteral | 1509 // TemplateLiteral |
1502 // do Block | 1510 // do Block |
1503 // AsyncFunctionExpression | 1511 // AsyncFunctionExpression |
1504 | 1512 |
1505 int beg_pos = peek_position(); | 1513 int beg_pos = peek_position(); |
1506 switch (peek()) { | 1514 switch (peek()) { |
1507 case Token::THIS: { | 1515 case Token::THIS: { |
1508 BindingPatternUnexpectedToken(classifier); | 1516 BindingPatternUnexpectedToken(classifier); |
1509 Consume(Token::THIS); | 1517 Consume(Token::THIS); |
1510 return this->ThisExpression(scope_, factory(), beg_pos); | 1518 return this->ThisExpression(scope(), factory(), beg_pos); |
1511 } | 1519 } |
1512 | 1520 |
1513 case Token::NULL_LITERAL: | 1521 case Token::NULL_LITERAL: |
1514 case Token::TRUE_LITERAL: | 1522 case Token::TRUE_LITERAL: |
1515 case Token::FALSE_LITERAL: | 1523 case Token::FALSE_LITERAL: |
1516 BindingPatternUnexpectedToken(classifier); | 1524 BindingPatternUnexpectedToken(classifier); |
1517 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); | 1525 return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); |
1518 case Token::SMI: | 1526 case Token::SMI: |
1519 case Token::NUMBER: | 1527 case Token::NUMBER: |
1520 BindingPatternUnexpectedToken(classifier); | 1528 BindingPatternUnexpectedToken(classifier); |
(...skipping 12 matching lines...) Expand all Loading... | |
1533 case Token::IDENTIFIER: | 1541 case Token::IDENTIFIER: |
1534 case Token::LET: | 1542 case Token::LET: |
1535 case Token::STATIC: | 1543 case Token::STATIC: |
1536 case Token::YIELD: | 1544 case Token::YIELD: |
1537 case Token::AWAIT: | 1545 case Token::AWAIT: |
1538 case Token::ESCAPED_STRICT_RESERVED_WORD: | 1546 case Token::ESCAPED_STRICT_RESERVED_WORD: |
1539 case Token::FUTURE_STRICT_RESERVED_WORD: { | 1547 case Token::FUTURE_STRICT_RESERVED_WORD: { |
1540 // Using eval or arguments in this context is OK even in strict mode. | 1548 // Using eval or arguments in this context is OK even in strict mode. |
1541 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); | 1549 IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK); |
1542 return this->ExpressionFromIdentifier( | 1550 return this->ExpressionFromIdentifier( |
1543 name, beg_pos, scanner()->location().end_pos, scope_, factory()); | 1551 name, beg_pos, scanner()->location().end_pos, scope(), factory()); |
1544 } | 1552 } |
1545 | 1553 |
1546 case Token::STRING: { | 1554 case Token::STRING: { |
1547 BindingPatternUnexpectedToken(classifier); | 1555 BindingPatternUnexpectedToken(classifier); |
1548 Consume(Token::STRING); | 1556 Consume(Token::STRING); |
1549 return this->ExpressionFromString(beg_pos, scanner(), factory()); | 1557 return this->ExpressionFromString(beg_pos, scanner(), factory()); |
1550 } | 1558 } |
1551 | 1559 |
1552 case Token::ASSIGN_DIV: | 1560 case Token::ASSIGN_DIV: |
1553 classifier->RecordBindingPatternError( | 1561 classifier->RecordBindingPatternError( |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1959 classifier->RecordPatternError( | 1967 classifier->RecordPatternError( |
1960 Scanner::Location(next_beg_pos, next_end_pos), | 1968 Scanner::Location(next_beg_pos, next_end_pos), |
1961 MessageTemplate::kAwaitBindingIdentifier); | 1969 MessageTemplate::kAwaitBindingIdentifier); |
1962 } else { | 1970 } else { |
1963 classifier->RecordAsyncArrowFormalParametersError( | 1971 classifier->RecordAsyncArrowFormalParametersError( |
1964 Scanner::Location(next_beg_pos, next_end_pos), | 1972 Scanner::Location(next_beg_pos, next_end_pos), |
1965 MessageTemplate::kAwaitBindingIdentifier); | 1973 MessageTemplate::kAwaitBindingIdentifier); |
1966 } | 1974 } |
1967 } | 1975 } |
1968 ExpressionT lhs = this->ExpressionFromIdentifier( | 1976 ExpressionT lhs = this->ExpressionFromIdentifier( |
1969 *name, next_beg_pos, next_end_pos, scope_, factory()); | 1977 *name, next_beg_pos, next_end_pos, scope(), factory()); |
1970 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); | 1978 CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos); |
1971 | 1979 |
1972 if (peek() == Token::ASSIGN) { | 1980 if (peek() == Token::ASSIGN) { |
1973 Consume(Token::ASSIGN); | 1981 Consume(Token::ASSIGN); |
1974 ExpressionClassifier rhs_classifier(this); | 1982 ExpressionClassifier rhs_classifier(this); |
1975 ExpressionT rhs = this->ParseAssignmentExpression( | 1983 ExpressionT rhs = this->ParseAssignmentExpression( |
1976 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1984 true, &rhs_classifier, CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1977 Traits::RewriteNonPattern(&rhs_classifier, | 1985 Traits::RewriteNonPattern(&rhs_classifier, |
1978 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); | 1986 CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); |
1979 classifier->Accumulate(&rhs_classifier, | 1987 classifier->Accumulate(&rhs_classifier, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2266 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 2274 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
2267 } | 2275 } |
2268 ExpressionT expression = this->ParseConditionalExpression( | 2276 ExpressionT expression = this->ParseConditionalExpression( |
2269 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2277 accept_IN, &arrow_formals_classifier, CHECK_OK); |
2270 | 2278 |
2271 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { | 2279 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { |
2272 // async Identifier => AsyncConciseBody | 2280 // async Identifier => AsyncConciseBody |
2273 IdentifierT name = | 2281 IdentifierT name = |
2274 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); | 2282 ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); |
2275 expression = this->ExpressionFromIdentifier( | 2283 expression = this->ExpressionFromIdentifier( |
2276 name, position(), scanner()->location().end_pos, scope_, factory()); | 2284 name, position(), scanner()->location().end_pos, scope(), factory()); |
2277 } | 2285 } |
2278 | 2286 |
2279 if (peek() == Token::ARROW) { | 2287 if (peek() == Token::ARROW) { |
2280 Scanner::Location arrow_loc = scanner()->peek_location(); | 2288 Scanner::Location arrow_loc = scanner()->peek_location(); |
2281 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, | 2289 ValidateArrowFormalParameters(&arrow_formals_classifier, expression, |
2282 parenthesized_formals, is_async, CHECK_OK); | 2290 parenthesized_formals, is_async, CHECK_OK); |
2283 // This reads strangely, but is correct: it checks whether any | 2291 // This reads strangely, but is correct: it checks whether any |
2284 // sub-expression of the parameter list failed to be a valid formal | 2292 // sub-expression of the parameter list failed to be a valid formal |
2285 // parameter initializer. Since YieldExpressions are banned anywhere | 2293 // parameter initializer. Since YieldExpressions are banned anywhere |
2286 // in an arrow parameter list, this is correct. | 2294 // in an arrow parameter list, this is correct. |
2287 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to | 2295 // TODO(adamk): Rename "FormalParameterInitializerError" to refer to |
2288 // "YieldExpression", which is its only use. | 2296 // "YieldExpression", which is its only use. |
2289 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); | 2297 ValidateFormalParameterInitializer(&arrow_formals_classifier, ok); |
2290 | 2298 |
2291 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); | 2299 Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); |
2292 Scope* scope = this->NewScope(scope_, FUNCTION_SCOPE, | 2300 Scope* scope = this->NewScope(this->scope(), FUNCTION_SCOPE, |
2293 is_async ? FunctionKind::kAsyncArrowFunction | 2301 is_async ? FunctionKind::kAsyncArrowFunction |
2294 : FunctionKind::kArrowFunction); | 2302 : FunctionKind::kArrowFunction); |
2295 // Because the arrow's parameters were parsed in the outer scope, any | 2303 // Because the arrow's parameters were parsed in the outer scope, any |
2296 // usage flags that might have been triggered there need to be copied | 2304 // usage flags that might have been triggered there need to be copied |
2297 // to the arrow scope. | 2305 // to the arrow scope. |
2298 scope_->PropagateUsageFlagsToScope(scope); | 2306 this->scope()->PropagateUsageFlagsToScope(scope); |
2299 FormalParametersT parameters(scope); | 2307 FormalParametersT parameters(scope); |
2300 if (!arrow_formals_classifier.is_simple_parameter_list()) { | 2308 if (!arrow_formals_classifier.is_simple_parameter_list()) { |
2301 scope->SetHasNonSimpleParameters(); | 2309 scope->SetHasNonSimpleParameters(); |
2302 parameters.is_simple = false; | 2310 parameters.is_simple = false; |
2303 } | 2311 } |
2304 | 2312 |
2305 checkpoint.Restore(¶meters.materialized_literals_count); | 2313 checkpoint.Restore(¶meters.materialized_literals_count); |
2306 | 2314 |
2307 scope->set_start_position(lhs_beg_pos); | 2315 scope->set_start_position(lhs_beg_pos); |
2308 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2316 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2710 // Possibly async arrow formals --- record ExpressionError just in case. | 2718 // Possibly async arrow formals --- record ExpressionError just in case. |
2711 ExpressionUnexpectedToken(classifier); | 2719 ExpressionUnexpectedToken(classifier); |
2712 classifier->RecordAsyncBindingPatternError( | 2720 classifier->RecordAsyncBindingPatternError( |
2713 Scanner::Location(beg_pos, scanner()->location().end_pos), | 2721 Scanner::Location(beg_pos, scanner()->location().end_pos), |
2714 MessageTemplate::kAwaitBindingIdentifier); | 2722 MessageTemplate::kAwaitBindingIdentifier); |
2715 classifier->RecordAsyncArrowFormalParametersError( | 2723 classifier->RecordAsyncArrowFormalParametersError( |
2716 Scanner::Location(beg_pos, scanner()->location().end_pos), | 2724 Scanner::Location(beg_pos, scanner()->location().end_pos), |
2717 MessageTemplate::kAwaitBindingIdentifier); | 2725 MessageTemplate::kAwaitBindingIdentifier); |
2718 | 2726 |
2719 return this->ExpressionFromIdentifier( | 2727 return this->ExpressionFromIdentifier( |
2720 name, beg_pos, scanner()->location().end_pos, scope_, factory()); | 2728 name, beg_pos, scanner()->location().end_pos, scope(), factory()); |
2721 } | 2729 } |
2722 default: | 2730 default: |
2723 break; | 2731 break; |
2724 } | 2732 } |
2725 | 2733 |
2726 int await_pos = peek_position(); | 2734 int await_pos = peek_position(); |
2727 Consume(Token::AWAIT); | 2735 Consume(Token::AWAIT); |
2728 | 2736 |
2729 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); | 2737 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); |
2730 | 2738 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2855 | 2863 |
2856 ArrowFormalParametersUnexpectedToken(classifier); | 2864 ArrowFormalParametersUnexpectedToken(classifier); |
2857 | 2865 |
2858 // Keep track of eval() calls since they disable all local variable | 2866 // Keep track of eval() calls since they disable all local variable |
2859 // optimizations. | 2867 // optimizations. |
2860 // The calls that need special treatment are the | 2868 // The calls that need special treatment are the |
2861 // direct eval calls. These calls are all of the form eval(...), with | 2869 // direct eval calls. These calls are all of the form eval(...), with |
2862 // no explicit receiver. | 2870 // no explicit receiver. |
2863 // These calls are marked as potentially direct eval calls. Whether | 2871 // These calls are marked as potentially direct eval calls. Whether |
2864 // they are actually direct calls to eval is determined at run time. | 2872 // they are actually direct calls to eval is determined at run time. |
2865 this->CheckPossibleEvalCall(result, scope_); | 2873 this->CheckPossibleEvalCall(result, scope()); |
2866 | 2874 |
2867 bool is_super_call = result->IsSuperCallReference(); | 2875 bool is_super_call = result->IsSuperCallReference(); |
2868 if (spread_pos.IsValid()) { | 2876 if (spread_pos.IsValid()) { |
2869 args = Traits::PrepareSpreadArguments(args); | 2877 args = Traits::PrepareSpreadArguments(args); |
2870 result = Traits::SpreadCall(result, args, pos); | 2878 result = Traits::SpreadCall(result, args, pos); |
2871 } else { | 2879 } else { |
2872 result = factory()->NewCall(result, args, pos); | 2880 result = factory()->NewCall(result, args, pos); |
2873 } | 2881 } |
2874 | 2882 |
2875 // Explicit calls to the super constructor using super() perform an | 2883 // Explicit calls to the super constructor using super() perform an |
2876 // implicit binding assignment to the 'this' variable. | 2884 // implicit binding assignment to the 'this' variable. |
2877 if (is_super_call) { | 2885 if (is_super_call) { |
2878 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 2886 ExpressionT this_expr = this->ThisExpression(scope(), factory(), pos); |
2879 result = | 2887 result = |
2880 factory()->NewAssignment(Token::INIT, this_expr, result, pos); | 2888 factory()->NewAssignment(Token::INIT, this_expr, result, pos); |
2881 } | 2889 } |
2882 | 2890 |
2883 if (fni_ != NULL) fni_->RemoveLastFunction(); | 2891 if (fni_ != NULL) fni_->RemoveLastFunction(); |
2884 break; | 2892 break; |
2885 } | 2893 } |
2886 | 2894 |
2887 case Token::PERIOD: { | 2895 case Token::PERIOD: { |
2888 CheckNoTailCallExpressions(classifier, CHECK_OK); | 2896 CheckNoTailCallExpressions(classifier, CHECK_OK); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3006 ExpectMetaProperty(CStrVector("sent"), "function.sent", pos, CHECK_OK); | 3014 ExpectMetaProperty(CStrVector("sent"), "function.sent", pos, CHECK_OK); |
3007 | 3015 |
3008 if (!is_generator()) { | 3016 if (!is_generator()) { |
3009 // TODO(neis): allow escaping into closures? | 3017 // TODO(neis): allow escaping into closures? |
3010 ReportMessageAt(scanner()->location(), | 3018 ReportMessageAt(scanner()->location(), |
3011 MessageTemplate::kUnexpectedFunctionSent); | 3019 MessageTemplate::kUnexpectedFunctionSent); |
3012 *ok = false; | 3020 *ok = false; |
3013 return this->EmptyExpression(); | 3021 return this->EmptyExpression(); |
3014 } | 3022 } |
3015 | 3023 |
3016 return this->FunctionSentExpression(scope_, factory(), pos); | 3024 return this->FunctionSentExpression(scope(), factory(), pos); |
3017 } | 3025 } |
3018 | 3026 |
3019 bool is_generator = Check(Token::MUL); | 3027 bool is_generator = Check(Token::MUL); |
3020 IdentifierT name = this->EmptyIdentifier(); | 3028 IdentifierT name = this->EmptyIdentifier(); |
3021 bool is_strict_reserved_name = false; | 3029 bool is_strict_reserved_name = false; |
3022 Scanner::Location function_name_location = Scanner::Location::invalid(); | 3030 Scanner::Location function_name_location = Scanner::Location::invalid(); |
3023 FunctionLiteral::FunctionType function_type = | 3031 FunctionLiteral::FunctionType function_type = |
3024 FunctionLiteral::kAnonymousExpression; | 3032 FunctionLiteral::kAnonymousExpression; |
3025 if (peek_any_identifier()) { | 3033 if (peek_any_identifier()) { |
3026 name = ParseIdentifierOrStrictReservedWord( | 3034 name = ParseIdentifierOrStrictReservedWord( |
(...skipping 22 matching lines...) Expand all Loading... | |
3049 | 3057 |
3050 | 3058 |
3051 template <class Traits> | 3059 template <class Traits> |
3052 typename ParserBase<Traits>::ExpressionT | 3060 typename ParserBase<Traits>::ExpressionT |
3053 ParserBase<Traits>::ParseSuperExpression(bool is_new, | 3061 ParserBase<Traits>::ParseSuperExpression(bool is_new, |
3054 ExpressionClassifier* classifier, | 3062 ExpressionClassifier* classifier, |
3055 bool* ok) { | 3063 bool* ok) { |
3056 Expect(Token::SUPER, CHECK_OK); | 3064 Expect(Token::SUPER, CHECK_OK); |
3057 int pos = position(); | 3065 int pos = position(); |
3058 | 3066 |
3059 Scope* scope = scope_->ReceiverScope(); | 3067 Scope* scope = this->scope()->ReceiverScope(); |
3060 FunctionKind kind = scope->function_kind(); | 3068 FunctionKind kind = scope->function_kind(); |
3061 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || | 3069 if (IsConciseMethod(kind) || IsAccessorFunction(kind) || |
3062 IsClassConstructor(kind)) { | 3070 IsClassConstructor(kind)) { |
3063 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { | 3071 if (peek() == Token::PERIOD || peek() == Token::LBRACK) { |
3064 scope->RecordSuperPropertyUsage(); | 3072 scope->RecordSuperPropertyUsage(); |
3065 return this->NewSuperPropertyReference(scope_, factory(), pos); | 3073 return this->NewSuperPropertyReference(this->scope(), factory(), pos); |
3066 } | 3074 } |
3067 // new super() is never allowed. | 3075 // new super() is never allowed. |
3068 // super() is only allowed in derived constructor | 3076 // super() is only allowed in derived constructor |
3069 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { | 3077 if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) { |
3070 // TODO(rossberg): This might not be the correct FunctionState for the | 3078 // TODO(rossberg): This might not be the correct FunctionState for the |
3071 // method here. | 3079 // method here. |
3072 function_state_->set_super_location(scanner()->location()); | 3080 function_state_->set_super_location(scanner()->location()); |
3073 return this->NewSuperCallReference(scope_, factory(), pos); | 3081 return this->NewSuperCallReference(this->scope(), factory(), pos); |
3074 } | 3082 } |
3075 } | 3083 } |
3076 | 3084 |
3077 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); | 3085 ReportMessageAt(scanner()->location(), MessageTemplate::kUnexpectedSuper); |
3078 *ok = false; | 3086 *ok = false; |
3079 return this->EmptyExpression(); | 3087 return this->EmptyExpression(); |
3080 } | 3088 } |
3081 | 3089 |
3082 template <class Traits> | 3090 template <class Traits> |
3083 void ParserBase<Traits>::ExpectMetaProperty(Vector<const char> property_name, | 3091 void ParserBase<Traits>::ExpectMetaProperty(Vector<const char> property_name, |
3084 const char* full_name, int pos, | 3092 const char* full_name, int pos, |
3085 bool* ok) { | 3093 bool* ok) { |
3086 Consume(Token::PERIOD); | 3094 Consume(Token::PERIOD); |
3087 ExpectContextualKeyword(property_name, ok); | 3095 ExpectContextualKeyword(property_name, ok); |
3088 if (!*ok) return; | 3096 if (!*ok) return; |
3089 if (scanner()->literal_contains_escapes()) { | 3097 if (scanner()->literal_contains_escapes()) { |
3090 Traits::ReportMessageAt( | 3098 Traits::ReportMessageAt( |
3091 Scanner::Location(pos, scanner()->location().end_pos), | 3099 Scanner::Location(pos, scanner()->location().end_pos), |
3092 MessageTemplate::kInvalidEscapedMetaProperty, full_name); | 3100 MessageTemplate::kInvalidEscapedMetaProperty, full_name); |
3093 *ok = false; | 3101 *ok = false; |
3094 } | 3102 } |
3095 } | 3103 } |
3096 | 3104 |
3097 template <class Traits> | 3105 template <class Traits> |
3098 typename ParserBase<Traits>::ExpressionT | 3106 typename ParserBase<Traits>::ExpressionT |
3099 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { | 3107 ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { |
3100 int pos = position(); | 3108 int pos = position(); |
3101 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); | 3109 ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); |
3102 | 3110 |
3103 if (!scope_->ReceiverScope()->is_function_scope()) { | 3111 if (!scope()->ReceiverScope()->is_function_scope()) { |
3104 ReportMessageAt(scanner()->location(), | 3112 ReportMessageAt(scanner()->location(), |
3105 MessageTemplate::kUnexpectedNewTarget); | 3113 MessageTemplate::kUnexpectedNewTarget); |
3106 *ok = false; | 3114 *ok = false; |
3107 return this->EmptyExpression(); | 3115 return this->EmptyExpression(); |
3108 } | 3116 } |
3109 | 3117 |
3110 return this->NewTargetExpression(scope_, factory(), pos); | 3118 return this->NewTargetExpression(scope(), factory(), pos); |
3111 } | 3119 } |
3112 | 3120 |
3113 template <class Traits> | 3121 template <class Traits> |
3114 typename ParserBase<Traits>::ExpressionT | 3122 typename ParserBase<Traits>::ExpressionT |
3115 ParserBase<Traits>::ParseMemberExpressionContinuation( | 3123 ParserBase<Traits>::ParseMemberExpressionContinuation( |
3116 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, | 3124 ExpressionT expression, bool* is_async, ExpressionClassifier* classifier, |
3117 bool* ok) { | 3125 bool* ok) { |
3118 // Parses this part of MemberExpression: | 3126 // Parses this part of MemberExpression: |
3119 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* | 3127 // ('[' Expression ']' | '.' Identifier | TemplateLiteral)* |
3120 while (true) { | 3128 while (true) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3347 | 3355 |
3348 typename Traits::Type::StatementList body; | 3356 typename Traits::Type::StatementList body; |
3349 int num_parameters = formal_parameters.scope->num_parameters(); | 3357 int num_parameters = formal_parameters.scope->num_parameters(); |
3350 int materialized_literal_count = -1; | 3358 int materialized_literal_count = -1; |
3351 int expected_property_count = -1; | 3359 int expected_property_count = -1; |
3352 Scanner::Location super_loc; | 3360 Scanner::Location super_loc; |
3353 | 3361 |
3354 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; | 3362 FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction; |
3355 { | 3363 { |
3356 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3364 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3357 FunctionState function_state(&function_state_, &scope_, | 3365 FunctionState function_state(&function_state_, &state_, |
3358 formal_parameters.scope, arrow_kind, | 3366 formal_parameters.scope, arrow_kind, |
3359 &function_factory); | 3367 &function_factory); |
3360 | 3368 |
3361 function_state.SkipMaterializedLiterals( | 3369 function_state.SkipMaterializedLiterals( |
3362 formal_parameters.materialized_literals_count); | 3370 formal_parameters.materialized_literals_count); |
3363 | 3371 |
3364 this->ReindexLiterals(formal_parameters); | 3372 this->ReindexLiterals(formal_parameters); |
3365 | 3373 |
3366 Expect(Token::ARROW, CHECK_OK); | 3374 Expect(Token::ARROW, CHECK_OK); |
3367 | 3375 |
3368 if (peek() == Token::LBRACE) { | 3376 if (peek() == Token::LBRACE) { |
3369 // Multiple statement body | 3377 // Multiple statement body |
3370 Consume(Token::LBRACE); | 3378 Consume(Token::LBRACE); |
3371 bool is_lazily_parsed = | 3379 bool is_lazily_parsed = |
3372 (mode() == PARSE_LAZILY && scope_->AllowsLazyParsing()); | 3380 (mode() == PARSE_LAZILY && scope()->AllowsLazyParsing()); |
3373 if (is_lazily_parsed) { | 3381 if (is_lazily_parsed) { |
3374 body = this->NewStatementList(0, zone()); | 3382 body = this->NewStatementList(0, zone()); |
3375 this->SkipLazyFunctionBody(&materialized_literal_count, | 3383 this->SkipLazyFunctionBody(&materialized_literal_count, |
3376 &expected_property_count, CHECK_OK); | 3384 &expected_property_count, CHECK_OK); |
3377 if (formal_parameters.materialized_literals_count > 0) { | 3385 if (formal_parameters.materialized_literals_count > 0) { |
3378 materialized_literal_count += | 3386 materialized_literal_count += |
3379 formal_parameters.materialized_literals_count; | 3387 formal_parameters.materialized_literals_count; |
3380 } | 3388 } |
3381 } else { | 3389 } else { |
3382 body = this->ParseEagerFunctionBody( | 3390 body = this->ParseEagerFunctionBody( |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3665 has_seen_constructor_ = true; | 3673 has_seen_constructor_ = true; |
3666 return; | 3674 return; |
3667 } | 3675 } |
3668 } | 3676 } |
3669 | 3677 |
3670 | 3678 |
3671 } // namespace internal | 3679 } // namespace internal |
3672 } // namespace v8 | 3680 } // namespace v8 |
3673 | 3681 |
3674 #endif // V8_PARSING_PARSER_BASE_H | 3682 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |