| 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 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 Expression* is_undefined = factory()->NewCompareOperation( | 1608 Expression* is_undefined = factory()->NewCompareOperation( |
| 1609 Token::EQ_STRICT, assign, | 1609 Token::EQ_STRICT, assign, |
| 1610 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); | 1610 factory()->NewUndefinedLiteral(kNoSourcePosition), pos); |
| 1611 | 1611 |
| 1612 // is_undefined ? this : is_object_conditional | 1612 // is_undefined ? this : is_object_conditional |
| 1613 return_value = factory()->NewConditional(is_undefined, ThisExpression(pos), | 1613 return_value = factory()->NewConditional(is_undefined, ThisExpression(pos), |
| 1614 is_object_conditional, pos); | 1614 is_object_conditional, pos); |
| 1615 } | 1615 } |
| 1616 if (is_generator()) { | 1616 if (is_generator()) { |
| 1617 return_value = BuildIteratorResult(return_value, true); | 1617 return_value = BuildIteratorResult(return_value, true); |
| 1618 } else if (is_async_function()) { | |
| 1619 return_value = BuildResolvePromise(return_value, return_value->position()); | |
| 1620 } | 1618 } |
| 1621 return return_value; | 1619 return return_value; |
| 1622 } | 1620 } |
| 1623 | 1621 |
| 1624 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { | 1622 Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) { |
| 1625 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); | 1623 Variable* result = NewTemporary(ast_value_factory()->dot_result_string()); |
| 1626 DoExpression* expr = factory()->NewDoExpression(body, result, pos); | 1624 DoExpression* expr = factory()->NewDoExpression(body, result, pos); |
| 1627 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { | 1625 if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) { |
| 1628 *ok = false; | 1626 *ok = false; |
| 1629 return nullptr; | 1627 return nullptr; |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2472 void Parser::PrepareGeneratorVariables() { | 2470 void Parser::PrepareGeneratorVariables() { |
| 2473 // For generators, allocating variables in contexts is currently a win because | 2471 // For generators, allocating variables in contexts is currently a win because |
| 2474 // it minimizes the work needed to suspend and resume an activation. The | 2472 // it minimizes the work needed to suspend and resume an activation. The |
| 2475 // code produced for generators relies on this forced context allocation (it | 2473 // code produced for generators relies on this forced context allocation (it |
| 2476 // does not restore the frame's parameters upon resume). | 2474 // does not restore the frame's parameters upon resume). |
| 2477 function_state_->scope()->ForceContextAllocation(); | 2475 function_state_->scope()->ForceContextAllocation(); |
| 2478 | 2476 |
| 2479 // Calling a generator returns a generator object. That object is stored | 2477 // Calling a generator returns a generator object. That object is stored |
| 2480 // in a temporary variable, a definition that is used by "yield" | 2478 // in a temporary variable, a definition that is used by "yield" |
| 2481 // expressions. | 2479 // expressions. |
| 2482 Variable* temp = | 2480 function_state_->scope()->DeclareGeneratorObjectVar( |
| 2483 NewTemporary(ast_value_factory()->dot_generator_object_string()); | 2481 ast_value_factory()->dot_generator_object_string()); |
| 2484 function_state_->set_generator_object_variable(temp); | |
| 2485 } | 2482 } |
| 2486 | 2483 |
| 2487 FunctionLiteral* Parser::ParseFunctionLiteral( | 2484 FunctionLiteral* Parser::ParseFunctionLiteral( |
| 2488 const AstRawString* function_name, Scanner::Location function_name_location, | 2485 const AstRawString* function_name, Scanner::Location function_name_location, |
| 2489 FunctionNameValidity function_name_validity, FunctionKind kind, | 2486 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 2490 int function_token_pos, FunctionLiteral::FunctionType function_type, | 2487 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 2491 LanguageMode language_mode, bool* ok) { | 2488 LanguageMode language_mode, bool* ok) { |
| 2492 // Function :: | 2489 // Function :: |
| 2493 // '(' FormalParameterList? ')' '{' FunctionBody '}' | 2490 // '(' FormalParameterList? ')' '{' FunctionBody '}' |
| 2494 // | 2491 // |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3088 Token::COMMA, call_runtime, | 3085 Token::COMMA, call_runtime, |
| 3089 factory()->NewVariableProxy(PromiseVariable()), pos); | 3086 factory()->NewVariableProxy(PromiseVariable()), pos); |
| 3090 } | 3087 } |
| 3091 | 3088 |
| 3092 Variable* Parser::PromiseVariable() { | 3089 Variable* Parser::PromiseVariable() { |
| 3093 // Based on the various compilation paths, there are many different code | 3090 // Based on the various compilation paths, there are many different code |
| 3094 // paths which may be the first to access the Promise temporary. Whichever | 3091 // paths which may be the first to access the Promise temporary. Whichever |
| 3095 // comes first should create it and stash it in the FunctionState. | 3092 // comes first should create it and stash it in the FunctionState. |
| 3096 Variable* promise = function_state_->promise_variable(); | 3093 Variable* promise = function_state_->promise_variable(); |
| 3097 if (function_state_->promise_variable() == nullptr) { | 3094 if (function_state_->promise_variable() == nullptr) { |
| 3098 promise = scope()->NewTemporary(ast_value_factory()->empty_string()); | 3095 promise = function_state_->scope()->DeclarePromiseVar( |
| 3099 function_state_->set_promise_variable(promise); | 3096 ast_value_factory()->empty_string()); |
| 3100 } | 3097 } |
| 3101 return promise; | 3098 return promise; |
| 3102 } | 3099 } |
| 3103 | 3100 |
| 3104 Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { | 3101 Expression* Parser::BuildInitialYield(int pos, FunctionKind kind) { |
| 3105 Assignment* assignment = BuildCreateJSGeneratorObject(pos, kind); | 3102 Assignment* assignment = BuildCreateJSGeneratorObject(pos, kind); |
| 3106 VariableProxy* generator = | 3103 VariableProxy* generator = |
| 3107 factory()->NewVariableProxy(function_state_->generator_object_variable()); | 3104 factory()->NewVariableProxy(function_state_->generator_object_variable()); |
| 3108 // The position of the yield is important for reporting the exception | 3105 // The position of the yield is important for reporting the exception |
| 3109 // caused by calling the .throw method on a generator suspended at the | 3106 // caused by calling the .throw method on a generator suspended at the |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5026 | 5023 |
| 5027 return final_loop; | 5024 return final_loop; |
| 5028 } | 5025 } |
| 5029 | 5026 |
| 5030 #undef CHECK_OK | 5027 #undef CHECK_OK |
| 5031 #undef CHECK_OK_VOID | 5028 #undef CHECK_OK_VOID |
| 5032 #undef CHECK_FAILED | 5029 #undef CHECK_FAILED |
| 5033 | 5030 |
| 5034 } // namespace internal | 5031 } // namespace internal |
| 5035 } // namespace v8 | 5032 } // namespace v8 |
| OLD | NEW |