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/parser.h" | 5 #include "src/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/ast-literal-reindexer.h" | 9 #include "src/ast-literal-reindexer.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 3617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3628 bool is_let_identifier_expression = false; | 3628 bool is_let_identifier_expression = false; |
3629 DeclarationParsingResult parsing_result; | 3629 DeclarationParsingResult parsing_result; |
3630 if (peek() != Token::SEMICOLON) { | 3630 if (peek() != Token::SEMICOLON) { |
3631 if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) || | 3631 if (peek() == Token::VAR || (peek() == Token::CONST && allow_const()) || |
3632 (peek() == Token::LET && IsNextLetKeyword())) { | 3632 (peek() == Token::LET && IsNextLetKeyword())) { |
3633 ParseVariableDeclarations(kForStatement, &parsing_result, CHECK_OK); | 3633 ParseVariableDeclarations(kForStatement, &parsing_result, CHECK_OK); |
3634 is_const = parsing_result.descriptor.mode == CONST; | 3634 is_const = parsing_result.descriptor.mode == CONST; |
3635 | 3635 |
3636 int num_decl = parsing_result.declarations.length(); | 3636 int num_decl = parsing_result.declarations.length(); |
3637 bool accept_IN = num_decl >= 1; | 3637 bool accept_IN = num_decl >= 1; |
3638 bool accept_OF = true; | |
3639 ForEachStatement::VisitMode mode; | 3638 ForEachStatement::VisitMode mode; |
3640 int each_beg_pos = scanner()->location().beg_pos; | 3639 int each_beg_pos = scanner()->location().beg_pos; |
3641 int each_end_pos = scanner()->location().end_pos; | 3640 int each_end_pos = scanner()->location().end_pos; |
3642 | 3641 |
3643 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { | 3642 if (accept_IN && CheckInOrOf(&mode, ok)) { |
3644 if (!*ok) return nullptr; | 3643 if (!*ok) return nullptr; |
3645 if (num_decl != 1) { | 3644 if (num_decl != 1) { |
3646 const char* loop_type = | 3645 const char* loop_type = |
3647 mode == ForEachStatement::ITERATE ? "for-of" : "for-in"; | 3646 mode == ForEachStatement::ITERATE ? "for-of" : "for-in"; |
3648 ParserTraits::ReportMessageAt( | 3647 ParserTraits::ReportMessageAt( |
3649 parsing_result.bindings_loc, | 3648 parsing_result.bindings_loc, |
3650 MessageTemplate::kForInOfLoopMultiBindings, loop_type); | 3649 MessageTemplate::kForInOfLoopMultiBindings, loop_type); |
3651 *ok = false; | 3650 *ok = false; |
3652 return nullptr; | 3651 return nullptr; |
3653 } | 3652 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3791 IsLexicalVariableMode(parsing_result.descriptor.mode) | 3790 IsLexicalVariableMode(parsing_result.descriptor.mode) |
3792 ? &lexical_bindings | 3791 ? &lexical_bindings |
3793 : nullptr, | 3792 : nullptr, |
3794 CHECK_OK); | 3793 CHECK_OK); |
3795 } | 3794 } |
3796 } else { | 3795 } else { |
3797 int lhs_beg_pos = peek_position(); | 3796 int lhs_beg_pos = peek_position(); |
3798 Expression* expression = ParseExpression(false, CHECK_OK); | 3797 Expression* expression = ParseExpression(false, CHECK_OK); |
3799 int lhs_end_pos = scanner()->location().end_pos; | 3798 int lhs_end_pos = scanner()->location().end_pos; |
3800 ForEachStatement::VisitMode mode; | 3799 ForEachStatement::VisitMode mode; |
3801 bool accept_OF = expression->IsVariableProxy(); | |
3802 is_let_identifier_expression = | 3800 is_let_identifier_expression = |
3803 expression->IsVariableProxy() && | 3801 expression->IsVariableProxy() && |
3804 expression->AsVariableProxy()->raw_name() == | 3802 expression->AsVariableProxy()->raw_name() == |
3805 ast_value_factory()->let_string(); | 3803 ast_value_factory()->let_string(); |
3806 | 3804 |
3807 if (CheckInOrOf(accept_OF, &mode, ok)) { | 3805 if (CheckInOrOf(&mode, ok)) { |
3808 if (!*ok) return nullptr; | 3806 if (!*ok) return nullptr; |
3809 expression = this->CheckAndRewriteReferenceExpression( | 3807 expression = this->CheckAndRewriteReferenceExpression( |
3810 expression, lhs_beg_pos, lhs_end_pos, | 3808 expression, lhs_beg_pos, lhs_end_pos, |
3811 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); | 3809 MessageTemplate::kInvalidLhsInFor, kSyntaxError, CHECK_OK); |
3812 | 3810 |
3813 ForEachStatement* loop = | 3811 ForEachStatement* loop = |
3814 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3812 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3815 Target target(&this->target_stack_, loop); | 3813 Target target(&this->target_stack_, loop); |
3816 | 3814 |
3817 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3815 Expression* enumerable = ParseExpression(true, CHECK_OK); |
(...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6390 | 6388 |
6391 Expression* Parser::SpreadCallNew(Expression* function, | 6389 Expression* Parser::SpreadCallNew(Expression* function, |
6392 ZoneList<v8::internal::Expression*>* args, | 6390 ZoneList<v8::internal::Expression*>* args, |
6393 int pos) { | 6391 int pos) { |
6394 args->InsertAt(0, function, zone()); | 6392 args->InsertAt(0, function, zone()); |
6395 | 6393 |
6396 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); | 6394 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, pos); |
6397 } | 6395 } |
6398 } // namespace internal | 6396 } // namespace internal |
6399 } // namespace v8 | 6397 } // namespace v8 |
OLD | NEW |