Chromium Code Reviews| 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 5649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5660 factory()->NewCallRuntime(Runtime::kAppendElement, | 5660 factory()->NewCallRuntime(Runtime::kAppendElement, |
| 5661 append_element_args, | 5661 append_element_args, |
| 5662 RelocInfo::kNoPosition), | 5662 RelocInfo::kNoPosition), |
| 5663 RelocInfo::kNoPosition), | 5663 RelocInfo::kNoPosition), |
| 5664 zone()); | 5664 zone()); |
| 5665 } else { | 5665 } else { |
| 5666 // If it's a spread, we're adding a for/of loop iterating through it. | 5666 // If it's a spread, we're adding a for/of loop iterating through it. |
| 5667 Variable* each = | 5667 Variable* each = |
| 5668 scope_->NewTemporary(ast_value_factory()->dot_for_string()); | 5668 scope_->NewTemporary(ast_value_factory()->dot_for_string()); |
| 5669 Expression* subject = spread->expression(); | 5669 Expression* subject = spread->expression(); |
| 5670 Variable* iterator = | |
| 5671 scope_->NewTemporary(ast_value_factory()->dot_iterator_string()); | |
| 5672 Variable* element = | |
| 5673 scope_->NewTemporary(ast_value_factory()->dot_result_string()); | |
| 5674 // iterator = subject[Symbol.iterator]() | |
| 5675 Expression* assign_iterator = factory()->NewAssignment( | |
| 5676 Token::ASSIGN, factory()->NewVariableProxy(iterator), | |
| 5677 GetIterator(subject, factory(), spread->expression_position()), | |
|
nickie
2016/02/29 08:43:38
The only reason I can see that this may not be equ
| |
| 5678 subject->position()); | |
| 5679 // !%_IsJSReceiver(element = iterator.next()) && | |
| 5680 // %ThrowIteratorResultNotAnObject(element) | |
| 5681 Expression* next_element; | |
| 5682 { | |
| 5683 // element = iterator.next() | |
| 5684 Expression* iterator_proxy = factory()->NewVariableProxy(iterator); | |
| 5685 next_element = BuildIteratorNextResult(iterator_proxy, element, | |
| 5686 spread->expression_position()); | |
|
nickie
2016/02/29 08:43:38
Same here, InitializeForEachStatement uses a "hack
| |
| 5687 } | |
| 5688 // element.done | |
| 5689 Expression* element_done; | |
| 5690 { | |
| 5691 Expression* done_literal = factory()->NewStringLiteral( | |
| 5692 ast_value_factory()->done_string(), RelocInfo::kNoPosition); | |
| 5693 Expression* element_proxy = factory()->NewVariableProxy(element); | |
| 5694 element_done = factory()->NewProperty(element_proxy, done_literal, | |
| 5695 RelocInfo::kNoPosition); | |
| 5696 } | |
| 5697 // each = element.value | |
| 5698 Expression* assign_each; | |
| 5699 { | |
| 5700 Expression* value_literal = factory()->NewStringLiteral( | |
| 5701 ast_value_factory()->value_string(), RelocInfo::kNoPosition); | |
| 5702 Expression* element_proxy = factory()->NewVariableProxy(element); | |
| 5703 Expression* element_value = factory()->NewProperty( | |
| 5704 element_proxy, value_literal, RelocInfo::kNoPosition); | |
| 5705 assign_each = factory()->NewAssignment( | |
| 5706 Token::ASSIGN, factory()->NewVariableProxy(each), element_value, | |
| 5707 RelocInfo::kNoPosition); | |
| 5708 } | |
| 5709 // %AppendElement($R, each) | 5670 // %AppendElement($R, each) |
| 5710 Statement* append_body; | 5671 Statement* append_body; |
| 5711 { | 5672 { |
| 5712 ZoneList<Expression*>* append_element_args = | 5673 ZoneList<Expression*>* append_element_args = |
| 5713 NewExpressionList(2, zone()); | 5674 NewExpressionList(2, zone()); |
| 5714 append_element_args->Add(factory()->NewVariableProxy(result), zone()); | 5675 append_element_args->Add(factory()->NewVariableProxy(result), zone()); |
| 5715 append_element_args->Add(factory()->NewVariableProxy(each), zone()); | 5676 append_element_args->Add(factory()->NewVariableProxy(each), zone()); |
| 5716 append_body = factory()->NewExpressionStatement( | 5677 append_body = factory()->NewExpressionStatement( |
| 5717 factory()->NewCallRuntime(Runtime::kAppendElement, | 5678 factory()->NewCallRuntime(Runtime::kAppendElement, |
| 5718 append_element_args, | 5679 append_element_args, |
| 5719 RelocInfo::kNoPosition), | 5680 RelocInfo::kNoPosition), |
| 5720 RelocInfo::kNoPosition); | 5681 RelocInfo::kNoPosition); |
| 5721 } | 5682 } |
| 5722 // for (each of spread) %AppendElement($R, each) | 5683 // for (each of spread) %AppendElement($R, each) |
| 5723 ForEachStatement* loop = factory()->NewForEachStatement( | 5684 ForEachStatement* loop = factory()->NewForEachStatement( |
| 5724 ForEachStatement::ITERATE, nullptr, RelocInfo::kNoPosition); | 5685 ForEachStatement::ITERATE, nullptr, RelocInfo::kNoPosition); |
| 5725 ForOfStatement* for_of = loop->AsForOfStatement(); | 5686 InitializeForEachStatement(loop, factory()->NewVariableProxy(each), |
| 5726 for_of->Initialize(factory()->NewVariableProxy(each), subject, | 5687 subject, append_body, false); |
| 5727 append_body, iterator, assign_iterator, next_element, | 5688 do_block->statements()->Add(loop, zone()); |
| 5728 element_done, assign_each); | |
| 5729 do_block->statements()->Add(for_of, zone()); | |
| 5730 } | 5689 } |
| 5731 } | 5690 } |
| 5732 // Now, rewind the original array literal to truncate everything from the | 5691 // Now, rewind the original array literal to truncate everything from the |
| 5733 // first spread (included) until the end. This fixes $R's initialization. | 5692 // first spread (included) until the end. This fixes $R's initialization. |
| 5734 lit->RewindSpreads(); | 5693 lit->RewindSpreads(); |
| 5735 return factory()->NewDoExpression(do_block, result, lit->position()); | 5694 return factory()->NewDoExpression(do_block, result, lit->position()); |
| 5736 } | 5695 } |
| 5737 | 5696 |
| 5738 | 5697 |
| 5739 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { | 5698 void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) { |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6930 Expression* do_each = | 6889 Expression* do_each = |
| 6931 factory->NewDoExpression(new_assign_each, var_each, nopos); | 6890 factory->NewDoExpression(new_assign_each, var_each, nopos); |
| 6932 loop->set_assign_each(do_each); | 6891 loop->set_assign_each(do_each); |
| 6933 | 6892 |
| 6934 return final_loop; | 6893 return final_loop; |
| 6935 } | 6894 } |
| 6936 | 6895 |
| 6937 | 6896 |
| 6938 } // namespace internal | 6897 } // namespace internal |
| 6939 } // namespace v8 | 6898 } // namespace v8 |
| OLD | NEW |