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 4723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4734 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); | 4734 factory()->NewBlock(nullptr, 3, false, RelocInfo::kNoPosition); |
4735 | 4735 |
4736 { | 4736 { |
4737 Expression* allocation = BuildCreateJSGeneratorObject(pos, kind); | 4737 Expression* allocation = BuildCreateJSGeneratorObject(pos, kind); |
4738 VariableProxy* init_proxy = factory()->NewVariableProxy( | 4738 VariableProxy* init_proxy = factory()->NewVariableProxy( |
4739 function_state_->generator_object_variable()); | 4739 function_state_->generator_object_variable()); |
4740 Assignment* assignment = factory()->NewAssignment( | 4740 Assignment* assignment = factory()->NewAssignment( |
4741 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); | 4741 Token::INIT, init_proxy, allocation, RelocInfo::kNoPosition); |
4742 VariableProxy* get_proxy = factory()->NewVariableProxy( | 4742 VariableProxy* get_proxy = factory()->NewVariableProxy( |
4743 function_state_->generator_object_variable()); | 4743 function_state_->generator_object_variable()); |
4744 Yield* yield = | 4744 // The position of the yield is important for reporting the exception |
4745 factory()->NewYield(get_proxy, assignment, RelocInfo::kNoPosition); | 4745 // caused by calling the .throw method on a generator suspended at the |
| 4746 // initial yield (i.e. right after generator instantiation). |
| 4747 Yield* yield = factory()->NewYield(get_proxy, assignment, |
| 4748 scope_->start_position()); |
4746 try_block->statements()->Add( | 4749 try_block->statements()->Add( |
4747 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), | 4750 factory()->NewExpressionStatement(yield, RelocInfo::kNoPosition), |
4748 zone()); | 4751 zone()); |
4749 } | 4752 } |
4750 | 4753 |
4751 ParseStatementList(try_block->statements(), Token::RBRACE, CHECK_OK); | 4754 ParseStatementList(try_block->statements(), Token::RBRACE, CHECK_OK); |
4752 | 4755 |
4753 Statement* final_return = factory()->NewReturnStatement( | 4756 Statement* final_return = factory()->NewReturnStatement( |
4754 BuildIteratorResult(nullptr, true), RelocInfo::kNoPosition); | 4757 BuildIteratorResult(nullptr, true), RelocInfo::kNoPosition); |
4755 try_block->statements()->Add(final_return, zone()); | 4758 try_block->statements()->Add(final_return, zone()); |
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6965 try_block, target); | 6968 try_block, target); |
6966 final_loop = target; | 6969 final_loop = target; |
6967 } | 6970 } |
6968 | 6971 |
6969 return final_loop; | 6972 return final_loop; |
6970 } | 6973 } |
6971 | 6974 |
6972 | 6975 |
6973 } // namespace internal | 6976 } // namespace internal |
6974 } // namespace v8 | 6977 } // namespace v8 |
OLD | NEW |