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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 4765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4776 Expression* Parser::ExpressionListToExpression(ZoneList<Expression*>* args) { | 4776 Expression* Parser::ExpressionListToExpression(ZoneList<Expression*>* args) { |
4777 Expression* expr = args->at(0); | 4777 Expression* expr = args->at(0); |
4778 for (int i = 1; i < args->length(); ++i) { | 4778 for (int i = 1; i < args->length(); ++i) { |
4779 expr = factory()->NewBinaryOperation(Token::COMMA, expr, args->at(i), | 4779 expr = factory()->NewBinaryOperation(Token::COMMA, expr, args->at(i), |
4780 expr->position()); | 4780 expr->position()); |
4781 } | 4781 } |
4782 return expr; | 4782 return expr; |
4783 } | 4783 } |
4784 | 4784 |
4785 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { | 4785 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { |
4786 // yield %AsyncFunctionAwait(.generator_object, <operand>) | 4786 // yield do { |
| 4787 // tmp = <operand>; |
| 4788 // tmp = %AsyncFunctionAwait(.generator_object, tmp); |
| 4789 // } |
4787 Variable* generator_object_variable = | 4790 Variable* generator_object_variable = |
4788 function_state_->generator_object_variable(); | 4791 function_state_->generator_object_variable(); |
4789 | 4792 |
4790 // If generator_object_variable is null, | 4793 // If generator_object_variable is null, |
4791 if (!generator_object_variable) return value; | 4794 if (!generator_object_variable) return value; |
4792 | 4795 |
4793 const int nopos = kNoSourcePosition; | 4796 const int nopos = kNoSourcePosition; |
4794 | 4797 |
4795 Variable* temp_var = NewTemporary(ast_value_factory()->empty_string()); | 4798 Variable* temp_var = NewTemporary(ast_value_factory()->empty_string()); |
4796 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp_var); | |
4797 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos); | 4799 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos); |
4798 | 4800 |
4799 // Wrap value evaluation to provide a break location. | 4801 // Wrap value evaluation to provide a break location. |
4800 Expression* value_assignment = | 4802 Expression* value_assignment = factory()->NewAssignment( |
4801 factory()->NewAssignment(Token::ASSIGN, temp_proxy, value, nopos); | 4803 Token::ASSIGN, factory()->NewVariableProxy(temp_var), value, nopos); |
4802 do_block->statements()->Add( | 4804 do_block->statements()->Add( |
4803 factory()->NewExpressionStatement(value_assignment, value->position()), | 4805 factory()->NewExpressionStatement(value_assignment, value->position()), |
4804 zone()); | 4806 zone()); |
4805 | 4807 |
4806 ZoneList<Expression*>* async_function_await_args = | 4808 ZoneList<Expression*>* async_function_await_args = |
4807 new (zone()) ZoneList<Expression*>(2, zone()); | 4809 new (zone()) ZoneList<Expression*>(2, zone()); |
4808 Expression* generator_object = | 4810 Expression* generator_object = |
4809 factory()->NewVariableProxy(generator_object_variable); | 4811 factory()->NewVariableProxy(generator_object_variable); |
4810 async_function_await_args->Add(generator_object, zone()); | 4812 async_function_await_args->Add(generator_object, zone()); |
4811 async_function_await_args->Add(temp_proxy, zone()); | 4813 async_function_await_args->Add(factory()->NewVariableProxy(temp_var), zone()); |
4812 Expression* async_function_await = factory()->NewCallRuntime( | 4814 Expression* async_function_await = factory()->NewCallRuntime( |
4813 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos); | 4815 Context::ASYNC_FUNCTION_AWAIT_INDEX, async_function_await_args, nopos); |
| 4816 |
4814 // Wrap await to provide a break location between value evaluation and yield. | 4817 // Wrap await to provide a break location between value evaluation and yield. |
4815 Expression* await_assignment = factory()->NewAssignment( | 4818 Expression* await_assignment = factory()->NewAssignment( |
4816 Token::ASSIGN, temp_proxy, async_function_await, nopos); | 4819 Token::ASSIGN, factory()->NewVariableProxy(temp_var), |
| 4820 async_function_await, nopos); |
4817 do_block->statements()->Add( | 4821 do_block->statements()->Add( |
4818 factory()->NewExpressionStatement(await_assignment, await_pos), zone()); | 4822 factory()->NewExpressionStatement(await_assignment, await_pos), zone()); |
4819 Expression* do_expr = factory()->NewDoExpression(do_block, temp_var, nopos); | 4823 Expression* do_expr = factory()->NewDoExpression(do_block, temp_var, nopos); |
4820 | 4824 |
4821 generator_object = factory()->NewVariableProxy(generator_object_variable); | 4825 generator_object = factory()->NewVariableProxy(generator_object_variable); |
4822 return factory()->NewYield(generator_object, do_expr, nopos, | 4826 return factory()->NewYield(generator_object, do_expr, nopos, |
4823 Yield::kOnExceptionRethrow); | 4827 Yield::kOnExceptionRethrow); |
4824 } | 4828 } |
4825 | 4829 |
4826 class NonPatternRewriter : public AstExpressionRewriter { | 4830 class NonPatternRewriter : public AstExpressionRewriter { |
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6024 node->Print(Isolate::Current()); | 6028 node->Print(Isolate::Current()); |
6025 } | 6029 } |
6026 #endif // DEBUG | 6030 #endif // DEBUG |
6027 | 6031 |
6028 #undef CHECK_OK | 6032 #undef CHECK_OK |
6029 #undef CHECK_OK_VOID | 6033 #undef CHECK_OK_VOID |
6030 #undef CHECK_FAILED | 6034 #undef CHECK_FAILED |
6031 | 6035 |
6032 } // namespace internal | 6036 } // namespace internal |
6033 } // namespace v8 | 6037 } // namespace v8 |
OLD | NEW |