| 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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 547 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
| 548 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && | 548 set_allow_tailcalls(FLAG_harmony_tailcalls && !info->is_native() && |
| 549 info->isolate()->is_tail_call_elimination_enabled()); | 549 info->isolate()->is_tail_call_elimination_enabled()); |
| 550 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); | 550 set_allow_harmony_do_expressions(FLAG_harmony_do_expressions); |
| 551 set_allow_harmony_function_sent(FLAG_harmony_function_sent); | 551 set_allow_harmony_function_sent(FLAG_harmony_function_sent); |
| 552 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); | 552 set_allow_harmony_restrictive_generators(FLAG_harmony_restrictive_generators); |
| 553 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); | 553 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); |
| 554 set_allow_harmony_class_fields(FLAG_harmony_class_fields); | 554 set_allow_harmony_class_fields(FLAG_harmony_class_fields); |
| 555 set_allow_harmony_object_rest_spread(FLAG_harmony_object_rest_spread); | 555 set_allow_harmony_object_rest_spread(FLAG_harmony_object_rest_spread); |
| 556 set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import); | 556 set_allow_harmony_dynamic_import(FLAG_harmony_dynamic_import); |
| 557 set_allow_harmony_async_iteration(FLAG_harmony_async_iteration); |
| 557 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 558 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 558 ++feature) { | 559 ++feature) { |
| 559 use_counts_[feature] = 0; | 560 use_counts_[feature] = 0; |
| 560 } | 561 } |
| 561 if (info->ast_value_factory() == NULL) { | 562 if (info->ast_value_factory() == NULL) { |
| 562 // info takes ownership of AstValueFactory. | 563 // info takes ownership of AstValueFactory. |
| 563 info->set_ast_value_factory(new AstValueFactory( | 564 info->set_ast_value_factory(new AstValueFactory( |
| 564 zone(), info->isolate()->ast_string_constants(), info->hash_seed())); | 565 zone(), info->isolate()->ast_string_constants(), info->hash_seed())); |
| 565 info->set_ast_value_factory_owned(); | 566 info->set_ast_value_factory_owned(); |
| 566 ast_value_factory_ = info->ast_value_factory(); | 567 ast_value_factory_ = info->ast_value_factory(); |
| (...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1815 statement = factory()->NewExpressionStatement( | 1816 statement = factory()->NewExpressionStatement( |
| 1816 factory()->NewAssignment(Token::INIT, fproxy, | 1817 factory()->NewAssignment(Token::INIT, fproxy, |
| 1817 factory()->NewThisFunction(pos), | 1818 factory()->NewThisFunction(pos), |
| 1818 kNoSourcePosition), | 1819 kNoSourcePosition), |
| 1819 kNoSourcePosition); | 1820 kNoSourcePosition); |
| 1820 } | 1821 } |
| 1821 result->Set(index, statement); | 1822 result->Set(index, statement); |
| 1822 } | 1823 } |
| 1823 } | 1824 } |
| 1824 | 1825 |
| 1825 // !%_IsJSReceiver(result = iterator.next()) && | 1826 // [if (IteratorType == kNormal)] |
| 1826 // %ThrowIteratorResultNotAnObject(result) | 1827 // !%_IsJSReceiver(result = iterator.next()) && |
| 1828 // %ThrowIteratorResultNotAnObject(result) |
| 1829 // [else if (IteratorType == kAsync)] |
| 1830 // !%_IsJSReceiver(result = Await(iterator.next())) && |
| 1831 // %ThrowIteratorResultNotAnObject(result) |
| 1832 // [endif] |
| 1827 Expression* Parser::BuildIteratorNextResult(Expression* iterator, | 1833 Expression* Parser::BuildIteratorNextResult(Expression* iterator, |
| 1828 Variable* result, int pos) { | 1834 Variable* result, IteratorType type, |
| 1835 int pos) { |
| 1829 Expression* next_literal = factory()->NewStringLiteral( | 1836 Expression* next_literal = factory()->NewStringLiteral( |
| 1830 ast_value_factory()->next_string(), kNoSourcePosition); | 1837 ast_value_factory()->next_string(), kNoSourcePosition); |
| 1831 Expression* next_property = | 1838 Expression* next_property = |
| 1832 factory()->NewProperty(iterator, next_literal, kNoSourcePosition); | 1839 factory()->NewProperty(iterator, next_literal, kNoSourcePosition); |
| 1833 ZoneList<Expression*>* next_arguments = | 1840 ZoneList<Expression*>* next_arguments = |
| 1834 new (zone()) ZoneList<Expression*>(0, zone()); | 1841 new (zone()) ZoneList<Expression*>(0, zone()); |
| 1835 Expression* next_call = | 1842 Expression* next_call = |
| 1836 factory()->NewCall(next_property, next_arguments, pos); | 1843 factory()->NewCall(next_property, next_arguments, pos); |
| 1844 if (type == IteratorType::kAsync) { |
| 1845 next_call = RewriteAwaitExpression(next_call, pos); |
| 1846 } |
| 1837 Expression* result_proxy = factory()->NewVariableProxy(result); | 1847 Expression* result_proxy = factory()->NewVariableProxy(result); |
| 1838 Expression* left = | 1848 Expression* left = |
| 1839 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); | 1849 factory()->NewAssignment(Token::ASSIGN, result_proxy, next_call, pos); |
| 1840 | 1850 |
| 1841 // %_IsJSReceiver(...) | 1851 // %_IsJSReceiver(...) |
| 1842 ZoneList<Expression*>* is_spec_object_args = | 1852 ZoneList<Expression*>* is_spec_object_args = |
| 1843 new (zone()) ZoneList<Expression*>(1, zone()); | 1853 new (zone()) ZoneList<Expression*>(1, zone()); |
| 1844 is_spec_object_args->Add(left, zone()); | 1854 is_spec_object_args->Add(left, zone()); |
| 1845 Expression* is_spec_object_call = factory()->NewCallRuntime( | 1855 Expression* is_spec_object_call = factory()->NewCallRuntime( |
| 1846 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos); | 1856 Runtime::kInlineIsJSReceiver, is_spec_object_args, pos); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1861 | 1871 |
| 1862 Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt, | 1872 Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt, |
| 1863 Expression* each, | 1873 Expression* each, |
| 1864 Expression* subject, | 1874 Expression* subject, |
| 1865 Statement* body, | 1875 Statement* body, |
| 1866 int each_keyword_pos) { | 1876 int each_keyword_pos) { |
| 1867 ForOfStatement* for_of = stmt->AsForOfStatement(); | 1877 ForOfStatement* for_of = stmt->AsForOfStatement(); |
| 1868 if (for_of != NULL) { | 1878 if (for_of != NULL) { |
| 1869 const bool finalize = true; | 1879 const bool finalize = true; |
| 1870 return InitializeForOfStatement(for_of, each, subject, body, finalize, | 1880 return InitializeForOfStatement(for_of, each, subject, body, finalize, |
| 1871 each_keyword_pos); | 1881 IteratorType::kNormal, each_keyword_pos); |
| 1872 } else { | 1882 } else { |
| 1873 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { | 1883 if (each->IsArrayLiteral() || each->IsObjectLiteral()) { |
| 1874 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); | 1884 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); |
| 1875 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 1885 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
| 1876 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( | 1886 Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment( |
| 1877 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, | 1887 this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy, |
| 1878 kNoSourcePosition), | 1888 kNoSourcePosition), |
| 1879 scope()); | 1889 scope()); |
| 1880 auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition); | 1890 auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition); |
| 1881 block->statements()->Add( | 1891 block->statements()->Add( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2014 // INTERNAL variable that's invisible to the debugger | 2024 // INTERNAL variable that's invisible to the debugger |
| 2015 // but visible to everything else. | 2025 // but visible to everything else. |
| 2016 Declaration* tdz_decl = DeclareVariable(for_info.bound_names[i], LET, | 2026 Declaration* tdz_decl = DeclareVariable(for_info.bound_names[i], LET, |
| 2017 kNoSourcePosition, CHECK_OK); | 2027 kNoSourcePosition, CHECK_OK); |
| 2018 tdz_decl->proxy()->var()->set_initializer_position(position()); | 2028 tdz_decl->proxy()->var()->set_initializer_position(position()); |
| 2019 } | 2029 } |
| 2020 } | 2030 } |
| 2021 return init_block; | 2031 return init_block; |
| 2022 } | 2032 } |
| 2023 | 2033 |
| 2024 Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of, | 2034 Statement* Parser::InitializeForOfStatement( |
| 2025 Expression* each, | 2035 ForEachStatement* for_each, Expression* each, Expression* iterable, |
| 2026 Expression* iterable, | 2036 Statement* body, bool finalize, IteratorType type, int next_result_pos) { |
| 2027 Statement* body, bool finalize, | |
| 2028 int next_result_pos) { | |
| 2029 // Create the auxiliary expressions needed for iterating over the iterable, | 2037 // Create the auxiliary expressions needed for iterating over the iterable, |
| 2030 // and initialize the given ForOfStatement with them. | 2038 // and initialize the given ForOfStatement with them. |
| 2031 // If finalize is true, also instrument the loop with code that performs the | 2039 // If finalize is true, also instrument the loop with code that performs the |
| 2032 // proper ES6 iterator finalization. In that case, the result is not | 2040 // proper ES6 iterator finalization. In that case, the result is not |
| 2033 // immediately a ForOfStatement. | 2041 // immediately a ForOfStatement. |
| 2042 DCHECK(for_each->IsForOfStatement()); |
| 2043 ForOfStatement* for_of = for_each->AsForOfStatement(); |
| 2034 | 2044 |
| 2035 const int nopos = kNoSourcePosition; | 2045 const int nopos = kNoSourcePosition; |
| 2036 auto avfactory = ast_value_factory(); | 2046 auto avfactory = ast_value_factory(); |
| 2037 | 2047 |
| 2038 Variable* iterator = NewTemporary(avfactory->dot_iterator_string()); | 2048 Variable* iterator = NewTemporary(avfactory->dot_iterator_string()); |
| 2039 Variable* result = NewTemporary(avfactory->dot_result_string()); | 2049 Variable* result = NewTemporary(avfactory->dot_result_string()); |
| 2040 Variable* completion = NewTemporary(avfactory->empty_string()); | 2050 Variable* completion = NewTemporary(avfactory->empty_string()); |
| 2041 | 2051 |
| 2042 // iterator = GetIterator(iterable) | 2052 // iterator = GetIterator(iterable, type) |
| 2043 Expression* assign_iterator; | 2053 Expression* assign_iterator; |
| 2044 { | 2054 { |
| 2045 assign_iterator = factory()->NewAssignment( | 2055 assign_iterator = factory()->NewAssignment( |
| 2046 Token::ASSIGN, factory()->NewVariableProxy(iterator), | 2056 Token::ASSIGN, factory()->NewVariableProxy(iterator), |
| 2047 factory()->NewGetIterator(iterable, iterable->position()), | 2057 factory()->NewGetIterator(iterable, type, iterable->position()), |
| 2048 iterable->position()); | 2058 iterable->position()); |
| 2049 } | 2059 } |
| 2050 | 2060 |
| 2051 // !%_IsJSReceiver(result = iterator.next()) && | 2061 // [if (IteratorType == kNormal)] |
| 2052 // %ThrowIteratorResultNotAnObject(result) | 2062 // !%_IsJSReceiver(result = iterator.next()) && |
| 2063 // %ThrowIteratorResultNotAnObject(result) |
| 2064 // [else if (IteratorType == kAsync)] |
| 2065 // !%_IsJSReceiver(result = Await(iterator.next())) && |
| 2066 // %ThrowIteratorResultNotAnObject(result) |
| 2067 // [endif] |
| 2053 Expression* next_result; | 2068 Expression* next_result; |
| 2054 { | 2069 { |
| 2055 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); | 2070 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); |
| 2056 next_result = | 2071 next_result = |
| 2057 BuildIteratorNextResult(iterator_proxy, result, next_result_pos); | 2072 BuildIteratorNextResult(iterator_proxy, result, type, next_result_pos); |
| 2058 } | 2073 } |
| 2059 | 2074 |
| 2060 // result.done | 2075 // result.done |
| 2061 Expression* result_done; | 2076 Expression* result_done; |
| 2062 { | 2077 { |
| 2063 Expression* done_literal = factory()->NewStringLiteral( | 2078 Expression* done_literal = factory()->NewStringLiteral( |
| 2064 ast_value_factory()->done_string(), kNoSourcePosition); | 2079 ast_value_factory()->done_string(), kNoSourcePosition); |
| 2065 Expression* result_proxy = factory()->NewVariableProxy(result); | 2080 Expression* result_proxy = factory()->NewVariableProxy(result); |
| 2066 result_done = | 2081 result_done = |
| 2067 factory()->NewProperty(result_proxy, done_literal, kNoSourcePosition); | 2082 factory()->NewProperty(result_proxy, done_literal, kNoSourcePosition); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 // Statement* body (gets overwritten) | 2150 // Statement* body (gets overwritten) |
| 2136 if (finalize) { | 2151 if (finalize) { |
| 2137 Block* block = factory()->NewBlock(nullptr, 2, false, nopos); | 2152 Block* block = factory()->NewBlock(nullptr, 2, false, nopos); |
| 2138 block->statements()->Add(body, zone()); | 2153 block->statements()->Add(body, zone()); |
| 2139 block->statements()->Add(set_completion_normal, zone()); | 2154 block->statements()->Add(set_completion_normal, zone()); |
| 2140 body = block; | 2155 body = block; |
| 2141 } | 2156 } |
| 2142 | 2157 |
| 2143 for_of->Initialize(body, iterator, assign_iterator, next_result, result_done, | 2158 for_of->Initialize(body, iterator, assign_iterator, next_result, result_done, |
| 2144 assign_each); | 2159 assign_each); |
| 2145 return finalize ? FinalizeForOfStatement(for_of, completion, nopos) : for_of; | 2160 return finalize ? FinalizeForOfStatement(for_of, completion, type, nopos) |
| 2161 : for_of; |
| 2146 } | 2162 } |
| 2147 | 2163 |
| 2148 Statement* Parser::DesugarLexicalBindingsInForStatement( | 2164 Statement* Parser::DesugarLexicalBindingsInForStatement( |
| 2149 ForStatement* loop, Statement* init, Expression* cond, Statement* next, | 2165 ForStatement* loop, Statement* init, Expression* cond, Statement* next, |
| 2150 Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok) { | 2166 Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok) { |
| 2151 // ES6 13.7.4.8 specifies that on each loop iteration the let variables are | 2167 // ES6 13.7.4.8 specifies that on each loop iteration the let variables are |
| 2152 // copied into a new environment. Moreover, the "next" statement must be | 2168 // copied into a new environment. Moreover, the "next" statement must be |
| 2153 // evaluated not in the environment of the just completed iteration but in | 2169 // evaluated not in the environment of the just completed iteration but in |
| 2154 // that of the upcoming one. We achieve this with the following desugaring. | 2170 // that of the upcoming one. We achieve this with the following desugaring. |
| 2155 // Extra care is needed to preserve the completion value of the original loop. | 2171 // Extra care is needed to preserve the completion value of the original loop. |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2787 zone(), &scanner_, stack_limit_, ast_value_factory(), | 2803 zone(), &scanner_, stack_limit_, ast_value_factory(), |
| 2788 &pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_); | 2804 &pending_error_handler_, runtime_call_stats_, parsing_on_main_thread_); |
| 2789 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); | 2805 #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name()); |
| 2790 SET_ALLOW(natives); | 2806 SET_ALLOW(natives); |
| 2791 SET_ALLOW(harmony_do_expressions); | 2807 SET_ALLOW(harmony_do_expressions); |
| 2792 SET_ALLOW(harmony_function_sent); | 2808 SET_ALLOW(harmony_function_sent); |
| 2793 SET_ALLOW(harmony_trailing_commas); | 2809 SET_ALLOW(harmony_trailing_commas); |
| 2794 SET_ALLOW(harmony_class_fields); | 2810 SET_ALLOW(harmony_class_fields); |
| 2795 SET_ALLOW(harmony_object_rest_spread); | 2811 SET_ALLOW(harmony_object_rest_spread); |
| 2796 SET_ALLOW(harmony_dynamic_import); | 2812 SET_ALLOW(harmony_dynamic_import); |
| 2813 SET_ALLOW(harmony_async_iteration); |
| 2797 #undef SET_ALLOW | 2814 #undef SET_ALLOW |
| 2798 } | 2815 } |
| 2799 // Aborting inner function preparsing would leave scopes in an inconsistent | 2816 // Aborting inner function preparsing would leave scopes in an inconsistent |
| 2800 // state; we don't parse inner functions in the abortable mode anyway. | 2817 // state; we don't parse inner functions in the abortable mode anyway. |
| 2801 DCHECK(!is_inner_function || !may_abort); | 2818 DCHECK(!is_inner_function || !may_abort); |
| 2802 | 2819 |
| 2803 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( | 2820 PreParser::PreParseResult result = reusable_preparser_->PreParseFunction( |
| 2804 kind, function_scope, parsing_module_, is_inner_function, may_abort, | 2821 kind, function_scope, parsing_module_, is_inner_function, may_abort, |
| 2805 use_counts_); | 2822 use_counts_); |
| 2806 | 2823 |
| (...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4048 factory()->NewCallRuntime(Runtime::kAppendElement, | 4065 factory()->NewCallRuntime(Runtime::kAppendElement, |
| 4049 append_element_args, kNoSourcePosition), | 4066 append_element_args, kNoSourcePosition), |
| 4050 kNoSourcePosition); | 4067 kNoSourcePosition); |
| 4051 } | 4068 } |
| 4052 // for (each of spread) %AppendElement($R, each) | 4069 // for (each of spread) %AppendElement($R, each) |
| 4053 ForEachStatement* loop = factory()->NewForEachStatement( | 4070 ForEachStatement* loop = factory()->NewForEachStatement( |
| 4054 ForEachStatement::ITERATE, nullptr, kNoSourcePosition); | 4071 ForEachStatement::ITERATE, nullptr, kNoSourcePosition); |
| 4055 const bool finalize = false; | 4072 const bool finalize = false; |
| 4056 InitializeForOfStatement(loop->AsForOfStatement(), | 4073 InitializeForOfStatement(loop->AsForOfStatement(), |
| 4057 factory()->NewVariableProxy(each), subject, | 4074 factory()->NewVariableProxy(each), subject, |
| 4058 append_body, finalize); | 4075 append_body, finalize, IteratorType::kNormal); |
| 4059 do_block->statements()->Add(loop, zone()); | 4076 do_block->statements()->Add(loop, zone()); |
| 4060 } | 4077 } |
| 4061 } | 4078 } |
| 4062 // Now, rewind the original array literal to truncate everything from the | 4079 // Now, rewind the original array literal to truncate everything from the |
| 4063 // first spread (included) until the end. This fixes $R's initialization. | 4080 // first spread (included) until the end. This fixes $R's initialization. |
| 4064 lit->RewindSpreads(); | 4081 lit->RewindSpreads(); |
| 4065 return factory()->NewDoExpression(do_block, result, lit->position()); | 4082 return factory()->NewDoExpression(do_block, result, lit->position()); |
| 4066 } | 4083 } |
| 4067 | 4084 |
| 4068 void Parser::QueueDestructuringAssignmentForRewriting(Expression* expr) { | 4085 void Parser::QueueDestructuringAssignmentForRewriting(Expression* expr) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4240 Expression* assignment = | 4257 Expression* assignment = |
| 4241 factory()->NewAssignment(Token::ASSIGN, output_proxy, | 4258 factory()->NewAssignment(Token::ASSIGN, output_proxy, |
| 4242 factory()->NewUndefinedLiteral(nopos), nopos); | 4259 factory()->NewUndefinedLiteral(nopos), nopos); |
| 4243 initialize_output = factory()->NewExpressionStatement(assignment, nopos); | 4260 initialize_output = factory()->NewExpressionStatement(assignment, nopos); |
| 4244 } | 4261 } |
| 4245 | 4262 |
| 4246 // let iterator = GetIterator(iterable); | 4263 // let iterator = GetIterator(iterable); |
| 4247 Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string()); | 4264 Variable* var_iterator = NewTemporary(ast_value_factory()->empty_string()); |
| 4248 Statement* get_iterator; | 4265 Statement* get_iterator; |
| 4249 { | 4266 { |
| 4250 Expression* iterator = factory()->NewGetIterator(iterable, nopos); | 4267 Expression* iterator = |
| 4268 factory()->NewGetIterator(iterable, IteratorType::kNormal, nopos); |
| 4251 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); | 4269 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); |
| 4252 Expression* assignment = factory()->NewAssignment( | 4270 Expression* assignment = factory()->NewAssignment( |
| 4253 Token::ASSIGN, iterator_proxy, iterator, nopos); | 4271 Token::ASSIGN, iterator_proxy, iterator, nopos); |
| 4254 get_iterator = factory()->NewExpressionStatement(assignment, nopos); | 4272 get_iterator = factory()->NewExpressionStatement(assignment, nopos); |
| 4255 } | 4273 } |
| 4256 | 4274 |
| 4257 // output = iterator.next(input); | 4275 // output = iterator.next(input); |
| 4258 Statement* call_next; | 4276 Statement* call_next; |
| 4259 { | 4277 { |
| 4260 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); | 4278 Expression* iterator_proxy = factory()->NewVariableProxy(var_iterator); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4322 Token::EQ, factory()->NewVariableProxy(var_throw), | 4340 Token::EQ, factory()->NewVariableProxy(var_throw), |
| 4323 factory()->NewNullLiteral(nopos), nopos); | 4341 factory()->NewNullLiteral(nopos), nopos); |
| 4324 Expression* call = | 4342 Expression* call = |
| 4325 NewThrowTypeError(MessageTemplate::kThrowMethodMissing, | 4343 NewThrowTypeError(MessageTemplate::kThrowMethodMissing, |
| 4326 ast_value_factory()->empty_string(), nopos); | 4344 ast_value_factory()->empty_string(), nopos); |
| 4327 Statement* throw_call = factory()->NewExpressionStatement(call, nopos); | 4345 Statement* throw_call = factory()->NewExpressionStatement(call, nopos); |
| 4328 | 4346 |
| 4329 Block* then = factory()->NewBlock(nullptr, 4 + 1, false, nopos); | 4347 Block* then = factory()->NewBlock(nullptr, 4 + 1, false, nopos); |
| 4330 BuildIteratorCloseForCompletion( | 4348 BuildIteratorCloseForCompletion( |
| 4331 scope(), then->statements(), var_iterator, | 4349 scope(), then->statements(), var_iterator, |
| 4332 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos)); | 4350 factory()->NewSmiLiteral(Parser::kNormalCompletion, nopos), |
| 4351 IteratorType::kNormal); |
| 4333 then->statements()->Add(throw_call, zone()); | 4352 then->statements()->Add(throw_call, zone()); |
| 4334 check_throw = factory()->NewIfStatement( | 4353 check_throw = factory()->NewIfStatement( |
| 4335 condition, then, factory()->NewEmptyStatement(nopos), nopos); | 4354 condition, then, factory()->NewEmptyStatement(nopos), nopos); |
| 4336 } | 4355 } |
| 4337 | 4356 |
| 4338 // output = %_Call(iteratorThrow, iterator, input); | 4357 // output = %_Call(iteratorThrow, iterator, input); |
| 4339 Statement* call_throw; | 4358 Statement* call_throw; |
| 4340 { | 4359 { |
| 4341 auto args = new (zone()) ZoneList<Expression*>(3, zone()); | 4360 auto args = new (zone()) ZoneList<Expression*>(3, zone()); |
| 4342 args->Add(factory()->NewVariableProxy(var_throw), zone()); | 4361 args->Add(factory()->NewVariableProxy(var_throw), zone()); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4689 } | 4708 } |
| 4690 | 4709 |
| 4691 statements->Add(get_return, zone()); | 4710 statements->Add(get_return, zone()); |
| 4692 statements->Add(check_return, zone()); | 4711 statements->Add(check_return, zone()); |
| 4693 statements->Add(call_return, zone()); | 4712 statements->Add(call_return, zone()); |
| 4694 statements->Add(validate_output, zone()); | 4713 statements->Add(validate_output, zone()); |
| 4695 } | 4714 } |
| 4696 | 4715 |
| 4697 void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion, | 4716 void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion, |
| 4698 Expression* condition, Variable* iter, | 4717 Expression* condition, Variable* iter, |
| 4699 Block* iterator_use, Block* target) { | 4718 Block* iterator_use, Block* target, |
| 4719 IteratorType type) { |
| 4700 // | 4720 // |
| 4701 // This function adds two statements to [target], corresponding to the | 4721 // This function adds two statements to [target], corresponding to the |
| 4702 // following code: | 4722 // following code: |
| 4703 // | 4723 // |
| 4704 // completion = kNormalCompletion; | 4724 // completion = kNormalCompletion; |
| 4705 // try { | 4725 // try { |
| 4706 // try { | 4726 // try { |
| 4707 // iterator_use | 4727 // iterator_use |
| 4708 // } catch(e) { | 4728 // } catch(e) { |
| 4709 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 4729 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4745 condition, statement, factory()->NewEmptyStatement(nopos), nopos); | 4765 condition, statement, factory()->NewEmptyStatement(nopos), nopos); |
| 4746 } | 4766 } |
| 4747 | 4767 |
| 4748 // if (condition) { | 4768 // if (condition) { |
| 4749 // #BuildIteratorCloseForCompletion(iter, completion) | 4769 // #BuildIteratorCloseForCompletion(iter, completion) |
| 4750 // } | 4770 // } |
| 4751 Block* maybe_close; | 4771 Block* maybe_close; |
| 4752 { | 4772 { |
| 4753 Block* block = factory()->NewBlock(nullptr, 2, true, nopos); | 4773 Block* block = factory()->NewBlock(nullptr, 2, true, nopos); |
| 4754 Expression* proxy = factory()->NewVariableProxy(completion); | 4774 Expression* proxy = factory()->NewVariableProxy(completion); |
| 4755 BuildIteratorCloseForCompletion(use_scope, block->statements(), iter, | 4775 BuildIteratorCloseForCompletion(use_scope, block->statements(), iter, proxy, |
| 4756 proxy); | 4776 type); |
| 4757 DCHECK(block->statements()->length() == 2); | 4777 DCHECK(block->statements()->length() == 2); |
| 4758 | 4778 |
| 4759 maybe_close = factory()->NewBlock(nullptr, 1, true, nopos); | 4779 maybe_close = factory()->NewBlock(nullptr, 1, true, nopos); |
| 4760 maybe_close->statements()->Add( | 4780 maybe_close->statements()->Add( |
| 4761 factory()->NewIfStatement(condition, block, | 4781 factory()->NewIfStatement(condition, block, |
| 4762 factory()->NewEmptyStatement(nopos), nopos), | 4782 factory()->NewEmptyStatement(nopos), nopos), |
| 4763 zone()); | 4783 zone()); |
| 4764 } | 4784 } |
| 4765 | 4785 |
| 4766 // try { #try_block } | 4786 // try { #try_block } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4805 factory()->NewTryFinallyStatement(try_block, maybe_close, nopos); | 4825 factory()->NewTryFinallyStatement(try_block, maybe_close, nopos); |
| 4806 } | 4826 } |
| 4807 | 4827 |
| 4808 target->statements()->Add(initialize_completion, zone()); | 4828 target->statements()->Add(initialize_completion, zone()); |
| 4809 target->statements()->Add(try_finally, zone()); | 4829 target->statements()->Add(try_finally, zone()); |
| 4810 } | 4830 } |
| 4811 | 4831 |
| 4812 void Parser::BuildIteratorCloseForCompletion(Scope* scope, | 4832 void Parser::BuildIteratorCloseForCompletion(Scope* scope, |
| 4813 ZoneList<Statement*>* statements, | 4833 ZoneList<Statement*>* statements, |
| 4814 Variable* iterator, | 4834 Variable* iterator, |
| 4815 Expression* completion) { | 4835 Expression* completion, |
| 4836 IteratorType type) { |
| 4816 // | 4837 // |
| 4817 // This function adds two statements to [statements], corresponding to the | 4838 // This function adds two statements to [statements], corresponding to the |
| 4818 // following code: | 4839 // following code: |
| 4819 // | 4840 // |
| 4820 // let iteratorReturn = iterator.return; | 4841 // let iteratorReturn = iterator.return; |
| 4821 // if (!IS_NULL_OR_UNDEFINED(iteratorReturn)) { | 4842 // if (!IS_NULL_OR_UNDEFINED(iteratorReturn)) { |
| 4822 // if (completion === kThrowCompletion) { | 4843 // if (completion === kThrowCompletion) { |
| 4823 // if (!IS_CALLABLE(iteratorReturn)) { | 4844 // if (!IS_CALLABLE(iteratorReturn)) { |
| 4824 // throw MakeTypeError(kReturnMethodNotCallable); | 4845 // throw MakeTypeError(kReturnMethodNotCallable); |
| 4825 // } | 4846 // } |
| 4826 // try { %_Call(iteratorReturn, iterator) } catch (_) { } | 4847 // [if (IteratorType == kAsync)] |
| 4848 // try { Await(%_Call(iteratorReturn, iterator) } catch (_) { } |
| 4849 // [else] |
| 4850 // try { %_Call(iteratorReturn, iterator) } catch (_) { } |
| 4851 // [endif] |
| 4827 // } else { | 4852 // } else { |
| 4828 // let output = %_Call(iteratorReturn, iterator); | 4853 // [if (IteratorType == kAsync)] |
| 4854 // let output = Await(%_Call(iteratorReturn, iterator)); |
| 4855 // [else] |
| 4856 // let output = %_Call(iteratorReturn, iterator); |
| 4857 // [endif] |
| 4829 // if (!IS_RECEIVER(output)) { | 4858 // if (!IS_RECEIVER(output)) { |
| 4830 // %ThrowIterResultNotAnObject(output); | 4859 // %ThrowIterResultNotAnObject(output); |
| 4831 // } | 4860 // } |
| 4832 // } | 4861 // } |
| 4833 // } | 4862 // } |
| 4834 // | 4863 // |
| 4835 | 4864 |
| 4836 const int nopos = kNoSourcePosition; | 4865 const int nopos = kNoSourcePosition; |
| 4837 // let iteratorReturn = iterator.return; | 4866 // let iteratorReturn = iterator.return; |
| 4838 Variable* var_return = NewTemporary(ast_value_factory()->empty_string()); | 4867 Variable* var_return = NewTemporary(ast_value_factory()->empty_string()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4863 // try { %_Call(iteratorReturn, iterator) } catch (_) { } | 4892 // try { %_Call(iteratorReturn, iterator) } catch (_) { } |
| 4864 Statement* try_call_return; | 4893 Statement* try_call_return; |
| 4865 { | 4894 { |
| 4866 auto args = new (zone()) ZoneList<Expression*>(2, zone()); | 4895 auto args = new (zone()) ZoneList<Expression*>(2, zone()); |
| 4867 args->Add(factory()->NewVariableProxy(var_return), zone()); | 4896 args->Add(factory()->NewVariableProxy(var_return), zone()); |
| 4868 args->Add(factory()->NewVariableProxy(iterator), zone()); | 4897 args->Add(factory()->NewVariableProxy(iterator), zone()); |
| 4869 | 4898 |
| 4870 Expression* call = | 4899 Expression* call = |
| 4871 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos); | 4900 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos); |
| 4872 | 4901 |
| 4902 if (type == IteratorType::kAsync) { |
| 4903 call = RewriteAwaitExpression(call, nopos); |
| 4904 } |
| 4905 |
| 4873 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); | 4906 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); |
| 4874 try_block->statements()->Add(factory()->NewExpressionStatement(call, nopos), | 4907 try_block->statements()->Add(factory()->NewExpressionStatement(call, nopos), |
| 4875 zone()); | 4908 zone()); |
| 4876 | 4909 |
| 4877 Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos); | 4910 Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos); |
| 4878 | 4911 |
| 4879 Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); | 4912 Scope* catch_scope = NewScopeWithParent(scope, CATCH_SCOPE); |
| 4880 Variable* catch_variable = | 4913 Variable* catch_variable = |
| 4881 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); | 4914 catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR); |
| 4882 catch_scope->set_is_hidden(); | 4915 catch_scope->set_is_hidden(); |
| 4883 | 4916 |
| 4884 try_call_return = factory()->NewTryCatchStatement( | 4917 try_call_return = factory()->NewTryCatchStatement( |
| 4885 try_block, catch_scope, catch_variable, catch_block, nopos); | 4918 try_block, catch_scope, catch_variable, catch_block, nopos); |
| 4886 } | 4919 } |
| 4887 | 4920 |
| 4888 // let output = %_Call(iteratorReturn, iterator); | 4921 // let output = %_Call(iteratorReturn, iterator); |
| 4889 // if (!IS_RECEIVER(output)) { | 4922 // if (!IS_RECEIVER(output)) { |
| 4890 // %ThrowIteratorResultNotAnObject(output); | 4923 // %ThrowIteratorResultNotAnObject(output); |
| 4891 // } | 4924 // } |
| 4892 Block* validate_return; | 4925 Block* validate_return; |
| 4893 { | 4926 { |
| 4894 Variable* var_output = NewTemporary(ast_value_factory()->empty_string()); | 4927 Variable* var_output = NewTemporary(ast_value_factory()->empty_string()); |
| 4895 Statement* call_return; | 4928 Statement* call_return; |
| 4896 { | 4929 { |
| 4897 auto args = new (zone()) ZoneList<Expression*>(2, zone()); | 4930 auto args = new (zone()) ZoneList<Expression*>(2, zone()); |
| 4898 args->Add(factory()->NewVariableProxy(var_return), zone()); | 4931 args->Add(factory()->NewVariableProxy(var_return), zone()); |
| 4899 args->Add(factory()->NewVariableProxy(iterator), zone()); | 4932 args->Add(factory()->NewVariableProxy(iterator), zone()); |
| 4900 Expression* call = | 4933 Expression* call = |
| 4901 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos); | 4934 factory()->NewCallRuntime(Runtime::kInlineCall, args, nopos); |
| 4935 if (type == IteratorType::kAsync) { |
| 4936 call = RewriteAwaitExpression(call, nopos); |
| 4937 } |
| 4902 | 4938 |
| 4903 Expression* output_proxy = factory()->NewVariableProxy(var_output); | 4939 Expression* output_proxy = factory()->NewVariableProxy(var_output); |
| 4904 Expression* assignment = | 4940 Expression* assignment = |
| 4905 factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos); | 4941 factory()->NewAssignment(Token::ASSIGN, output_proxy, call, nopos); |
| 4906 call_return = factory()->NewExpressionStatement(assignment, nopos); | 4942 call_return = factory()->NewExpressionStatement(assignment, nopos); |
| 4907 } | 4943 } |
| 4908 | 4944 |
| 4909 Expression* is_receiver_call; | 4945 Expression* is_receiver_call; |
| 4910 { | 4946 { |
| 4911 auto args = new (zone()) ZoneList<Expression*>(1, zone()); | 4947 auto args = new (zone()) ZoneList<Expression*>(1, zone()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4962 maybe_call_return = factory()->NewIfStatement( | 4998 maybe_call_return = factory()->NewIfStatement( |
| 4963 condition, factory()->NewEmptyStatement(nopos), call_return_carefully, | 4999 condition, factory()->NewEmptyStatement(nopos), call_return_carefully, |
| 4964 nopos); | 5000 nopos); |
| 4965 } | 5001 } |
| 4966 | 5002 |
| 4967 statements->Add(get_return, zone()); | 5003 statements->Add(get_return, zone()); |
| 4968 statements->Add(maybe_call_return, zone()); | 5004 statements->Add(maybe_call_return, zone()); |
| 4969 } | 5005 } |
| 4970 | 5006 |
| 4971 Statement* Parser::FinalizeForOfStatement(ForOfStatement* loop, | 5007 Statement* Parser::FinalizeForOfStatement(ForOfStatement* loop, |
| 4972 Variable* var_completion, int pos) { | 5008 Variable* var_completion, |
| 5009 IteratorType type, int pos) { |
| 4973 // | 5010 // |
| 4974 // This function replaces the loop with the following wrapping: | 5011 // This function replaces the loop with the following wrapping: |
| 4975 // | 5012 // |
| 4976 // completion = kNormalCompletion; | 5013 // completion = kNormalCompletion; |
| 4977 // try { | 5014 // try { |
| 4978 // try { | 5015 // try { |
| 4979 // #loop; | 5016 // #loop; |
| 4980 // } catch(e) { | 5017 // } catch(e) { |
| 4981 // if (completion === kAbruptCompletion) completion = kThrowCompletion; | 5018 // if (completion === kAbruptCompletion) completion = kThrowCompletion; |
| 4982 // %ReThrow(e); | 5019 // %ReThrow(e); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5006 { | 5043 { |
| 5007 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); | 5044 Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos); |
| 5008 try_block->statements()->Add(loop, zone()); | 5045 try_block->statements()->Add(loop, zone()); |
| 5009 | 5046 |
| 5010 // The scope in which the parser creates this loop. | 5047 // The scope in which the parser creates this loop. |
| 5011 Scope* loop_scope = scope()->outer_scope(); | 5048 Scope* loop_scope = scope()->outer_scope(); |
| 5012 DCHECK_EQ(loop_scope->scope_type(), BLOCK_SCOPE); | 5049 DCHECK_EQ(loop_scope->scope_type(), BLOCK_SCOPE); |
| 5013 DCHECK_EQ(scope()->scope_type(), BLOCK_SCOPE); | 5050 DCHECK_EQ(scope()->scope_type(), BLOCK_SCOPE); |
| 5014 | 5051 |
| 5015 FinalizeIteratorUse(loop_scope, var_completion, closing_condition, | 5052 FinalizeIteratorUse(loop_scope, var_completion, closing_condition, |
| 5016 loop->iterator(), try_block, final_loop); | 5053 loop->iterator(), try_block, final_loop, type); |
| 5017 } | 5054 } |
| 5018 | 5055 |
| 5019 return final_loop; | 5056 return final_loop; |
| 5020 } | 5057 } |
| 5021 | 5058 |
| 5022 #undef CHECK_OK | 5059 #undef CHECK_OK |
| 5023 #undef CHECK_OK_VOID | 5060 #undef CHECK_OK_VOID |
| 5024 #undef CHECK_FAILED | 5061 #undef CHECK_FAILED |
| 5025 | 5062 |
| 5026 } // namespace internal | 5063 } // namespace internal |
| 5027 } // namespace v8 | 5064 } // namespace v8 |
| OLD | NEW |