| 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 3970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3981 // return Promise.reject(e); | 3981 // return Promise.reject(e); |
| 3982 // } | 3982 // } |
| 3983 // } | 3983 // } |
| 3984 scope->ForceContextAllocation(); | 3984 scope->ForceContextAllocation(); |
| 3985 Variable* temp = | 3985 Variable* temp = |
| 3986 scope_->NewTemporary(ast_value_factory()->dot_generator_object_string()); | 3986 scope_->NewTemporary(ast_value_factory()->dot_generator_object_string()); |
| 3987 function_state_->set_generator_object_variable(temp); | 3987 function_state_->set_generator_object_variable(temp); |
| 3988 | 3988 |
| 3989 Expression* init_generator_variable = factory()->NewAssignment( | 3989 Expression* init_generator_variable = factory()->NewAssignment( |
| 3990 Token::INIT, factory()->NewVariableProxy(temp), | 3990 Token::INIT, factory()->NewVariableProxy(temp), |
| 3991 BuildCreateJSGeneratorObject(pos), RelocInfo::kNoPosition); | 3991 BuildCreateJSGeneratorObject(pos, kind), RelocInfo::kNoPosition); |
| 3992 body->Add(factory()->NewExpressionStatement(init_generator_variable, | 3992 body->Add(factory()->NewExpressionStatement(init_generator_variable, |
| 3993 RelocInfo::kNoPosition), | 3993 RelocInfo::kNoPosition), |
| 3994 zone()); | 3994 zone()); |
| 3995 | 3995 |
| 3996 Block* try_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 3996 Block* try_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
| 3997 | 3997 |
| 3998 ZoneList<Statement*>* inner_body = try_block->statements(); | 3998 ZoneList<Statement*>* inner_body = try_block->statements(); |
| 3999 | 3999 |
| 4000 Expression* return_value = nullptr; | 4000 Expression* return_value = nullptr; |
| 4001 if (body_type == FunctionBody::Normal) { | 4001 if (body_type == FunctionBody::Normal) { |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4585 catch_block->statements()->Add(return_promise_reject, zone()); | 4585 catch_block->statements()->Add(return_promise_reject, zone()); |
| 4586 TryStatement* try_catch_statement = | 4586 TryStatement* try_catch_statement = |
| 4587 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable, | 4587 factory()->NewTryCatchStatement(try_block, catch_scope, catch_variable, |
| 4588 catch_block, RelocInfo::kNoPosition); | 4588 catch_block, RelocInfo::kNoPosition); |
| 4589 | 4589 |
| 4590 block = factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); | 4590 block = factory()->NewBlock(nullptr, 1, true, RelocInfo::kNoPosition); |
| 4591 block->statements()->Add(try_catch_statement, zone()); | 4591 block->statements()->Add(try_catch_statement, zone()); |
| 4592 return block; | 4592 return block; |
| 4593 } | 4593 } |
| 4594 | 4594 |
| 4595 Expression* Parser::BuildCreateJSGeneratorObject(int pos) { | 4595 Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) { |
| 4596 DCHECK_NOT_NULL(function_state_->generator_object_variable()); | 4596 DCHECK_NOT_NULL(function_state_->generator_object_variable()); |
| 4597 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); | 4597 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(2, zone()); |
| 4598 args->Add(factory()->NewThisFunction(pos), zone()); | 4598 args->Add(factory()->NewThisFunction(pos), zone()); |
| 4599 args->Add(ThisExpression(scope_, factory(), RelocInfo::kNoPosition), zone()); | 4599 args->Add(IsArrowFunction(kind) |
| 4600 ? GetLiteralUndefined(pos) |
| 4601 : ThisExpression(scope_, factory(), RelocInfo::kNoPosition), |
| 4602 zone()); |
| 4600 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, | 4603 return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args, |
| 4601 pos); | 4604 pos); |
| 4602 } | 4605 } |
| 4603 | 4606 |
| 4604 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { | 4607 Expression* Parser::BuildPromiseResolve(Expression* value, int pos) { |
| 4605 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); | 4608 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(1, zone()); |
| 4606 args->Add(value, zone()); | 4609 args->Add(value, zone()); |
| 4607 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, | 4610 return factory()->NewCallRuntime(Context::PROMISE_CREATE_RESOLVED_INDEX, args, |
| 4608 pos); | 4611 pos); |
| 4609 } | 4612 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4660 // - InitialYield yields the actual generator object. | 4663 // - InitialYield yields the actual generator object. |
| 4661 // - Any return statement inside the body will have its argument wrapped | 4664 // - Any return statement inside the body will have its argument wrapped |
| 4662 // in a "done" iterator result object. | 4665 // in a "done" iterator result object. |
| 4663 // - If the generator terminates for whatever reason, we must close it. | 4666 // - If the generator terminates for whatever reason, we must close it. |
| 4664 // Hence the finally clause. | 4667 // Hence the finally clause. |
| 4665 | 4668 |
| 4666 Block* try_block = | 4669 Block* try_block = |
| 4667 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); | 4670 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); |
| 4668 | 4671 |
| 4669 { | 4672 { |
| 4670 Expression* allocation = BuildCreateJSGeneratorObject(pos); | 4673 Expression* allocation = BuildCreateJSGeneratorObject(pos, kind); |
| 4671 VariableProxy* init_proxy = factory()->NewVariableProxy( | 4674 VariableProxy* init_proxy = factory()->NewVariableProxy( |
| 4672 function_state_->generator_object_variable()); | 4675 function_state_->generator_object_variable()); |
| 4673 Assignment* assignment = factory()->NewAssignment( | 4676 Assignment* assignment = factory()->NewAssignment( |
| 4674 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); | 4677 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); |
| 4675 VariableProxy* get_proxy = factory()->NewVariableProxy( | 4678 VariableProxy* get_proxy = factory()->NewVariableProxy( |
| 4676 function_state_->generator_object_variable()); | 4679 function_state_->generator_object_variable()); |
| 4677 Yield* yield = | 4680 Yield* yield = |
| 4678 factory()->NewYield(get_proxy, assignment, RelocInfo::kNoPosition); | 4681 factory()->NewYield(get_proxy, assignment, RelocInfo::kNoPosition); |
| 4679 try_block->statements()->Add( | 4682 try_block->statements()->Add( |
| 4680 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), | 4683 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), |
| (...skipping 2363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7044 try_block, target); | 7047 try_block, target); |
| 7045 final_loop = target; | 7048 final_loop = target; |
| 7046 } | 7049 } |
| 7047 | 7050 |
| 7048 return final_loop; | 7051 return final_loop; |
| 7049 } | 7052 } |
| 7050 | 7053 |
| 7051 | 7054 |
| 7052 } // namespace internal | 7055 } // namespace internal |
| 7053 } // namespace v8 | 7056 } // namespace v8 |
| OLD | NEW |