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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 | 1103 |
1104 scope->set_start_position(shared_info->start_position()); | 1104 scope->set_start_position(shared_info->start_position()); |
1105 ExpressionClassifier formals_classifier(this); | 1105 ExpressionClassifier formals_classifier(this); |
1106 ParserFormalParameters formals(scope); | 1106 ParserFormalParameters formals(scope); |
1107 Checkpoint checkpoint(this); | 1107 Checkpoint checkpoint(this); |
1108 { | 1108 { |
1109 // Parsing patterns as variable reference expression creates | 1109 // Parsing patterns as variable reference expression creates |
1110 // NewUnresolved references in current scope. Entrer arrow function | 1110 // NewUnresolved references in current scope. Entrer arrow function |
1111 // scope for formal parameter parsing. | 1111 // scope for formal parameter parsing. |
1112 BlockState block_state(&scope_, scope); | 1112 BlockState block_state(&scope_, scope); |
| 1113 function_state.set_parse_phase(FunctionParsePhase::FormalParameters); |
1113 if (Check(Token::LPAREN)) { | 1114 if (Check(Token::LPAREN)) { |
1114 // '(' StrictFormalParameters ')' | 1115 // '(' StrictFormalParameters ')' |
1115 ParseFormalParameterList(&formals, &formals_classifier, &ok); | 1116 ParseFormalParameterList(&formals, &formals_classifier, &ok); |
1116 if (ok) ok = Check(Token::RPAREN); | 1117 if (ok) ok = Check(Token::RPAREN); |
1117 } else { | 1118 } else { |
1118 // BindingIdentifier | 1119 // BindingIdentifier |
1119 ParseFormalParameter(&formals, &formals_classifier, &ok); | 1120 ParseFormalParameter(&formals, &formals_classifier, &ok); |
1120 if (ok) { | 1121 if (ok) { |
1121 DeclareFormalParameter(formals.scope, formals.at(0), | 1122 DeclareFormalParameter(formals.scope, formals.at(0), |
1122 &formals_classifier); | 1123 &formals_classifier); |
1123 } | 1124 } |
1124 } | 1125 } |
1125 } | 1126 } |
1126 | 1127 |
1127 if (ok) { | 1128 if (ok) { |
| 1129 function_state.set_parse_phase(FunctionParsePhase::FunctionBody); |
1128 checkpoint.Restore(&formals.materialized_literals_count); | 1130 checkpoint.Restore(&formals.materialized_literals_count); |
1129 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should | 1131 // Pass `accept_IN=true` to ParseArrowFunctionLiteral --- This should |
1130 // not be observable, or else the preparser would have failed. | 1132 // not be observable, or else the preparser would have failed. |
1131 Expression* expression = ParseArrowFunctionLiteral( | 1133 Expression* expression = ParseArrowFunctionLiteral( |
1132 true, formals, is_async, formals_classifier, &ok); | 1134 true, formals, is_async, formals_classifier, &ok); |
1133 if (ok) { | 1135 if (ok) { |
1134 // Scanning must end at the same position that was recorded | 1136 // Scanning must end at the same position that was recorded |
1135 // previously. If not, parsing has been interrupted due to a stack | 1137 // previously. If not, parsing has been interrupted due to a stack |
1136 // overflow, at which point the partially parsed arrow function | 1138 // overflow, at which point the partially parsed arrow function |
1137 // concise body happens to be a valid expression. This is a problem | 1139 // concise body happens to be a valid expression. This is a problem |
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 if (allow_tailcalls() && !is_sloppy(language_mode())) { | 2714 if (allow_tailcalls() && !is_sloppy(language_mode())) { |
2713 // ES6 14.6.1 Static Semantics: IsInTailPosition | 2715 // ES6 14.6.1 Static Semantics: IsInTailPosition |
2714 function_state_->AddImplicitTailCallExpression(return_value); | 2716 function_state_->AddImplicitTailCallExpression(return_value); |
2715 } | 2717 } |
2716 } | 2718 } |
2717 } | 2719 } |
2718 ExpectSemicolon(CHECK_OK); | 2720 ExpectSemicolon(CHECK_OK); |
2719 | 2721 |
2720 if (is_generator()) { | 2722 if (is_generator()) { |
2721 return_value = BuildIteratorResult(return_value, true); | 2723 return_value = BuildIteratorResult(return_value, true); |
| 2724 } else if (is_async_function()) { |
| 2725 return_value = BuildPromiseResolve(return_value, return_value->position()); |
2722 } | 2726 } |
2723 | 2727 |
2724 result = factory()->NewReturnStatement(return_value, loc.beg_pos); | 2728 result = factory()->NewReturnStatement(return_value, loc.beg_pos); |
2725 | 2729 |
2726 Scope* decl_scope = scope_->DeclarationScope(); | 2730 Scope* decl_scope = scope_->DeclarationScope(); |
2727 if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) { | 2731 if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) { |
2728 ReportMessageAt(loc, MessageTemplate::kIllegalReturn); | 2732 ReportMessageAt(loc, MessageTemplate::kIllegalReturn); |
2729 *ok = false; | 2733 *ok = false; |
2730 return NULL; | 2734 return NULL; |
2731 } | 2735 } |
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3952 expr = assignment->target(); | 3956 expr = assignment->target(); |
3953 | 3957 |
3954 // TODO(adamk): Only call this if necessary. | 3958 // TODO(adamk): Only call this if necessary. |
3955 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, | 3959 RewriteParameterInitializerScope(parser_->stack_limit(), initializer, |
3956 parser_->scope_, parameters->scope); | 3960 parser_->scope_, parameters->scope); |
3957 } | 3961 } |
3958 | 3962 |
3959 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); | 3963 AddFormalParameter(parameters, expr, initializer, end_pos, is_rest); |
3960 } | 3964 } |
3961 | 3965 |
| 3966 void ParserTraits::ParseAsyncArrowSingleExpressionBody( |
| 3967 ZoneList<Statement*>* body, bool accept_IN, |
| 3968 Type::ExpressionClassifier* classifier, int pos, bool* ok) { |
| 3969 parser_->DesugarAsyncFunctionBody( |
| 3970 parser_->ast_value_factory()->empty_string(), parser_->scope_, body, |
| 3971 classifier, kAsyncArrowFunction, FunctionBody::SingleExpression, |
| 3972 accept_IN, pos, ok); |
| 3973 } |
| 3974 |
| 3975 void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, |
| 3976 Scope* scope, ZoneList<Statement*>* body, |
| 3977 ExpressionClassifier* classifier, |
| 3978 FunctionKind kind, FunctionBody body_type, |
| 3979 bool accept_IN, int pos, bool* ok) { |
| 3980 // function async_function() { |
| 3981 // try { |
| 3982 // .generator_object = %CreateGeneratorObject(); |
| 3983 // ... function body ... |
| 3984 // } catch (e) { |
| 3985 // return Promise.reject(e); |
| 3986 // } |
| 3987 // } |
| 3988 scope->ForceContextAllocation(); |
| 3989 Variable* temp = |
| 3990 scope_->NewTemporary(ast_value_factory()->dot_generator_object_string()); |
| 3991 function_state_->set_generator_object_variable(temp); |
| 3992 |
| 3993 Expression* init_generator_variable = factory()->NewAssignment( |
| 3994 Token::INIT, factory()->NewVariableProxy(temp), |
| 3995 BuildCreateJSGeneratorObject(pos), RelocInfo::kNoPosition); |
| 3996 body->Add(factory()->NewExpressionStatement(init_generator_variable, |
| 3997 RelocInfo::kNoPosition), |
| 3998 zone()); |
| 3999 |
| 4000 Block* try_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
| 4001 |
| 4002 ZoneList<Statement*>* inner_body = try_block->statements(); |
| 4003 |
| 4004 Expression* return_value = nullptr; |
| 4005 if (body_type == FunctionBody::Normal) { |
| 4006 ParseStatementList(inner_body, Token::RBRACE, ok); |
| 4007 if (!*ok) return; |
| 4008 return_value = factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); |
| 4009 } else { |
| 4010 return_value = ParseAssignmentExpression(accept_IN, classifier, ok); |
| 4011 if (!*ok) return; |
| 4012 ParserTraits::RewriteNonPattern(classifier, ok); |
| 4013 if (!*ok) return; |
| 4014 } |
| 4015 |
| 4016 return_value = BuildPromiseResolve(return_value, return_value->position()); |
| 4017 inner_body->Add( |
| 4018 factory()->NewReturnStatement(return_value, return_value->position()), |
| 4019 zone()); |
| 4020 body->Add(BuildRejectPromiseOnException(try_block), zone()); |
| 4021 scope->set_end_position(scanner()->location().end_pos); |
| 4022 } |
3962 | 4023 |
3963 DoExpression* Parser::ParseDoExpression(bool* ok) { | 4024 DoExpression* Parser::ParseDoExpression(bool* ok) { |
3964 // AssignmentExpression :: | 4025 // AssignmentExpression :: |
3965 // do '{' StatementList '}' | 4026 // do '{' StatementList '}' |
3966 int pos = peek_position(); | 4027 int pos = peek_position(); |
3967 | 4028 |
3968 Expect(Token::DO, CHECK_OK); | 4029 Expect(Token::DO, CHECK_OK); |
3969 Variable* result = | 4030 Variable* result = |
3970 scope_->NewTemporary(ast_value_factory()->dot_result_string()); | 4031 scope_->NewTemporary(ast_value_factory()->dot_result_string()); |
3971 Block* block = ParseBlock(nullptr, false, CHECK_OK); | 4032 Block* block = ParseBlock(nullptr, false, CHECK_OK); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4088 // expressions. This also marks the FunctionState as a generator. | 4149 // expressions. This also marks the FunctionState as a generator. |
4089 Variable* temp = scope_->NewTemporary( | 4150 Variable* temp = scope_->NewTemporary( |
4090 ast_value_factory()->dot_generator_object_string()); | 4151 ast_value_factory()->dot_generator_object_string()); |
4091 function_state.set_generator_object_variable(temp); | 4152 function_state.set_generator_object_variable(temp); |
4092 } | 4153 } |
4093 | 4154 |
4094 Expect(Token::LPAREN, CHECK_OK); | 4155 Expect(Token::LPAREN, CHECK_OK); |
4095 int start_position = scanner()->location().beg_pos; | 4156 int start_position = scanner()->location().beg_pos; |
4096 scope_->set_start_position(start_position); | 4157 scope_->set_start_position(start_position); |
4097 ParserFormalParameters formals(scope); | 4158 ParserFormalParameters formals(scope); |
| 4159 function_state.set_parse_phase(FunctionParsePhase::FormalParameters); |
4098 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); | 4160 ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK); |
4099 arity = formals.Arity(); | 4161 arity = formals.Arity(); |
4100 Expect(Token::RPAREN, CHECK_OK); | 4162 Expect(Token::RPAREN, CHECK_OK); |
4101 int formals_end_position = scanner()->location().end_pos; | 4163 int formals_end_position = scanner()->location().end_pos; |
4102 | 4164 |
4103 CheckArityRestrictions(arity, kind, formals.has_rest, start_position, | 4165 CheckArityRestrictions(arity, kind, formals.has_rest, start_position, |
4104 formals_end_position, CHECK_OK); | 4166 formals_end_position, CHECK_OK); |
4105 Expect(Token::LBRACE, CHECK_OK); | 4167 Expect(Token::LBRACE, CHECK_OK); |
4106 | 4168 function_state.set_parse_phase(FunctionParsePhase::FunctionBody); |
4107 // Don't include the rest parameter into the function's formal parameter | 4169 // Don't include the rest parameter into the function's formal parameter |
4108 // count (esp. the SharedFunctionInfo::internal_formal_parameter_count, | 4170 // count (esp. the SharedFunctionInfo::internal_formal_parameter_count, |
4109 // which says whether we need to create an arguments adaptor frame). | 4171 // which says whether we need to create an arguments adaptor frame). |
4110 if (formals.has_rest) arity--; | 4172 if (formals.has_rest) arity--; |
4111 | 4173 |
4112 // Determine if the function can be parsed lazily. Lazy parsing is different | 4174 // Determine if the function can be parsed lazily. Lazy parsing is different |
4113 // from lazy compilation; we need to parse more eagerly than we compile. | 4175 // from lazy compilation; we need to parse more eagerly than we compile. |
4114 | 4176 |
4115 // We can only parse lazily if we also compile lazily. The heuristics for | 4177 // We can only parse lazily if we also compile lazily. The heuristics for |
4116 // lazy compilation are: | 4178 // lazy compilation are: |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4500 param_scope = param_scope->FinalizeBlockScope(); | 4562 param_scope = param_scope->FinalizeBlockScope(); |
4501 if (param_scope != nullptr) { | 4563 if (param_scope != nullptr) { |
4502 CheckConflictingVarDeclarations(param_scope, CHECK_OK); | 4564 CheckConflictingVarDeclarations(param_scope, CHECK_OK); |
4503 } | 4565 } |
4504 init_block->statements()->Add(param_block, zone()); | 4566 init_block->statements()->Add(param_block, zone()); |
4505 } | 4567 } |
4506 } | 4568 } |
4507 return init_block; | 4569 return init_block; |
4508 } | 4570 } |
4509 | 4571 |
| 4572 Block* Parser::BuildRejectPromiseOnException(Block* block) { |
| 4573 // try { <block> } catch (error) { return Promise.reject(error); } |
| 4574 Block* try_block = block; |
| 4575 Scope* catch_scope = NewScope(scope_, CATCH_SCOPE); |
| 4576 catch_scope->set_is_hidden(); |
| 4577 Variable* catch_variable = |
| 4578 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR, |
| 4579 kCreatedInitialized, Variable::NORMAL); |
| 4580 Block* catch_block = |
| 4581 factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); |
| 4582 |
| 4583 Expression* promise_reject = BuildPromiseReject( |
| 4584 factory()->NewVariableProxy(catch_variable), RelocInfo::kNoPosition); |
| 4585 |
| 4586 ReturnStatement* return_promise_reject = |
| 4587 factory()->NewReturnStatement(promise_reject, RelocInfo::kNoPosition); |
| 4588 catch_block->statements()->Add(return_promise_reject, zone()); |
| 4589 TryStatement* try_catch_statement = |
| 4590 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable, |
| 4591 catch_block, RelocInfo::kNoPosition); |
| 4592 |
| 4593 block = factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); |
| 4594 block->statements()->Add(try_catch_statement, zone()); |
| 4595 return block; |
| 4596 } |
| 4597 |
| 4598 Expression* Parser::BuildCreateJSGeneratorObject(int pos) { |
| 4599 DCHECK_NOT_NULL(function_state_->generator_object_variable()); |
| 4600 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
| 4601 args->Add(factory()->NewThisFunction(pos), zone()); |
| 4602 args->Add(ThisExpression(scope_, factory(), RelocInfo::kNoPosition), zone()); |
| 4603 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, |
| 4604 pos); |
| 4605 } |
| 4606 |
| 4607 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { |
| 4608 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
| 4609 args->Add(value, zone()); |
| 4610 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, |
| 4611 pos); |
| 4612 } |
| 4613 |
| 4614 Expression* Parser::BuildPromiseReject(Expression* value, int pos) { |
| 4615 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
| 4616 args->Add(value, zone()); |
| 4617 return factory()->NewCallRuntime(Context::PROMISE_CREATE_REJECTED_INDEX, args, |
| 4618 pos); |
| 4619 } |
4510 | 4620 |
4511 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( | 4621 ZoneList<Statement*>* Parser::ParseEagerFunctionBody( |
4512 const AstRawString* function_name, int pos, | 4622 const AstRawString* function_name, int pos, |
4513 const ParserFormalParameters& parameters, FunctionKind kind, | 4623 const ParserFormalParameters& parameters, FunctionKind kind, |
4514 FunctionLiteral::FunctionType function_type, bool* ok) { | 4624 FunctionLiteral::FunctionType function_type, bool* ok) { |
4515 // Everything inside an eagerly parsed function will be parsed eagerly | 4625 // Everything inside an eagerly parsed function will be parsed eagerly |
4516 // (see comment above). | 4626 // (see comment above). |
4517 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 4627 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
4518 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); | 4628 ZoneList<Statement*>* result = new(zone()) ZoneList<Statement*>(8, zone()); |
4519 | 4629 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4553 // - InitialYield yields the actual generator object. | 4663 // - InitialYield yields the actual generator object. |
4554 // - Any return statement inside the body will have its argument wrapped | 4664 // - Any return statement inside the body will have its argument wrapped |
4555 // in a "done" iterator result object. | 4665 // in a "done" iterator result object. |
4556 // - If the generator terminates for whatever reason, we must close it. | 4666 // - If the generator terminates for whatever reason, we must close it. |
4557 // Hence the finally clause. | 4667 // Hence the finally clause. |
4558 | 4668 |
4559 Block* try_block = | 4669 Block* try_block = |
4560 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); | 4670 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); |
4561 | 4671 |
4562 { | 4672 { |
4563 ZoneList<Expression*>* arguments = | 4673 Expression* allocation = BuildCreateJSGeneratorObject(pos); |
4564 new (zone()) ZoneList<Expression*>(2, zone()); | |
4565 arguments->Add(factory()->NewThisFunction(pos), zone()); | |
4566 arguments->Add( | |
4567 ThisExpression(scope_, factory(), RelocInfo::kNoPosition), zone()); | |
4568 CallRuntime* allocation = factory()->NewCallRuntime( | |
4569 Runtime::kCreateJSGeneratorObject, arguments, pos); | |
4570 | |
4571 VariableProxy* init_proxy = factory()->NewVariableProxy( | 4674 VariableProxy* init_proxy = factory()->NewVariableProxy( |
4572 function_state_->generator_object_variable()); | 4675 function_state_->generator_object_variable()); |
4573 Assignment* assignment = factory()->NewAssignment( | 4676 Assignment* assignment = factory()->NewAssignment( |
4574 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); | 4677 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); |
4575 VariableProxy* get_proxy = factory()->NewVariableProxy( | 4678 VariableProxy* get_proxy = factory()->NewVariableProxy( |
4576 function_state_->generator_object_variable()); | 4679 function_state_->generator_object_variable()); |
4577 Yield* yield = | 4680 Yield* yield = |
4578 factory()->NewYield(get_proxy, assignment, RelocInfo::kNoPosition); | 4681 factory()->NewYield(get_proxy, assignment, RelocInfo::kNoPosition); |
4579 try_block->statements()->Add( | 4682 try_block->statements()->Add( |
4580 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), | 4683 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), |
(...skipping 15 matching lines...) Expand all Loading... |
4596 args->Add(call_proxy, zone()); | 4699 args->Add(call_proxy, zone()); |
4597 Expression* call = factory()->NewCallRuntime( | 4700 Expression* call = factory()->NewCallRuntime( |
4598 Runtime::kGeneratorClose, args, RelocInfo::kNoPosition); | 4701 Runtime::kGeneratorClose, args, RelocInfo::kNoPosition); |
4599 finally_block->statements()->Add( | 4702 finally_block->statements()->Add( |
4600 factory()->NewExpressionStatement(call, RelocInfo::kNoPosition), | 4703 factory()->NewExpressionStatement(call, RelocInfo::kNoPosition), |
4601 zone()); | 4704 zone()); |
4602 | 4705 |
4603 body->Add(factory()->NewTryFinallyStatement(try_block, finally_block, | 4706 body->Add(factory()->NewTryFinallyStatement(try_block, finally_block, |
4604 RelocInfo::kNoPosition), | 4707 RelocInfo::kNoPosition), |
4605 zone()); | 4708 zone()); |
| 4709 } else if (IsAsyncFunction(kind)) { |
| 4710 const bool accept_IN = true; |
| 4711 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, |
| 4712 FunctionBody::Normal, accept_IN, pos, CHECK_OK); |
4606 } else { | 4713 } else { |
4607 ParseStatementList(body, Token::RBRACE, CHECK_OK); | 4714 ParseStatementList(body, Token::RBRACE, CHECK_OK); |
4608 } | 4715 } |
4609 | 4716 |
4610 if (IsSubclassConstructor(kind)) { | 4717 if (IsSubclassConstructor(kind)) { |
4611 body->Add( | 4718 body->Add( |
4612 factory()->NewReturnStatement( | 4719 factory()->NewReturnStatement( |
4613 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), | 4720 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), |
4614 RelocInfo::kNoPosition), | 4721 RelocInfo::kNoPosition), |
4615 zone()); | 4722 zone()); |
4616 } | 4723 } |
4617 } | 4724 } |
4618 | 4725 |
4619 Expect(Token::RBRACE, CHECK_OK); | 4726 Expect(Token::RBRACE, CHECK_OK); |
4620 scope_->set_end_position(scanner()->location().end_pos); | 4727 scope_->set_end_position(scanner()->location().end_pos); |
4621 | 4728 |
4622 if (!parameters.is_simple) { | 4729 if (!parameters.is_simple) { |
4623 DCHECK_NOT_NULL(inner_scope); | 4730 DCHECK_NOT_NULL(inner_scope); |
4624 DCHECK_EQ(body, inner_block->statements()); | 4731 DCHECK_EQ(body, inner_block->statements()); |
4625 SetLanguageMode(scope_, inner_scope->language_mode()); | 4732 SetLanguageMode(scope_, inner_scope->language_mode()); |
4626 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); | 4733 Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK); |
| 4734 |
| 4735 if (IsAsyncFunction(kind)) { |
| 4736 init_block = BuildRejectPromiseOnException(init_block); |
| 4737 } |
| 4738 |
4627 DCHECK_NOT_NULL(init_block); | 4739 DCHECK_NOT_NULL(init_block); |
4628 | 4740 |
4629 inner_scope->set_end_position(scanner()->location().end_pos); | 4741 inner_scope->set_end_position(scanner()->location().end_pos); |
4630 inner_scope = inner_scope->FinalizeBlockScope(); | 4742 inner_scope = inner_scope->FinalizeBlockScope(); |
4631 if (inner_scope != nullptr) { | 4743 if (inner_scope != nullptr) { |
4632 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); | 4744 CheckConflictingVarDeclarations(inner_scope, CHECK_OK); |
4633 InsertShadowingVarBindingInitializers(inner_block); | 4745 InsertShadowingVarBindingInitializers(inner_block); |
4634 } | 4746 } |
4635 | 4747 |
4636 result->Add(init_block, zone()); | 4748 result->Add(init_block, zone()); |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5421 int pos) { | 5533 int pos) { |
5422 return parser_->RewriteAssignExponentiation(left, right, pos); | 5534 return parser_->RewriteAssignExponentiation(left, right, pos); |
5423 } | 5535 } |
5424 | 5536 |
5425 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 5537 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, |
5426 bool* ok) { | 5538 bool* ok) { |
5427 parser_->RewriteNonPattern(classifier, ok); | 5539 parser_->RewriteNonPattern(classifier, ok); |
5428 } | 5540 } |
5429 | 5541 |
5430 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, int pos) { | 5542 Expression* ParserTraits::RewriteAwaitExpression(Expression* value, int pos) { |
5431 // TODO(caitp): Implement AsyncFunctionAwait() | 5543 // yield %AsyncFunctionAwait(.generator_object, <operand>) |
5432 // per tc39.github.io/ecmascript-asyncawait/#abstract-ops-async-function-await | 5544 Variable* generator_object_variable = |
5433 return value; | 5545 parser_->function_state_->generator_object_variable(); |
| 5546 |
| 5547 DCHECK_NOT_NULL(generator_object_variable); |
| 5548 |
| 5549 Expression* generator_object = |
| 5550 parser_->factory()->NewVariableProxy(generator_object_variable); |
| 5551 |
| 5552 ZoneList<Expression*>* async_function_await_args = |
| 5553 new (zone()) ZoneList<Expression*>(2, zone()); |
| 5554 async_function_await_args->Add(generator_object, zone()); |
| 5555 async_function_await_args->Add(value, zone()); |
| 5556 Expression* async_function_await = parser_->factory()->NewCallRuntime( |
| 5557 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, |
| 5558 RelocInfo::kNoPosition); |
| 5559 |
| 5560 generator_object = |
| 5561 parser_->factory()->NewVariableProxy(generator_object_variable); |
| 5562 return parser_->factory()->NewYield(generator_object, async_function_await, |
| 5563 pos); |
5434 } | 5564 } |
5435 | 5565 |
5436 Zone* ParserTraits::zone() const { | 5566 Zone* ParserTraits::zone() const { |
5437 return parser_->function_state_->scope()->zone(); | 5567 return parser_->function_state_->scope()->zone(); |
5438 } | 5568 } |
5439 | 5569 |
5440 | 5570 |
5441 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { | 5571 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { |
5442 return parser_->function_state_->non_patterns_to_rewrite(); | 5572 return parser_->function_state_->non_patterns_to_rewrite(); |
5443 } | 5573 } |
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6917 try_block, target); | 7047 try_block, target); |
6918 final_loop = target; | 7048 final_loop = target; |
6919 } | 7049 } |
6920 | 7050 |
6921 return final_loop; | 7051 return final_loop; |
6922 } | 7052 } |
6923 | 7053 |
6924 | 7054 |
6925 } // namespace internal | 7055 } // namespace internal |
6926 } // namespace v8 | 7056 } // namespace v8 |
OLD | NEW |