| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/ast/ast.h" | 5 #include "src/ast/ast.h" |
| 6 #include "src/messages.h" | 6 #include "src/messages.h" |
| 7 #include "src/parsing/parameter-initializer-rewriter.h" | 7 #include "src/parsing/parameter-initializer-rewriter.h" |
| 8 #include "src/parsing/parser.h" | 8 #include "src/parsing/parser.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 auto v = CreateTempVar(); | 418 auto v = CreateTempVar(); |
| 419 auto completion = CreateTempVar(); | 419 auto completion = CreateTempVar(); |
| 420 auto nopos = RelocInfo::kNoPosition; | 420 auto nopos = RelocInfo::kNoPosition; |
| 421 | 421 |
| 422 // For the purpose of iterator finalization, we temporarily set block_ to a | 422 // For the purpose of iterator finalization, we temporarily set block_ to a |
| 423 // new block. In the main body of this function, we write to block_ (both | 423 // new block. In the main body of this function, we write to block_ (both |
| 424 // explicitly and implicitly via recursion). At the end of the function, we | 424 // explicitly and implicitly via recursion). At the end of the function, we |
| 425 // wrap this new block in a try-finally statement, restore block_ to its | 425 // wrap this new block in a try-finally statement, restore block_ to its |
| 426 // original value, and add the try-finally statement to block_. | 426 // original value, and add the try-finally statement to block_. |
| 427 auto target = block_; | 427 auto target = block_; |
| 428 if (FLAG_harmony_iterator_close) { | 428 block_ = factory()->NewBlock(nullptr, 8, true, nopos); |
| 429 block_ = factory()->NewBlock(nullptr, 8, true, nopos); | |
| 430 } | |
| 431 | 429 |
| 432 Spread* spread = nullptr; | 430 Spread* spread = nullptr; |
| 433 for (Expression* value : *node->values()) { | 431 for (Expression* value : *node->values()) { |
| 434 if (value->IsSpread()) { | 432 if (value->IsSpread()) { |
| 435 spread = value->AsSpread(); | 433 spread = value->AsSpread(); |
| 436 break; | 434 break; |
| 437 } | 435 } |
| 438 | 436 |
| 439 PatternContext context = SetInitializerContextIfNeeded(value); | 437 PatternContext context = SetInitializerContextIfNeeded(value); |
| 440 | 438 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 if_not_done = factory()->NewIfStatement( | 506 if_not_done = factory()->NewIfStatement( |
| 509 factory()->NewUnaryOperation(Token::NOT, | 507 factory()->NewUnaryOperation(Token::NOT, |
| 510 factory()->NewVariableProxy(done), | 508 factory()->NewVariableProxy(done), |
| 511 RelocInfo::kNoPosition), | 509 RelocInfo::kNoPosition), |
| 512 next_block, factory()->NewEmptyStatement(RelocInfo::kNoPosition), | 510 next_block, factory()->NewEmptyStatement(RelocInfo::kNoPosition), |
| 513 RelocInfo::kNoPosition); | 511 RelocInfo::kNoPosition); |
| 514 } | 512 } |
| 515 block_->statements()->Add(if_not_done, zone()); | 513 block_->statements()->Add(if_not_done, zone()); |
| 516 | 514 |
| 517 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) { | 515 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) { |
| 518 if (FLAG_harmony_iterator_close) { | 516 { |
| 519 // completion = kAbruptCompletion; | 517 // completion = kAbruptCompletion; |
| 520 Expression* proxy = factory()->NewVariableProxy(completion); | 518 Expression* proxy = factory()->NewVariableProxy(completion); |
| 521 Expression* assignment = factory()->NewAssignment( | 519 Expression* assignment = factory()->NewAssignment( |
| 522 Token::ASSIGN, proxy, | 520 Token::ASSIGN, proxy, |
| 523 factory()->NewSmiLiteral(kAbruptCompletion, nopos), nopos); | 521 factory()->NewSmiLiteral(kAbruptCompletion, nopos), nopos); |
| 524 block_->statements()->Add( | 522 block_->statements()->Add( |
| 525 factory()->NewExpressionStatement(assignment, nopos), zone()); | 523 factory()->NewExpressionStatement(assignment, nopos), zone()); |
| 526 } | 524 } |
| 527 | 525 |
| 528 RecurseIntoSubpattern(value, factory()->NewVariableProxy(v)); | 526 RecurseIntoSubpattern(value, factory()->NewVariableProxy(v)); |
| 529 | 527 |
| 530 if (FLAG_harmony_iterator_close) { | 528 { |
| 531 // completion = kNormalCompletion; | 529 // completion = kNormalCompletion; |
| 532 Expression* proxy = factory()->NewVariableProxy(completion); | 530 Expression* proxy = factory()->NewVariableProxy(completion); |
| 533 Expression* assignment = factory()->NewAssignment( | 531 Expression* assignment = factory()->NewAssignment( |
| 534 Token::ASSIGN, proxy, | 532 Token::ASSIGN, proxy, |
| 535 factory()->NewSmiLiteral(kNormalCompletion, nopos), nopos); | 533 factory()->NewSmiLiteral(kNormalCompletion, nopos), nopos); |
| 536 block_->statements()->Add( | 534 block_->statements()->Add( |
| 537 factory()->NewExpressionStatement(assignment, nopos), zone()); | 535 factory()->NewExpressionStatement(assignment, nopos), zone()); |
| 538 } | 536 } |
| 539 } | 537 } |
| 540 set_context(context); | 538 set_context(context); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 body->statements()->Add(get_next, zone()); | 631 body->statements()->Add(get_next, zone()); |
| 634 body->statements()->Add(maybe_append_and_unset_done, zone()); | 632 body->statements()->Add(maybe_append_and_unset_done, zone()); |
| 635 loop->Initialize(condition, body); | 633 loop->Initialize(condition, body); |
| 636 } | 634 } |
| 637 | 635 |
| 638 block_->statements()->Add(loop, zone()); | 636 block_->statements()->Add(loop, zone()); |
| 639 RecurseIntoSubpattern(spread->expression(), | 637 RecurseIntoSubpattern(spread->expression(), |
| 640 factory()->NewVariableProxy(array)); | 638 factory()->NewVariableProxy(array)); |
| 641 } | 639 } |
| 642 | 640 |
| 643 if (FLAG_harmony_iterator_close) { | 641 Expression* closing_condition = factory()->NewUnaryOperation( |
| 644 Expression* closing_condition = factory()->NewUnaryOperation( | 642 Token::NOT, factory()->NewVariableProxy(done), nopos); |
| 645 Token::NOT, factory()->NewVariableProxy(done), nopos); | 643 parser_->FinalizeIteratorUse(completion, closing_condition, iterator, block_, |
| 646 parser_->FinalizeIteratorUse(completion, closing_condition, iterator, | 644 target); |
| 647 block_, target); | 645 block_ = target; |
| 648 block_ = target; | |
| 649 } | |
| 650 } | 646 } |
| 651 | 647 |
| 652 | 648 |
| 653 void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) { | 649 void Parser::PatternRewriter::VisitArrayLiteral(ArrayLiteral* node) { |
| 654 Variable* temp_var = nullptr; | 650 Variable* temp_var = nullptr; |
| 655 VisitArrayLiteral(node, &temp_var); | 651 VisitArrayLiteral(node, &temp_var); |
| 656 } | 652 } |
| 657 | 653 |
| 658 | 654 |
| 659 void Parser::PatternRewriter::VisitAssignment(Assignment* node) { | 655 void Parser::PatternRewriter::VisitAssignment(Assignment* node) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 NOT_A_PATTERN(TryFinallyStatement) | 771 NOT_A_PATTERN(TryFinallyStatement) |
| 776 NOT_A_PATTERN(UnaryOperation) | 772 NOT_A_PATTERN(UnaryOperation) |
| 777 NOT_A_PATTERN(VariableDeclaration) | 773 NOT_A_PATTERN(VariableDeclaration) |
| 778 NOT_A_PATTERN(WhileStatement) | 774 NOT_A_PATTERN(WhileStatement) |
| 779 NOT_A_PATTERN(WithStatement) | 775 NOT_A_PATTERN(WithStatement) |
| 780 NOT_A_PATTERN(Yield) | 776 NOT_A_PATTERN(Yield) |
| 781 | 777 |
| 782 #undef NOT_A_PATTERN | 778 #undef NOT_A_PATTERN |
| 783 } // namespace internal | 779 } // namespace internal |
| 784 } // namespace v8 | 780 } // namespace v8 |
| OLD | NEW |