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 4361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4372 Expression* expr = args->at(0); | 4372 Expression* expr = args->at(0); |
4373 for (int i = 1; i < args->length(); ++i) { | 4373 for (int i = 1; i < args->length(); ++i) { |
4374 expr = factory()->NewBinaryOperation(Token::COMMA, expr, args->at(i), | 4374 expr = factory()->NewBinaryOperation(Token::COMMA, expr, args->at(i), |
4375 expr->position()); | 4375 expr->position()); |
4376 } | 4376 } |
4377 return expr; | 4377 return expr; |
4378 } | 4378 } |
4379 | 4379 |
4380 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { | 4380 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { |
4381 // yield do { | 4381 // yield do { |
4382 // promise_tmp = .promise; | |
4382 // tmp = <operand>; | 4383 // tmp = <operand>; |
4383 // tmp = %AsyncFunctionAwait(.generator_object, tmp); | 4384 // %AsyncFunctionAwait(.generator_object, tmp, promise_tmp); |
4385 // promise_tmp | |
4384 // } | 4386 // } |
4385 Variable* generator_object_variable = | 4387 Variable* generator_object_variable = |
4386 function_state_->generator_object_variable(); | 4388 function_state_->generator_object_variable(); |
4387 | 4389 |
4388 // If generator_object_variable is null, | 4390 // If generator_object_variable is null, |
4389 if (!generator_object_variable) return value; | 4391 if (!generator_object_variable) return value; |
4390 | 4392 |
4391 const int nopos = kNoSourcePosition; | 4393 const int nopos = kNoSourcePosition; |
4392 | 4394 |
4393 Variable* temp_var = NewTemporary(ast_value_factory()->empty_string()); | 4395 Variable* temp_var = NewTemporary(ast_value_factory()->empty_string()); |
4394 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos); | 4396 Block* do_block = factory()->NewBlock(nullptr, 2, false, nopos); |
4395 | 4397 |
4396 // Wrap value evaluation to provide a break location. | 4398 // Wrap value evaluation to provide a break location. |
4399 Variable* promise_temp_var = | |
adamk
2016/09/15 22:39:40
Why do we need a new var here? Is something going
Dan Ehrenberg
2016/09/17 00:04:31
- To output something from a block, we need a Vari
| |
4400 NewTemporary(ast_value_factory()->empty_string()); | |
4401 Expression* promise_assignment = factory()->NewAssignment( | |
4402 Token::ASSIGN, factory()->NewVariableProxy(promise_temp_var), | |
4403 BuildDotPromise(), nopos); | |
4404 do_block->statements()->Add( | |
4405 factory()->NewExpressionStatement(promise_assignment, value->position()), | |
adamk
2016/09/15 22:39:40
Is it important that this uses the same position a
Dan Ehrenberg
2016/09/17 00:04:31
It does not; changed it to nopos.
| |
4406 zone()); | |
4407 | |
4397 Expression* value_assignment = factory()->NewAssignment( | 4408 Expression* value_assignment = factory()->NewAssignment( |
4398 Token::ASSIGN, factory()->NewVariableProxy(temp_var), value, nopos); | 4409 Token::ASSIGN, factory()->NewVariableProxy(temp_var), value, nopos); |
4399 do_block->statements()->Add( | 4410 do_block->statements()->Add( |
4400 factory()->NewExpressionStatement(value_assignment, value->position()), | 4411 factory()->NewExpressionStatement(value_assignment, value->position()), |
4401 zone()); | 4412 zone()); |
4402 | 4413 |
4403 ZoneList<Expression*>* async_function_await_args = | 4414 ZoneList<Expression*>* async_function_await_args = |
4404 new (zone()) ZoneList<Expression*>(2, zone()); | 4415 new (zone()) ZoneList<Expression*>(3, zone()); |
4405 Expression* generator_object = | 4416 Expression* generator_object = |
4406 factory()->NewVariableProxy(generator_object_variable); | 4417 factory()->NewVariableProxy(generator_object_variable); |
4407 async_function_await_args->Add(generator_object, zone()); | 4418 async_function_await_args->Add(generator_object, zone()); |
4408 async_function_await_args->Add(factory()->NewVariableProxy(temp_var), zone()); | 4419 async_function_await_args->Add(factory()->NewVariableProxy(temp_var), zone()); |
4420 async_function_await_args->Add(factory()->NewVariableProxy(promise_temp_var), | |
4421 zone()); | |
4409 | 4422 |
4410 // The parser emits calls to AsyncFunctionAwaitCaught, but the | 4423 // The parser emits calls to AsyncFunctionAwaitCaught, but the |
4411 // AstNumberingVisitor will rewrite this to AsyncFunctionAwaitUncaught | 4424 // AstNumberingVisitor will rewrite this to AsyncFunctionAwaitUncaught |
4412 // if there is no local enclosing try/catch block. | 4425 // if there is no local enclosing try/catch block. |
4413 Expression* async_function_await = | 4426 Expression* async_function_await = |
4414 factory()->NewCallRuntime(Context::ASYNC_FUNCTION_AWAIT_CAUGHT_INDEX, | 4427 factory()->NewCallRuntime(Context::ASYNC_FUNCTION_AWAIT_CAUGHT_INDEX, |
4415 async_function_await_args, nopos); | 4428 async_function_await_args, nopos); |
4429 do_block->statements()->Add( | |
4430 factory()->NewExpressionStatement(async_function_await, await_pos), | |
4431 zone()); | |
4416 | 4432 |
4417 // Wrap await to provide a break location between value evaluation and yield. | 4433 // Wrap await to provide a break location between value evaluation and yield. |
4418 Expression* await_assignment = factory()->NewAssignment( | 4434 Expression* do_expr = |
4419 Token::ASSIGN, factory()->NewVariableProxy(temp_var), | 4435 factory()->NewDoExpression(do_block, promise_temp_var, nopos); |
4420 async_function_await, nopos); | |
4421 do_block->statements()->Add( | |
4422 factory()->NewExpressionStatement(await_assignment, await_pos), zone()); | |
4423 Expression* do_expr = factory()->NewDoExpression(do_block, temp_var, nopos); | |
4424 | 4436 |
4425 generator_object = factory()->NewVariableProxy(generator_object_variable); | 4437 generator_object = factory()->NewVariableProxy(generator_object_variable); |
4426 return factory()->NewYield(generator_object, do_expr, nopos, | 4438 return factory()->NewYield(generator_object, do_expr, nopos, |
4427 Yield::kOnExceptionRethrow); | 4439 Yield::kOnExceptionRethrow); |
4428 } | 4440 } |
4429 | 4441 |
4430 class NonPatternRewriter : public AstExpressionRewriter { | 4442 class NonPatternRewriter : public AstExpressionRewriter { |
4431 public: | 4443 public: |
4432 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) | 4444 NonPatternRewriter(uintptr_t stack_limit, Parser* parser) |
4433 : AstExpressionRewriter(stack_limit), parser_(parser) {} | 4445 : AstExpressionRewriter(stack_limit), parser_(parser) {} |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5627 node->Print(Isolate::Current()); | 5639 node->Print(Isolate::Current()); |
5628 } | 5640 } |
5629 #endif // DEBUG | 5641 #endif // DEBUG |
5630 | 5642 |
5631 #undef CHECK_OK | 5643 #undef CHECK_OK |
5632 #undef CHECK_OK_VOID | 5644 #undef CHECK_OK_VOID |
5633 #undef CHECK_FAILED | 5645 #undef CHECK_FAILED |
5634 | 5646 |
5635 } // namespace internal | 5647 } // namespace internal |
5636 } // namespace v8 | 5648 } // namespace v8 |
OLD | NEW |