| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
| (...skipping 5789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5800 do_block->statements()->Add( | 5800 do_block->statements()->Add( |
| 5801 factory()->NewExpressionStatement(init_result, kNoSourcePosition), | 5801 factory()->NewExpressionStatement(init_result, kNoSourcePosition), |
| 5802 zone()); | 5802 zone()); |
| 5803 // Traverse the array literal starting from the first spread. | 5803 // Traverse the array literal starting from the first spread. |
| 5804 while (s != lit->EndValue()) { | 5804 while (s != lit->EndValue()) { |
| 5805 Expression* value = *s++; | 5805 Expression* value = *s++; |
| 5806 Spread* spread = value->AsSpread(); | 5806 Spread* spread = value->AsSpread(); |
| 5807 if (spread == nullptr) { | 5807 if (spread == nullptr) { |
| 5808 // If the element is not a spread, we're adding a single: | 5808 // If the element is not a spread, we're adding a single: |
| 5809 // %AppendElement($R, value) | 5809 // %AppendElement($R, value) |
| 5810 ZoneList<Expression*>* append_element_args = NewExpressionList(2, zone()); | 5810 // or, in case of a hole, |
| 5811 append_element_args->Add(factory()->NewVariableProxy(result), zone()); | 5811 // ++($R.length) |
| 5812 append_element_args->Add(value, zone()); | 5812 if (!value->IsLiteral() || |
| 5813 do_block->statements()->Add( | 5813 !value->AsLiteral()->raw_value()->IsTheHole()) { |
| 5814 factory()->NewExpressionStatement( | 5814 ZoneList<Expression*>* append_element_args = |
| 5815 factory()->NewCallRuntime(Runtime::kAppendElement, | 5815 NewExpressionList(2, zone()); |
| 5816 append_element_args, kNoSourcePosition), | 5816 append_element_args->Add(factory()->NewVariableProxy(result), zone()); |
| 5817 kNoSourcePosition), | 5817 append_element_args->Add(value, zone()); |
| 5818 zone()); | 5818 do_block->statements()->Add( |
| 5819 factory()->NewExpressionStatement( |
| 5820 factory()->NewCallRuntime(Runtime::kAppendElement, |
| 5821 append_element_args, |
| 5822 kNoSourcePosition), |
| 5823 kNoSourcePosition), |
| 5824 zone()); |
| 5825 } else { |
| 5826 Property* length_property = factory()->NewProperty( |
| 5827 factory()->NewVariableProxy(result), |
| 5828 factory()->NewStringLiteral(ast_value_factory()->length_string(), |
| 5829 kNoSourcePosition), |
| 5830 kNoSourcePosition); |
| 5831 CountOperation* count_op = factory()->NewCountOperation( |
| 5832 Token::INC, true /* prefix */, length_property, kNoSourcePosition); |
| 5833 do_block->statements()->Add( |
| 5834 factory()->NewExpressionStatement(count_op, kNoSourcePosition), |
| 5835 zone()); |
| 5836 } |
| 5819 } else { | 5837 } else { |
| 5820 // If it's a spread, we're adding a for/of loop iterating through it. | 5838 // If it's a spread, we're adding a for/of loop iterating through it. |
| 5821 Variable* each = NewTemporary(ast_value_factory()->dot_for_string()); | 5839 Variable* each = NewTemporary(ast_value_factory()->dot_for_string()); |
| 5822 Expression* subject = spread->expression(); | 5840 Expression* subject = spread->expression(); |
| 5823 // %AppendElement($R, each) | 5841 // %AppendElement($R, each) |
| 5824 Statement* append_body; | 5842 Statement* append_body; |
| 5825 { | 5843 { |
| 5826 ZoneList<Expression*>* append_element_args = | 5844 ZoneList<Expression*>* append_element_args = |
| 5827 NewExpressionList(2, zone()); | 5845 NewExpressionList(2, zone()); |
| 5828 append_element_args->Add(factory()->NewVariableProxy(result), zone()); | 5846 append_element_args->Add(factory()->NewVariableProxy(result), zone()); |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6841 node->Print(Isolate::Current()); | 6859 node->Print(Isolate::Current()); |
| 6842 } | 6860 } |
| 6843 #endif // DEBUG | 6861 #endif // DEBUG |
| 6844 | 6862 |
| 6845 #undef CHECK_OK | 6863 #undef CHECK_OK |
| 6846 #undef CHECK_OK_VOID | 6864 #undef CHECK_OK_VOID |
| 6847 #undef CHECK_FAILED | 6865 #undef CHECK_FAILED |
| 6848 | 6866 |
| 6849 } // namespace internal | 6867 } // namespace internal |
| 6850 } // namespace v8 | 6868 } // namespace v8 |
| OLD | NEW |