| 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/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 6382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6393 | 6393 |
| 6394 void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements, | 6394 void ParserTraits::BuildIteratorClose(ZoneList<Statement*>* statements, |
| 6395 Variable* iterator, | 6395 Variable* iterator, |
| 6396 Maybe<Variable*> input, | 6396 Maybe<Variable*> input, |
| 6397 Variable* var_output) { | 6397 Variable* var_output) { |
| 6398 // | 6398 // |
| 6399 // This function adds four statements to [statements], corresponding to the | 6399 // This function adds four statements to [statements], corresponding to the |
| 6400 // following code: | 6400 // following code: |
| 6401 // | 6401 // |
| 6402 // let iteratorReturn = iterator.return; | 6402 // let iteratorReturn = iterator.return; |
| 6403 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) return |input|; | 6403 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) { |
| 6404 // output = %_Call(iteratorReturn, iterator|, input|); | 6404 // return {value: input, done: true}; |
| 6405 // } |
| 6406 // output = %_Call(iteratorReturn, iterator, input); |
| 6405 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); | 6407 // if (!IS_RECEIVER(output)) %ThrowIterResultNotAnObject(output); |
| 6406 // | 6408 // |
| 6407 // Here, |...| denotes optional parts, depending on the presence of the | 6409 // When the input variable is not given, the return statement becomes |
| 6408 // input variable. The reason for allowing input is that BuildIteratorClose | 6410 // return {value: undefined, done: true}; |
| 6411 // and %_Call has only two arguments: |
| 6412 // output = %_Call(iteratorReturn, iterator); |
| 6413 // |
| 6414 // The reason for allowing input is that BuildIteratorClose |
| 6409 // can then be reused to handle the return case in yield*. | 6415 // can then be reused to handle the return case in yield*. |
| 6410 // | 6416 // |
| 6411 | 6417 |
| 6412 const int nopos = RelocInfo::kNoPosition; | 6418 const int nopos = RelocInfo::kNoPosition; |
| 6413 auto factory = parser_->factory(); | 6419 auto factory = parser_->factory(); |
| 6414 auto avfactory = parser_->ast_value_factory(); | 6420 auto avfactory = parser_->ast_value_factory(); |
| 6415 auto zone = parser_->zone(); | 6421 auto zone = parser_->zone(); |
| 6416 | 6422 |
| 6417 // let iteratorReturn = iterator.return; | 6423 // let iteratorReturn = iterator.return; |
| 6418 Variable* var_return = var_output; // Reusing the output variable. | 6424 Variable* var_return = var_output; // Reusing the output variable. |
| 6419 Statement* get_return; | 6425 Statement* get_return; |
| 6420 { | 6426 { |
| 6421 Expression* iterator_proxy = factory->NewVariableProxy(iterator); | 6427 Expression* iterator_proxy = factory->NewVariableProxy(iterator); |
| 6422 Expression* literal = | 6428 Expression* literal = |
| 6423 factory->NewStringLiteral(avfactory->return_string(), nopos); | 6429 factory->NewStringLiteral(avfactory->return_string(), nopos); |
| 6424 Expression* property = | 6430 Expression* property = |
| 6425 factory->NewProperty(iterator_proxy, literal, nopos); | 6431 factory->NewProperty(iterator_proxy, literal, nopos); |
| 6426 Expression* return_proxy = factory->NewVariableProxy(var_return); | 6432 Expression* return_proxy = factory->NewVariableProxy(var_return); |
| 6427 Expression* assignment = factory->NewAssignment( | 6433 Expression* assignment = factory->NewAssignment( |
| 6428 Token::ASSIGN, return_proxy, property, nopos); | 6434 Token::ASSIGN, return_proxy, property, nopos); |
| 6429 get_return = factory->NewExpressionStatement(assignment, nopos); | 6435 get_return = factory->NewExpressionStatement(assignment, nopos); |
| 6430 } | 6436 } |
| 6431 | 6437 |
| 6432 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) return |input|; | 6438 // if (IS_NULL_OR_UNDEFINED(iteratorReturn) { |
| 6439 // return {value: input, done: true}; |
| 6440 // } |
| 6433 Statement* check_return; | 6441 Statement* check_return; |
| 6434 { | 6442 { |
| 6435 Expression* condition = factory->NewCompareOperation( | 6443 Expression* condition = factory->NewCompareOperation( |
| 6436 Token::EQ, factory->NewVariableProxy(var_return), | 6444 Token::EQ, factory->NewVariableProxy(var_return), |
| 6437 factory->NewNullLiteral(nopos), nopos); | 6445 factory->NewNullLiteral(nopos), nopos); |
| 6438 | 6446 |
| 6439 Expression* value = input.IsJust() | 6447 Expression* value = input.IsJust() |
| 6440 ? static_cast<Expression*>( | 6448 ? static_cast<Expression*>( |
| 6441 factory->NewVariableProxy(input.FromJust())) | 6449 factory->NewVariableProxy(input.FromJust())) |
| 6442 : factory->NewUndefinedLiteral(nopos); | 6450 : factory->NewUndefinedLiteral(nopos); |
| 6443 | 6451 |
| 6444 Statement* return_input = factory->NewReturnStatement(value, nopos); | 6452 Statement* return_input = |
| 6453 factory->NewReturnStatement(BuildIteratorResult(value, true), nopos); |
| 6445 | 6454 |
| 6446 check_return = factory->NewIfStatement( | 6455 check_return = factory->NewIfStatement( |
| 6447 condition, return_input, factory->NewEmptyStatement(nopos), nopos); | 6456 condition, return_input, factory->NewEmptyStatement(nopos), nopos); |
| 6448 } | 6457 } |
| 6449 | 6458 |
| 6450 // output = %_Call(iteratorReturn, iterator, |input|); | 6459 // output = %_Call(iteratorReturn, iterator, input); |
| 6451 Statement* call_return; | 6460 Statement* call_return; |
| 6452 { | 6461 { |
| 6453 auto args = new (zone) ZoneList<Expression*>(3, zone); | 6462 auto args = new (zone) ZoneList<Expression*>(3, zone); |
| 6454 args->Add(factory->NewVariableProxy(var_return), zone); | 6463 args->Add(factory->NewVariableProxy(var_return), zone); |
| 6455 args->Add(factory->NewVariableProxy(iterator), zone); | 6464 args->Add(factory->NewVariableProxy(iterator), zone); |
| 6456 if (input.IsJust()) { | 6465 if (input.IsJust()) { |
| 6457 args->Add(factory->NewVariableProxy(input.FromJust()), zone); | 6466 args->Add(factory->NewVariableProxy(input.FromJust()), zone); |
| 6458 } | 6467 } |
| 6459 | 6468 |
| 6460 Expression* call = | 6469 Expression* call = |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6912 try_block, target); | 6921 try_block, target); |
| 6913 final_loop = target; | 6922 final_loop = target; |
| 6914 } | 6923 } |
| 6915 | 6924 |
| 6916 return final_loop; | 6925 return final_loop; |
| 6917 } | 6926 } |
| 6918 | 6927 |
| 6919 | 6928 |
| 6920 } // namespace internal | 6929 } // namespace internal |
| 6921 } // namespace v8 | 6930 } // namespace v8 |
| OLD | NEW |