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 4637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4648 inner_scope->set_is_declaration_scope(); | 4648 inner_scope->set_is_declaration_scope(); |
4649 inner_scope->set_start_position(scanner()->location().beg_pos); | 4649 inner_scope->set_start_position(scanner()->location().beg_pos); |
4650 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); | 4650 inner_block = factory()->NewBlock(NULL, 8, true, RelocInfo::kNoPosition); |
4651 inner_block->set_scope(inner_scope); | 4651 inner_block->set_scope(inner_scope); |
4652 body = inner_block->statements(); | 4652 body = inner_block->statements(); |
4653 } | 4653 } |
4654 | 4654 |
4655 { | 4655 { |
4656 BlockState block_state(&scope_, inner_scope); | 4656 BlockState block_state(&scope_, inner_scope); |
4657 | 4657 |
4658 // For generators, allocate and yield an iterator on function entry. | 4658 // try { InitialYield; ...body...; FinalYield } |
Michael Starzinger
2016/01/25 12:56:05
nit: On top of the pseudo-code, can we add a descr
| |
4659 if (IsGeneratorFunction(kind)) { | 4659 // finally { %GeneratorClose(generator) } |
4660 ZoneList<Expression*>* arguments = | |
4661 new(zone()) ZoneList<Expression*>(0, zone()); | |
4662 CallRuntime* allocation = factory()->NewCallRuntime( | |
4663 Runtime::kCreateJSGeneratorObject, arguments, pos); | |
4664 VariableProxy* init_proxy = factory()->NewVariableProxy( | |
4665 function_state_->generator_object_variable()); | |
4666 Assignment* assignment = factory()->NewAssignment( | |
4667 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); | |
4668 VariableProxy* get_proxy = factory()->NewVariableProxy( | |
4669 function_state_->generator_object_variable()); | |
4670 Yield* yield = factory()->NewYield( | |
4671 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); | |
4672 body->Add(factory()->NewExpressionStatement( | |
4673 yield, RelocInfo::kNoPosition), zone()); | |
4674 } | |
4675 | |
4676 ParseStatementList(body, Token::RBRACE, CHECK_OK); | |
4677 | 4660 |
4678 if (IsGeneratorFunction(kind)) { | 4661 if (IsGeneratorFunction(kind)) { |
4662 Block* try_block = | |
4663 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); | |
4664 | |
4665 { | |
4666 ZoneList<Expression*>* arguments = | |
4667 new (zone()) ZoneList<Expression*>(0, zone()); | |
4668 CallRuntime* allocation = factory()->NewCallRuntime( | |
4669 Runtime::kCreateJSGeneratorObject, arguments, pos); | |
4670 VariableProxy* init_proxy = factory()->NewVariableProxy( | |
4671 function_state_->generator_object_variable()); | |
4672 Assignment* assignment = factory()->NewAssignment( | |
4673 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); | |
4674 VariableProxy* get_proxy = factory()->NewVariableProxy( | |
4675 function_state_->generator_object_variable()); | |
4676 Yield* yield = factory()->NewYield( | |
4677 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); | |
4678 try_block->statements()->Add( | |
4679 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), | |
4680 zone()); | |
4681 } | |
4682 | |
4683 ParseStatementList(try_block->statements(), Token::RBRACE, CHECK_OK); | |
4684 | |
4679 VariableProxy* get_proxy = factory()->NewVariableProxy( | 4685 VariableProxy* get_proxy = factory()->NewVariableProxy( |
4680 function_state_->generator_object_variable()); | 4686 function_state_->generator_object_variable()); |
4681 Expression* undefined = | 4687 Expression* undefined = |
4682 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); | 4688 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); |
4683 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::kFinal, | 4689 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::kFinal, |
4684 RelocInfo::kNoPosition); | 4690 RelocInfo::kNoPosition); |
4685 body->Add(factory()->NewExpressionStatement( | 4691 try_block->statements()->Add( |
4686 yield, RelocInfo::kNoPosition), zone()); | 4692 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), |
4693 zone()); | |
4694 | |
4695 Block* finally_block = | |
4696 factory()->NewBlock(nullptr, 1, false, RelocInfo::kNoPosition); | |
4697 ZoneList<Expression*>* args = | |
4698 new (zone()) ZoneList<Expression*>(1, zone()); | |
4699 VariableProxy* call_proxy = factory()->NewVariableProxy( | |
4700 function_state_->generator_object_variable()); | |
4701 args->Add(call_proxy, zone()); | |
4702 Expression* call = factory()->NewCallRuntime( | |
4703 Runtime::kGeneratorClose, args, RelocInfo::kNoPosition); | |
4704 finally_block->statements()->Add( | |
4705 factory()->NewExpressionStatement(call, RelocInfo::kNoPosition), | |
4706 zone()); | |
4707 | |
4708 body->Add(factory()->NewTryFinallyStatement(try_block, finally_block, | |
4709 RelocInfo::kNoPosition), | |
4710 zone()); | |
4711 } else { | |
4712 ParseStatementList(body, Token::RBRACE, CHECK_OK); | |
4687 } | 4713 } |
4688 | 4714 |
4689 if (IsSubclassConstructor(kind)) { | 4715 if (IsSubclassConstructor(kind)) { |
4690 body->Add( | 4716 body->Add( |
4691 factory()->NewReturnStatement( | 4717 factory()->NewReturnStatement( |
4692 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), | 4718 this->ThisExpression(scope_, factory(), RelocInfo::kNoPosition), |
4693 RelocInfo::kNoPosition), | 4719 RelocInfo::kNoPosition), |
4694 zone()); | 4720 zone()); |
4695 } | 4721 } |
4696 } | 4722 } |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5733 auto class_literal = value->AsClassLiteral(); | 5759 auto class_literal = value->AsClassLiteral(); |
5734 if (class_literal->raw_name() == nullptr) { | 5760 if (class_literal->raw_name() == nullptr) { |
5735 class_literal->set_raw_name(name); | 5761 class_literal->set_raw_name(name); |
5736 } | 5762 } |
5737 } | 5763 } |
5738 } | 5764 } |
5739 | 5765 |
5740 | 5766 |
5741 } // namespace internal | 5767 } // namespace internal |
5742 } // namespace v8 | 5768 } // namespace v8 |
OLD | NEW |