Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: src/parsing/pattern-rewriter.cc

Issue 1778333002: Fix corner case in iterator finalization for array destructuring. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/iterator-close.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (value->IsSpread()) { 436 if (value->IsSpread()) {
437 spread = value->AsSpread(); 437 spread = value->AsSpread();
438 break; 438 break;
439 } 439 }
440 440
441 PatternContext context = SetInitializerContextIfNeeded(value); 441 PatternContext context = SetInitializerContextIfNeeded(value);
442 442
443 // if (!done) { 443 // if (!done) {
444 // done = true; // If .next, .done or .value throws, don't close. 444 // done = true; // If .next, .done or .value throws, don't close.
445 // result = IteratorNext(iterator); 445 // result = IteratorNext(iterator);
446 // v = (done = result.done) ? undefined : result.value; 446 // if (result.done) {
447 // v = undefined;
448 // } else {
449 // v = result.value;
450 // done = false;
451 // }
447 // } 452 // }
448 Statement* if_statement; 453 Statement* if_not_done;
449 { 454 {
455 auto result_done = factory()->NewProperty(
456 factory()->NewVariableProxy(result),
457 factory()->NewStringLiteral(ast_value_factory()->done_string(),
458 RelocInfo::kNoPosition),
459 RelocInfo::kNoPosition);
460
461 auto assign_undefined = factory()->NewAssignment(
462 Token::ASSIGN, factory()->NewVariableProxy(v),
463 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
464 RelocInfo::kNoPosition);
465
466 auto assign_value = factory()->NewAssignment(
467 Token::ASSIGN, factory()->NewVariableProxy(v),
468 factory()->NewProperty(
469 factory()->NewVariableProxy(result),
470 factory()->NewStringLiteral(ast_value_factory()->value_string(),
471 RelocInfo::kNoPosition),
472 RelocInfo::kNoPosition),
473 RelocInfo::kNoPosition);
474
475 auto unset_done = factory()->NewAssignment(
476 Token::ASSIGN, factory()->NewVariableProxy(done),
477 factory()->NewBooleanLiteral(false, RelocInfo::kNoPosition),
478 RelocInfo::kNoPosition);
479
480 auto inner_else =
481 factory()->NewBlock(nullptr, 2, true, RelocInfo::kNoPosition);
482 inner_else->statements()->Add(
483 factory()->NewExpressionStatement(assign_value, nopos), zone());
484 inner_else->statements()->Add(
485 factory()->NewExpressionStatement(unset_done, nopos), zone());
486
487 auto inner_if = factory()->NewIfStatement(
488 result_done,
489 factory()->NewExpressionStatement(assign_undefined, nopos),
490 inner_else, nopos);
491
450 auto next_block = 492 auto next_block =
451 factory()->NewBlock(nullptr, 3, true, RelocInfo::kNoPosition); 493 factory()->NewBlock(nullptr, 3, true, RelocInfo::kNoPosition);
452
453 next_block->statements()->Add( 494 next_block->statements()->Add(
454 factory()->NewExpressionStatement( 495 factory()->NewExpressionStatement(
455 factory()->NewAssignment( 496 factory()->NewAssignment(
456 Token::ASSIGN, factory()->NewVariableProxy(done), 497 Token::ASSIGN, factory()->NewVariableProxy(done),
457 factory()->NewBooleanLiteral(true, nopos), nopos), 498 factory()->NewBooleanLiteral(true, nopos), nopos),
458 nopos), 499 nopos),
459 zone()); 500 zone());
460
461 next_block->statements()->Add( 501 next_block->statements()->Add(
462 factory()->NewExpressionStatement( 502 factory()->NewExpressionStatement(
463 parser_->BuildIteratorNextResult( 503 parser_->BuildIteratorNextResult(
464 factory()->NewVariableProxy(iterator), result, 504 factory()->NewVariableProxy(iterator), result,
465 RelocInfo::kNoPosition), 505 RelocInfo::kNoPosition),
466 RelocInfo::kNoPosition), 506 RelocInfo::kNoPosition),
467 zone()); 507 zone());
508 next_block->statements()->Add(inner_if, zone());
468 509
469 auto assign_to_done = factory()->NewAssignment( 510 if_not_done = factory()->NewIfStatement(
470 Token::ASSIGN, factory()->NewVariableProxy(done),
471 factory()->NewProperty(
472 factory()->NewVariableProxy(result),
473 factory()->NewStringLiteral(ast_value_factory()->done_string(),
474 RelocInfo::kNoPosition),
475 RelocInfo::kNoPosition),
476 RelocInfo::kNoPosition);
477 auto next_value = factory()->NewConditional(
478 assign_to_done,
479 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition),
480 factory()->NewProperty(
481 factory()->NewVariableProxy(result),
482 factory()->NewStringLiteral(ast_value_factory()->value_string(),
483 RelocInfo::kNoPosition),
484 RelocInfo::kNoPosition),
485 RelocInfo::kNoPosition);
486 next_block->statements()->Add(
487 factory()->NewExpressionStatement(
488 factory()->NewAssignment(Token::ASSIGN,
489 factory()->NewVariableProxy(v),
490 next_value, RelocInfo::kNoPosition),
491 RelocInfo::kNoPosition),
492 zone());
493
494 if_statement = factory()->NewIfStatement(
495 factory()->NewUnaryOperation(Token::NOT, 511 factory()->NewUnaryOperation(Token::NOT,
496 factory()->NewVariableProxy(done), 512 factory()->NewVariableProxy(done),
497 RelocInfo::kNoPosition), 513 RelocInfo::kNoPosition),
498 next_block, factory()->NewEmptyStatement(RelocInfo::kNoPosition), 514 next_block, factory()->NewEmptyStatement(RelocInfo::kNoPosition),
499 RelocInfo::kNoPosition); 515 RelocInfo::kNoPosition);
500 } 516 }
501 block_->statements()->Add(if_statement, zone()); 517 block_->statements()->Add(if_not_done, zone());
502 518
503 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) { 519 if (!(value->IsLiteral() && value->AsLiteral()->raw_value()->IsTheHole())) {
504 if (FLAG_harmony_iterator_close) { 520 if (FLAG_harmony_iterator_close) {
505 // completion = kAbruptCompletion; 521 // completion = kAbruptCompletion;
506 Expression* proxy = factory()->NewVariableProxy(completion); 522 Expression* proxy = factory()->NewVariableProxy(completion);
507 Expression* assignment = factory()->NewAssignment( 523 Expression* assignment = factory()->NewAssignment(
508 Token::ASSIGN, proxy, 524 Token::ASSIGN, proxy,
509 factory()->NewSmiLiteral(kAbruptCompletion, nopos), nopos); 525 factory()->NewSmiLiteral(kAbruptCompletion, nopos), nopos);
510 block_->statements()->Add( 526 block_->statements()->Add(
511 factory()->NewExpressionStatement(assignment, nopos), zone()); 527 factory()->NewExpressionStatement(assignment, nopos), zone());
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 NOT_A_PATTERN(TryFinallyStatement) 699 NOT_A_PATTERN(TryFinallyStatement)
684 NOT_A_PATTERN(UnaryOperation) 700 NOT_A_PATTERN(UnaryOperation)
685 NOT_A_PATTERN(VariableDeclaration) 701 NOT_A_PATTERN(VariableDeclaration)
686 NOT_A_PATTERN(WhileStatement) 702 NOT_A_PATTERN(WhileStatement)
687 NOT_A_PATTERN(WithStatement) 703 NOT_A_PATTERN(WithStatement)
688 NOT_A_PATTERN(Yield) 704 NOT_A_PATTERN(Yield)
689 705
690 #undef NOT_A_PATTERN 706 #undef NOT_A_PATTERN
691 } // namespace internal 707 } // namespace internal
692 } // namespace v8 708 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/iterator-close.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698