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

Side by Side Diff: src/parsing/parser.cc

Issue 2100093002: Fix behavior of return on yield*. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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/function-sent.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 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/parsing/parser.h" 5 #include "src/parsing/parser.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/ast/ast.h" 8 #include "src/ast/ast.h"
9 #include "src/ast/ast-expression-rewriter.h" 9 #include "src/ast/ast-expression-rewriter.h"
10 #include "src/ast/ast-expression-visitor.h" 10 #include "src/ast/ast-expression-visitor.h"
(...skipping 5991 matching lines...) Expand 10 before | Expand all | Expand 10 after
6002 // mode = kNext; 6002 // mode = kNext;
6003 // } catch (error) { 6003 // } catch (error) {
6004 // mode = kThrow; 6004 // mode = kThrow;
6005 // } 6005 // }
6006 // } finally { 6006 // } finally {
6007 // input = function.sent; 6007 // input = function.sent;
6008 // continue; 6008 // continue;
6009 // } 6009 // }
6010 // } 6010 // }
6011 // 6011 //
6012 // output.value; 6012 // if (mode === kReturn) {
6013 // return {value: output.value, done: true};
6014 // }
6015 // output.value
6013 // } 6016 // }
6014 // 6017 //
6015 // IteratorClose(iterator) expands to the following: 6018 // IteratorClose(iterator) expands to the following:
6016 // 6019 //
6017 // let iteratorReturn = iterator.return; 6020 // let iteratorReturn = iterator.return;
6018 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return; 6021 // if (IS_NULL_OR_UNDEFINED(iteratorReturn)) return;
6019 // let output = %_Call(iteratorReturn, iterator); 6022 // let output = %_Call(iteratorReturn, iterator);
6020 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); 6023 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output);
6021 // 6024 //
6022 // IteratorClose(iterator, input, output) expands to the following: 6025 // IteratorClose(iterator, input, output) expands to the following:
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
6298 Statement* get_input; 6301 Statement* get_input;
6299 { 6302 {
6300 Expression* function_sent = FunctionSentExpression(scope, factory, nopos); 6303 Expression* function_sent = FunctionSentExpression(scope, factory, nopos);
6301 Expression* input_proxy = factory->NewVariableProxy(var_input); 6304 Expression* input_proxy = factory->NewVariableProxy(var_input);
6302 Expression* assignment = factory->NewAssignment( 6305 Expression* assignment = factory->NewAssignment(
6303 Token::ASSIGN, input_proxy, function_sent, nopos); 6306 Token::ASSIGN, input_proxy, function_sent, nopos);
6304 get_input = factory->NewExpressionStatement(assignment, nopos); 6307 get_input = factory->NewExpressionStatement(assignment, nopos);
6305 } 6308 }
6306 6309
6307 6310
6308 // output.value; 6311 // if (mode === kReturn) {
6312 // return {value: output.value, done: true};
6313 // }
6314 Statement* maybe_return_value;
6315 {
6316 Expression* mode_proxy = factory->NewVariableProxy(var_mode);
6317 Expression* kreturn =
6318 factory->NewSmiLiteral(JSGeneratorObject::kReturn, nopos);
6319 Expression* condition = factory->NewCompareOperation(
6320 Token::EQ_STRICT, mode_proxy, kreturn, nopos);
6321
6322 Expression* output_proxy = factory->NewVariableProxy(var_output);
6323 Expression* literal =
6324 factory->NewStringLiteral(avfactory->value_string(), nopos);
6325 Expression* property = factory->NewProperty(output_proxy, literal, nopos);
6326 Statement* return_value =
6327 factory->NewReturnStatement(BuildIteratorResult(property, true), nopos);
6328
6329 maybe_return_value = factory->NewIfStatement(
6330 condition, return_value, factory->NewEmptyStatement(nopos), nopos);
6331 }
6332
6333
6334 // output.value
6309 Statement* get_value; 6335 Statement* get_value;
6310 { 6336 {
6311 Expression* output_proxy = factory->NewVariableProxy(var_output); 6337 Expression* output_proxy = factory->NewVariableProxy(var_output);
6312 Expression* literal = 6338 Expression* literal =
6313 factory->NewStringLiteral(avfactory->value_string(), nopos); 6339 factory->NewStringLiteral(avfactory->value_string(), nopos);
6314 Expression* property = factory->NewProperty(output_proxy, literal, nopos); 6340 Expression* property = factory->NewProperty(output_proxy, literal, nopos);
6315 get_value = factory->NewExpressionStatement(property, nopos); 6341 get_value = factory->NewExpressionStatement(property, nopos);
6316 } 6342 }
6317 6343
6318 6344
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
6401 loop->Initialize(factory->NewBooleanLiteral(true, nopos), loop_body); 6427 loop->Initialize(factory->NewBooleanLiteral(true, nopos), loop_body);
6402 } 6428 }
6403 6429
6404 6430
6405 // do { ... } 6431 // do { ... }
6406 DoExpression* yield_star; 6432 DoExpression* yield_star;
6407 { 6433 {
6408 // The rewriter needs to process the get_value statement only, hence we 6434 // The rewriter needs to process the get_value statement only, hence we
6409 // put the preceding statements into an init block. 6435 // put the preceding statements into an init block.
6410 6436
6411 Block* do_block_ = factory->NewBlock(nullptr, 6, true, nopos); 6437 Block* do_block_ = factory->NewBlock(nullptr, 7, true, nopos);
6412 do_block_->statements()->Add(initialize_input, zone); 6438 do_block_->statements()->Add(initialize_input, zone);
6413 do_block_->statements()->Add(initialize_mode, zone); 6439 do_block_->statements()->Add(initialize_mode, zone);
6414 do_block_->statements()->Add(initialize_output, zone); 6440 do_block_->statements()->Add(initialize_output, zone);
6415 do_block_->statements()->Add(get_iterator, zone); 6441 do_block_->statements()->Add(get_iterator, zone);
6416 do_block_->statements()->Add(validate_iterator, zone); 6442 do_block_->statements()->Add(validate_iterator, zone);
6417 do_block_->statements()->Add(loop, zone); 6443 do_block_->statements()->Add(loop, zone);
6444 do_block_->statements()->Add(maybe_return_value, zone);
6418 6445
6419 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos); 6446 Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
6420 do_block->statements()->Add(do_block_, zone); 6447 do_block->statements()->Add(do_block_, zone);
6421 do_block->statements()->Add(get_value, zone); 6448 do_block->statements()->Add(get_value, zone);
6422 6449
6423 Variable* dot_result = scope->NewTemporary(avfactory->dot_result_string()); 6450 Variable* dot_result = scope->NewTemporary(avfactory->dot_result_string());
6424 yield_star = factory->NewDoExpression(do_block, dot_result, nopos); 6451 yield_star = factory->NewDoExpression(do_block, dot_result, nopos);
6425 Rewriter::Rewrite(parser_, yield_star, avfactory); 6452 Rewriter::Rewrite(parser_, yield_star, avfactory);
6426 } 6453 }
6427 6454
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
6976 try_block, target); 7003 try_block, target);
6977 final_loop = target; 7004 final_loop = target;
6978 } 7005 }
6979 7006
6980 return final_loop; 7007 return final_loop;
6981 } 7008 }
6982 7009
6983 7010
6984 } // namespace internal 7011 } // namespace internal
6985 } // namespace v8 7012 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/function-sent.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698