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/v8.h" | 5 #include "src/v8.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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 3466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3477 // Parsed for-in loop w/ variable/const declaration. | 3477 // Parsed for-in loop w/ variable/const declaration. |
3478 return result; | 3478 return result; |
3479 } else { | 3479 } else { |
3480 init = variable_statement; | 3480 init = variable_statement; |
3481 } | 3481 } |
3482 } else if ((peek() == Token::LET || peek() == Token::CONST) && | 3482 } else if ((peek() == Token::LET || peek() == Token::CONST) && |
3483 is_strict(language_mode())) { | 3483 is_strict(language_mode())) { |
3484 is_const = peek() == Token::CONST; | 3484 is_const = peek() == Token::CONST; |
3485 ParseVariableDeclarations(kForStatement, &parsing_result, CHECK_OK); | 3485 ParseVariableDeclarations(kForStatement, &parsing_result, CHECK_OK); |
3486 DCHECK(parsing_result.descriptor.pos != RelocInfo::kNoPosition); | 3486 DCHECK(parsing_result.descriptor.pos != RelocInfo::kNoPosition); |
3487 Block* variable_statement = | |
3488 parsing_result.BuildInitializationBlock(&lexical_bindings, CHECK_OK); | |
3489 | 3487 |
3490 int num_decl = parsing_result.declarations.length(); | 3488 int num_decl = parsing_result.declarations.length(); |
3491 bool accept_IN = num_decl >= 1; | 3489 bool accept_IN = num_decl >= 1; |
3492 bool accept_OF = true; | 3490 bool accept_OF = true; |
3493 ForEachStatement::VisitMode mode; | 3491 ForEachStatement::VisitMode mode; |
3494 int each_beg_pos = scanner()->location().beg_pos; | 3492 int each_beg_pos = scanner()->location().beg_pos; |
3495 int each_end_pos = scanner()->location().end_pos; | 3493 int each_end_pos = scanner()->location().end_pos; |
3496 | 3494 |
3497 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { | 3495 if (accept_IN && CheckInOrOf(accept_OF, &mode, ok)) { |
3498 if (!*ok) return nullptr; | 3496 if (!*ok) return nullptr; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3539 ForEachStatement* loop = | 3537 ForEachStatement* loop = |
3540 factory()->NewForEachStatement(mode, labels, stmt_pos); | 3538 factory()->NewForEachStatement(mode, labels, stmt_pos); |
3541 Target target(&this->target_stack_, loop); | 3539 Target target(&this->target_stack_, loop); |
3542 | 3540 |
3543 // The expression does not see the loop variable. | 3541 // The expression does not see the loop variable. |
3544 scope_ = saved_scope; | 3542 scope_ = saved_scope; |
3545 Expression* enumerable = ParseExpression(true, CHECK_OK); | 3543 Expression* enumerable = ParseExpression(true, CHECK_OK); |
3546 scope_ = for_scope; | 3544 scope_ = for_scope; |
3547 Expect(Token::RPAREN, CHECK_OK); | 3545 Expect(Token::RPAREN, CHECK_OK); |
3548 | 3546 |
3549 VariableProxy* each = | |
3550 scope_->NewUnresolved(factory(), parsing_result.SingleName(), | |
3551 Variable::NORMAL, each_end_pos); | |
3552 Statement* body = ParseSubStatement(NULL, CHECK_OK); | 3547 Statement* body = ParseSubStatement(NULL, CHECK_OK); |
3553 Block* body_block = | 3548 Block* body_block = |
3554 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); | 3549 factory()->NewBlock(NULL, 3, false, RelocInfo::kNoPosition); |
3555 Token::Value init_op = is_const ? Token::INIT_CONST : Token::ASSIGN; | 3550 |
3556 Assignment* assignment = factory()->NewAssignment( | 3551 auto each_initialization_block = factory()->NewBlock( |
3557 init_op, each, temp_proxy, RelocInfo::kNoPosition); | 3552 nullptr, 1, true, parsing_result.descriptor.pos); |
3558 Statement* assignment_statement = factory()->NewExpressionStatement( | 3553 { |
3559 assignment, RelocInfo::kNoPosition); | 3554 DCHECK(parsing_result.declarations.length() == 1); |
3560 body_block->AddStatement(variable_statement, zone()); | 3555 DeclarationParsingResult::Declaration decl = |
3561 body_block->AddStatement(assignment_statement, zone()); | 3556 parsing_result.declarations[0]; |
| 3557 decl.initializer = temp_proxy; |
| 3558 PatternRewriter::DeclareAndInitializeVariables( |
| 3559 each_initialization_block, &parsing_result.descriptor, &decl, |
| 3560 &lexical_bindings, CHECK_OK); |
| 3561 } |
| 3562 |
| 3563 body_block->AddStatement(each_initialization_block, zone()); |
3562 body_block->AddStatement(body, zone()); | 3564 body_block->AddStatement(body, zone()); |
3563 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block); | 3565 InitializeForEachStatement(loop, temp_proxy, enumerable, body_block); |
3564 scope_ = saved_scope; | 3566 scope_ = saved_scope; |
3565 for_scope->set_end_position(scanner()->location().end_pos); | 3567 for_scope->set_end_position(scanner()->location().end_pos); |
3566 for_scope = for_scope->FinalizeBlockScope(); | 3568 for_scope = for_scope->FinalizeBlockScope(); |
3567 body_block->set_scope(for_scope); | 3569 body_block->set_scope(for_scope); |
3568 // Parsed for-in loop w/ let declaration. | 3570 // Parsed for-in loop w/ let declaration. |
3569 return loop; | 3571 return loop; |
3570 | |
3571 } else { | 3572 } else { |
3572 init = variable_statement; | 3573 init = parsing_result.BuildInitializationBlock(&lexical_bindings, |
| 3574 CHECK_OK); |
3573 } | 3575 } |
3574 } else { | 3576 } else { |
3575 Scanner::Location lhs_location = scanner()->peek_location(); | 3577 Scanner::Location lhs_location = scanner()->peek_location(); |
3576 Expression* expression = ParseExpression(false, CHECK_OK); | 3578 Expression* expression = ParseExpression(false, CHECK_OK); |
3577 ForEachStatement::VisitMode mode; | 3579 ForEachStatement::VisitMode mode; |
3578 bool accept_OF = expression->IsVariableProxy(); | 3580 bool accept_OF = expression->IsVariableProxy(); |
3579 is_let_identifier_expression = | 3581 is_let_identifier_expression = |
3580 expression->IsVariableProxy() && | 3582 expression->IsVariableProxy() && |
3581 expression->AsVariableProxy()->raw_name() == | 3583 expression->AsVariableProxy()->raw_name() == |
3582 ast_value_factory()->let_string(); | 3584 ast_value_factory()->let_string(); |
(...skipping 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5806 | 5808 |
5807 Expression* Parser::SpreadCallNew(Expression* function, | 5809 Expression* Parser::SpreadCallNew(Expression* function, |
5808 ZoneList<v8::internal::Expression*>* args, | 5810 ZoneList<v8::internal::Expression*>* args, |
5809 int pos) { | 5811 int pos) { |
5810 args->InsertAt(0, function, zone()); | 5812 args->InsertAt(0, function, zone()); |
5811 | 5813 |
5812 return factory()->NewCallRuntime( | 5814 return factory()->NewCallRuntime( |
5813 ast_value_factory()->reflect_construct_string(), NULL, args, pos); | 5815 ast_value_factory()->reflect_construct_string(), NULL, args, pos); |
5814 } | 5816 } |
5815 } } // namespace v8::internal | 5817 } } // namespace v8::internal |
OLD | NEW |