From 813f48ff7ead2db76a049824e7103ef00aab1d3a Mon Sep 17 00:00:00 2001 From: neis Date: Thu, 4 Feb 2016 08:36:11 -0800 Subject: [PATCH] Fix embarrassing bug in last-minute change to yield* CL. R=littledan@chromium.org BUG= Review URL: https://codereview.chromium.org/1667503004 Cr-Commit-Position: refs/heads/master@{#33743} --- src/parsing/parser.cc | 37 +++++++++++++++++++++---------------- src/parsing/parser.h | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc index 81e0a5eb5a..dfac2c994f 100644 --- a/src/parsing/parser.cc +++ b/src/parsing/parser.cc @@ -5809,7 +5809,7 @@ void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value, // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); // break; // case kReturn: -// IteratorClose(iterator, input); // See below. +// IteratorClose(iterator, input, output); // See below. // break; // case kThrow: // let iteratorThrow = iterator.throw; @@ -5846,15 +5846,15 @@ void ParserTraits::SetFunctionNameFromIdentifierRef(Expression* value, // // let iteratorReturn = iterator.return; // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return; -// let result = %_Call(iteratorReturn, iterator); -// if (!IS_RECEIVER(result)) %ThrowIterResultNotAnObject(result); +// let output = %_Call(iteratorReturn, iterator); +// if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); // -// IteratorClose(iterator, input) expands to the following: +// IteratorClose(iterator, input, output) expands to the following: // // let iteratorReturn = iterator.return; // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return input; -// let result = %_Call(iteratorReturn, iterator, input); -// if (!IS_RECEIVER(result)) %ThrowIterResultNotAnObject(result); +// output = %_Call(iteratorReturn, iterator, input); +// if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); Expression* ParserTraits::RewriteYieldStar( @@ -6023,7 +6023,8 @@ Expression* ParserTraits::RewriteYieldStar( Statement* throw_call = factory->NewExpressionStatement(call, nopos); Block* then = factory->NewBlock(nullptr, 4+1, false, nopos); - BuildIteratorClose(then->statements(), var_iterator, Nothing()); + BuildIteratorClose(then->statements(), var_iterator, Nothing(), + Nothing()); then->statements()->Add(throw_call, zone); check_throw = factory->NewIfStatement(condition, then, skip, nopos); @@ -6195,7 +6196,8 @@ Expression* ParserTraits::RewriteYieldStar( case_next->Add(factory->NewBreakStatement(switch_mode, nopos), zone); auto case_return = new (zone) ZoneList(5, zone); - BuildIteratorClose(case_return, var_iterator, Just(var_input)); + BuildIteratorClose( + case_return, var_iterator, Just(var_input), Just(var_output)); case_return->Add(factory->NewBreakStatement(switch_mode, nopos), zone); auto case_throw = new (zone) ZoneList(5, zone); @@ -6259,7 +6261,8 @@ Expression* ParserTraits::RewriteYieldStar( void ParserTraits::BuildIteratorClose(ZoneList* statements, Variable* iterator, - Maybe input) { + Maybe input, + Maybe output) { const int nopos = RelocInfo::kNoPosition; auto factory = parser_->factory(); auto avfactory = parser_->ast_value_factory(); @@ -6300,8 +6303,8 @@ void ParserTraits::BuildIteratorClose(ZoneList* statements, factory->NewIfStatement(condition, return_undefined, skip, nopos); } - // let result = %_Call(iteratorReturn, iterator); OR - // let result = %_Call(iteratorReturn, iterator, input); + // let output = %_Call(iteratorReturn, iterator); OR + // output = %_Call(iteratorReturn, iterator, input); Statement* call_return; { auto args = new (zone) ZoneList(3, zone); @@ -6313,13 +6316,15 @@ void ParserTraits::BuildIteratorClose(ZoneList* statements, Expression* call = factory->NewCallRuntime(Runtime::kInlineCall, args, nopos); + Expression* output_proxy = factory->NewVariableProxy( + output.IsJust() ? output.FromJust() : var); Expression* assignment = factory->NewAssignment( - Token::ASSIGN, factory->NewVariableProxy(var), call, nopos); + Token::ASSIGN, output_proxy, call, nopos); call_return = factory->NewExpressionStatement(assignment, nopos); } - // if (!IS_RECEIVER(result)) %ThrowIterResultNotAnObject(result); - Statement* validate_result; + // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); + Statement* validate_output; { Expression* is_receiver_call; { @@ -6338,14 +6343,14 @@ void ParserTraits::BuildIteratorClose(ZoneList* statements, throw_call = factory->NewExpressionStatement(call, nopos); } - validate_result = + validate_output = factory->NewIfStatement(is_receiver_call, skip, throw_call, nopos); } statements->Add(get_return, zone); statements->Add(check_return, zone); statements->Add(call_return, zone); - statements->Add(validate_result, zone); + statements->Add(validate_output, zone); } diff --git a/src/parsing/parser.h b/src/parsing/parser.h index bb3b5c9ff3..0fb5d9785f 100644 --- a/src/parsing/parser.h +++ b/src/parsing/parser.h @@ -663,7 +663,7 @@ class ParserTraits { Parser* parser_; void BuildIteratorClose(ZoneList* statements, Variable* iterator, - Maybe input); + Maybe input, Maybe output); };