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/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 void SkipMaterializedLiterals(int count) { | 420 void SkipMaterializedLiterals(int count) { |
421 next_materialized_literal_index_ += count; | 421 next_materialized_literal_index_ += count; |
422 } | 422 } |
423 | 423 |
424 void AddProperty() { expected_property_count_++; } | 424 void AddProperty() { expected_property_count_++; } |
425 int expected_property_count() { return expected_property_count_; } | 425 int expected_property_count() { return expected_property_count_; } |
426 | 426 |
427 FunctionKind kind() const { return scope()->function_kind(); } | 427 FunctionKind kind() const { return scope()->function_kind(); } |
428 FunctionState* outer() const { return outer_function_state_; } | 428 FunctionState* outer() const { return outer_function_state_; } |
429 | 429 |
430 void set_generator_object_variable(typename Types::Variable* variable) { | |
431 DCHECK_NOT_NULL(variable); | |
432 DCHECK(IsResumableFunction(kind())); | |
433 DCHECK(scope()->has_forced_context_allocation()); | |
434 generator_object_variable_ = variable; | |
435 } | |
436 typename Types::Variable* generator_object_variable() const { | 430 typename Types::Variable* generator_object_variable() const { |
437 return generator_object_variable_; | 431 return scope()->generator_object_var(); |
438 } | 432 } |
439 | 433 |
440 void set_promise_variable(typename Types::Variable* variable) { | |
441 DCHECK(variable != NULL); | |
442 DCHECK(IsAsyncFunction(kind())); | |
443 promise_variable_ = variable; | |
444 } | |
445 typename Types::Variable* promise_variable() const { | 434 typename Types::Variable* promise_variable() const { |
446 return promise_variable_; | 435 return scope()->promise_var(); |
447 } | 436 } |
448 | 437 |
449 const ZoneList<DestructuringAssignment>& | 438 const ZoneList<DestructuringAssignment>& |
450 destructuring_assignments_to_rewrite() const { | 439 destructuring_assignments_to_rewrite() const { |
451 return destructuring_assignments_to_rewrite_; | 440 return destructuring_assignments_to_rewrite_; |
452 } | 441 } |
453 | 442 |
454 TailCallExpressionList& tail_call_expressions() { | 443 TailCallExpressionList& tail_call_expressions() { |
455 return tail_call_expressions_; | 444 return tail_call_expressions_; |
456 } | 445 } |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1376 if (is_sloppy(scope->language_mode())) { | 1365 if (is_sloppy(scope->language_mode())) { |
1377 // For sloppy scopes we also have to record the call at function level, | 1366 // For sloppy scopes we also have to record the call at function level, |
1378 // in case it includes declarations that will be hoisted. | 1367 // in case it includes declarations that will be hoisted. |
1379 scope->GetDeclarationScope()->RecordEvalCall(); | 1368 scope->GetDeclarationScope()->RecordEvalCall(); |
1380 } | 1369 } |
1381 return Call::IS_POSSIBLY_EVAL; | 1370 return Call::IS_POSSIBLY_EVAL; |
1382 } | 1371 } |
1383 return Call::NOT_EVAL; | 1372 return Call::NOT_EVAL; |
1384 } | 1373 } |
1385 | 1374 |
| 1375 // Convenience method which determines the type of return statement to emit |
| 1376 // depending on the current function type. |
| 1377 inline StatementT BuildReturnStatement(ExpressionT expr, int pos) { |
| 1378 if (V8_UNLIKELY(is_async_function())) { |
| 1379 return factory()->NewAsyncReturnStatement(expr, pos); |
| 1380 } |
| 1381 return factory()->NewReturnStatement(expr, pos); |
| 1382 } |
| 1383 |
1386 // Validation per ES6 object literals. | 1384 // Validation per ES6 object literals. |
1387 class ObjectLiteralChecker { | 1385 class ObjectLiteralChecker { |
1388 public: | 1386 public: |
1389 explicit ObjectLiteralChecker(ParserBase* parser) | 1387 explicit ObjectLiteralChecker(ParserBase* parser) |
1390 : parser_(parser), has_seen_proto_(false) {} | 1388 : parser_(parser), has_seen_proto_(false) {} |
1391 | 1389 |
1392 void CheckDuplicateProto(Token::Value property); | 1390 void CheckDuplicateProto(Token::Value property); |
1393 | 1391 |
1394 private: | 1392 private: |
1395 bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } | 1393 bool IsProto() { return this->scanner()->LiteralMatches("__proto__", 9); } |
(...skipping 2873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4269 formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK); | 4267 formal_parameters, body, kind == kAsyncArrowFunction, CHECK_OK); |
4270 ExpressionClassifier classifier(this); | 4268 ExpressionClassifier classifier(this); |
4271 if (kind == kAsyncArrowFunction) { | 4269 if (kind == kAsyncArrowFunction) { |
4272 ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction, | 4270 ParseAsyncFunctionBody(scope(), body, kAsyncArrowFunction, |
4273 FunctionBodyType::kSingleExpression, accept_IN, | 4271 FunctionBodyType::kSingleExpression, accept_IN, |
4274 pos, CHECK_OK); | 4272 pos, CHECK_OK); |
4275 impl()->RewriteNonPattern(CHECK_OK); | 4273 impl()->RewriteNonPattern(CHECK_OK); |
4276 } else { | 4274 } else { |
4277 ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK); | 4275 ExpressionT expression = ParseAssignmentExpression(accept_IN, CHECK_OK); |
4278 impl()->RewriteNonPattern(CHECK_OK); | 4276 impl()->RewriteNonPattern(CHECK_OK); |
4279 body->Add( | 4277 body->Add(BuildReturnStatement(expression, expression->position()), |
4280 factory()->NewReturnStatement(expression, expression->position()), | 4278 zone()); |
4281 zone()); | |
4282 if (allow_tailcalls() && !is_sloppy(language_mode())) { | 4279 if (allow_tailcalls() && !is_sloppy(language_mode())) { |
4283 // ES6 14.6.1 Static Semantics: IsInTailPosition | 4280 // ES6 14.6.1 Static Semantics: IsInTailPosition |
4284 impl()->MarkTailPosition(expression); | 4281 impl()->MarkTailPosition(expression); |
4285 } | 4282 } |
4286 } | 4283 } |
4287 materialized_literal_count = function_state.materialized_literal_count(); | 4284 materialized_literal_count = function_state.materialized_literal_count(); |
4288 expected_property_count = function_state.expected_property_count(); | 4285 expected_property_count = function_state.expected_property_count(); |
4289 impl()->MarkCollectedTailCallExpressions(); | 4286 impl()->MarkCollectedTailCallExpressions(); |
4290 } | 4287 } |
4291 | 4288 |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5176 return_value = ParseExpression(true, CHECK_OK); | 5173 return_value = ParseExpression(true, CHECK_OK); |
5177 | 5174 |
5178 if (allow_tailcalls() && !is_sloppy(language_mode()) && !is_resumable()) { | 5175 if (allow_tailcalls() && !is_sloppy(language_mode()) && !is_resumable()) { |
5179 // ES6 14.6.1 Static Semantics: IsInTailPosition | 5176 // ES6 14.6.1 Static Semantics: IsInTailPosition |
5180 function_state_->AddImplicitTailCallExpression(return_value); | 5177 function_state_->AddImplicitTailCallExpression(return_value); |
5181 } | 5178 } |
5182 } | 5179 } |
5183 } | 5180 } |
5184 ExpectSemicolon(CHECK_OK); | 5181 ExpectSemicolon(CHECK_OK); |
5185 return_value = impl()->RewriteReturn(return_value, loc.beg_pos); | 5182 return_value = impl()->RewriteReturn(return_value, loc.beg_pos); |
5186 return factory()->NewReturnStatement(return_value, loc.beg_pos); | 5183 return BuildReturnStatement(return_value, loc.beg_pos); |
5187 } | 5184 } |
5188 | 5185 |
5189 template <typename Impl> | 5186 template <typename Impl> |
5190 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( | 5187 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( |
5191 ZoneList<const AstRawString*>* labels, bool* ok) { | 5188 ZoneList<const AstRawString*>* labels, bool* ok) { |
5192 // WithStatement :: | 5189 // WithStatement :: |
5193 // 'with' '(' Expression ')' Statement | 5190 // 'with' '(' Expression ')' Statement |
5194 | 5191 |
5195 Expect(Token::WITH, CHECK_OK); | 5192 Expect(Token::WITH, CHECK_OK); |
5196 int pos = position(); | 5193 int pos = position(); |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5774 } | 5771 } |
5775 | 5772 |
5776 #undef CHECK_OK | 5773 #undef CHECK_OK |
5777 #undef CHECK_OK_CUSTOM | 5774 #undef CHECK_OK_CUSTOM |
5778 #undef CHECK_OK_VOID | 5775 #undef CHECK_OK_VOID |
5779 | 5776 |
5780 } // namespace internal | 5777 } // namespace internal |
5781 } // namespace v8 | 5778 } // namespace v8 |
5782 | 5779 |
5783 #endif // V8_PARSING_PARSER_BASE_H | 5780 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |