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 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 Expression* is_undefined = factory()->NewCompareOperation( | 1604 Expression* is_undefined = factory()->NewCompareOperation( |
1605 Token::EQ_STRICT, assign, | 1605 Token::EQ_STRICT, assign, |
1606 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); | 1606 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); |
1607 | 1607 |
1608 // is_undefined ? this : is_object_conditional | 1608 // is_undefined ? this : is_object_conditional |
1609 return_value = factory()->NewConditional(is_undefined, ThisExpression(pos), | 1609 return_value = factory()->NewConditional(is_undefined, ThisExpression(pos), |
1610 is_object_conditional, pos); | 1610 is_object_conditional, pos); |
1611 } | 1611 } |
1612 if (is_generator()) { | 1612 if (is_generator()) { |
1613 return_value = BuildIteratorResult(return_value, true); | 1613 return_value = BuildIteratorResult(return_value, true); |
1614 } else if (is_async_function()) { | |
1615 return_value = BuildResolvePromise(return_value, return_value->position()); | |
1616 } | 1614 } |
1617 return return_value; | 1615 return return_value; |
1618 } | 1616 } |
1619 | 1617 |
1620 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { | 1618 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { |
1621 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); | 1619 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); |
1622 DoExpression* expr = factory()->NewDoExpression(body, result, pos); | 1620 DoExpression* expr = factory()->NewDoExpression(body, result, pos); |
1623 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { | 1621 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { |
1624 *ok = false; | 1622 *ok = false; |
1625 return nullptr; | 1623 return nullptr; |
(...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3640 | 3638 |
3641 // This method intoduces the line initializing the generator object | 3639 // This method intoduces the line initializing the generator object |
3642 // when desugaring the body of async_function. | 3640 // when desugaring the body of async_function. |
3643 void Parser::PrepareAsyncFunctionBody(ZoneList<Statement*>* body, | 3641 void Parser::PrepareAsyncFunctionBody(ZoneList<Statement*>* body, |
3644 FunctionKind kind, int pos) { | 3642 FunctionKind kind, int pos) { |
3645 // When parsing an async arrow function, we get here without having called | 3643 // When parsing an async arrow function, we get here without having called |
3646 // PrepareGeneratorVariables yet, so do it now. | 3644 // PrepareGeneratorVariables yet, so do it now. |
3647 if (function_state_->generator_object_variable() == nullptr) { | 3645 if (function_state_->generator_object_variable() == nullptr) { |
3648 PrepareGeneratorVariables(); | 3646 PrepareGeneratorVariables(); |
3649 } | 3647 } |
| 3648 Variable* promise_var = PromiseVariable(); |
| 3649 DCHECK_NOT_NULL(promise_var); |
| 3650 USE(promise_var); |
3650 } | 3651 } |
3651 | 3652 |
3652 // This method completes the desugaring of the body of async_function. | 3653 // This method completes the desugaring of the body of async_function. |
3653 void Parser::RewriteAsyncFunctionBody(ZoneList<Statement*>* body, | 3654 void Parser::RewriteAsyncFunctionBody(ZoneList<Statement*>* body, |
3654 Expression* return_value, bool* ok) { | 3655 Expression* return_value, bool* ok) { |
3655 // function async_function() { | 3656 // function async_function() { |
3656 // .generator_object = %CreateJSGeneratorObject(); | 3657 // .generator_object = %CreateJSGeneratorObject(); |
3657 // BuildRejectPromiseOnException({ | 3658 // BuildRejectPromiseOnException({ |
3658 // ... block ... | 3659 // ... block ... |
3659 // return %ResolvePromise(.promise, expr), .promise; | 3660 // return %ResolvePromise(.promise, expr), .promise; |
3660 // }) | 3661 // }) |
3661 // } | 3662 // } |
3662 | 3663 |
3663 return_value = BuildResolvePromise(return_value, return_value->position()); | |
3664 body->Add( | 3664 body->Add( |
3665 factory()->NewReturnStatement(return_value, return_value->position()), | 3665 factory()->NewReturnStatement(return_value, return_value->position()), |
3666 zone()); | 3666 zone()); |
3667 } | 3667 } |
3668 | 3668 |
3669 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { | 3669 Expression* Parser::RewriteAwaitExpression(Expression* value, int await_pos) { |
3670 // yield do { | 3670 // yield do { |
3671 // tmp = <operand>; | 3671 // tmp = <operand>; |
3672 // %AsyncFunctionAwait(.generator_object, tmp, .promise); | 3672 // %AsyncFunctionAwait(.generator_object, tmp, .promise); |
3673 // .promise | 3673 // .promise |
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4898 | 4898 |
4899 return final_loop; | 4899 return final_loop; |
4900 } | 4900 } |
4901 | 4901 |
4902 #undef CHECK_OK | 4902 #undef CHECK_OK |
4903 #undef CHECK_OK_VOID | 4903 #undef CHECK_OK_VOID |
4904 #undef CHECK_FAILED | 4904 #undef CHECK_FAILED |
4905 | 4905 |
4906 } // namespace internal | 4906 } // namespace internal |
4907 } // namespace v8 | 4907 } // namespace v8 |
OLD | NEW |