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 4678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4689 body = inner_block->statements(); | 4689 body = inner_block->statements(); |
4690 } | 4690 } |
4691 | 4691 |
4692 { | 4692 { |
4693 BlockState block_state(&scope_, inner_scope); | 4693 BlockState block_state(&scope_, inner_scope); |
4694 | 4694 |
4695 if (IsGeneratorFunction(kind)) { | 4695 if (IsGeneratorFunction(kind)) { |
4696 // We produce: | 4696 // We produce: |
4697 // | 4697 // |
4698 // try { InitialYield; ...body...; return {value: undefined, done: true} } | 4698 // try { InitialYield; ...body...; return {value: undefined, done: true} } |
4699 // finally { %GeneratorClose(generator) } | 4699 // finally { %_GeneratorClose(generator) } |
4700 // | 4700 // |
4701 // - InitialYield yields the actual generator object. | 4701 // - InitialYield yields the actual generator object. |
4702 // - Any return statement inside the body will have its argument wrapped | 4702 // - Any return statement inside the body will have its argument wrapped |
4703 // in a "done" iterator result object. | 4703 // in a "done" iterator result object. |
4704 // - If the generator terminates for whatever reason, we must close it. | 4704 // - If the generator terminates for whatever reason, we must close it. |
4705 // Hence the finally clause. | 4705 // Hence the finally clause. |
4706 | 4706 |
4707 Block* try_block = | 4707 Block* try_block = |
4708 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); | 4708 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); |
4709 | 4709 |
(...skipping 19 matching lines...) Expand all Loading... |
4729 try_block->statements()->Add(final_return, zone()); | 4729 try_block->statements()->Add(final_return, zone()); |
4730 | 4730 |
4731 Block* finally_block = | 4731 Block* finally_block = |
4732 factory()->NewBlock(nullptr, 1, false, RelocInfo::kNoPosition); | 4732 factory()->NewBlock(nullptr, 1, false, RelocInfo::kNoPosition); |
4733 ZoneList<Expression*>* args = | 4733 ZoneList<Expression*>* args = |
4734 new (zone()) ZoneList<Expression*>(1, zone()); | 4734 new (zone()) ZoneList<Expression*>(1, zone()); |
4735 VariableProxy* call_proxy = factory()->NewVariableProxy( | 4735 VariableProxy* call_proxy = factory()->NewVariableProxy( |
4736 function_state_->generator_object_variable()); | 4736 function_state_->generator_object_variable()); |
4737 args->Add(call_proxy, zone()); | 4737 args->Add(call_proxy, zone()); |
4738 Expression* call = factory()->NewCallRuntime( | 4738 Expression* call = factory()->NewCallRuntime( |
4739 Runtime::kGeneratorClose, args, RelocInfo::kNoPosition); | 4739 Runtime::kInlineGeneratorClose, args, RelocInfo::kNoPosition); |
4740 finally_block->statements()->Add( | 4740 finally_block->statements()->Add( |
4741 factory()->NewExpressionStatement(call, RelocInfo::kNoPosition), | 4741 factory()->NewExpressionStatement(call, RelocInfo::kNoPosition), |
4742 zone()); | 4742 zone()); |
4743 | 4743 |
4744 body->Add(factory()->NewTryFinallyStatement(try_block, finally_block, | 4744 body->Add(factory()->NewTryFinallyStatement(try_block, finally_block, |
4745 RelocInfo::kNoPosition), | 4745 RelocInfo::kNoPosition), |
4746 zone()); | 4746 zone()); |
4747 } else if (IsAsyncFunction(kind)) { | 4747 } else if (IsAsyncFunction(kind)) { |
4748 const bool accept_IN = true; | 4748 const bool accept_IN = true; |
4749 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, | 4749 DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, |
(...skipping 2162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6912 try_block, target); | 6912 try_block, target); |
6913 final_loop = target; | 6913 final_loop = target; |
6914 } | 6914 } |
6915 | 6915 |
6916 return final_loop; | 6916 return final_loop; |
6917 } | 6917 } |
6918 | 6918 |
6919 | 6919 |
6920 } // namespace internal | 6920 } // namespace internal |
6921 } // namespace v8 | 6921 } // namespace v8 |
OLD | NEW |