| 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 3736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3747 | 3747 |
| 3748 list = new (zone()) ZoneList<Expression*>(1, zone()); | 3748 list = new (zone()) ZoneList<Expression*>(1, zone()); |
| 3749 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args, | 3749 list->Add(factory()->NewCallRuntime(Context::SPREAD_ARGUMENTS_INDEX, args, |
| 3750 kNoSourcePosition), | 3750 kNoSourcePosition), |
| 3751 zone()); | 3751 zone()); |
| 3752 return list; | 3752 return list; |
| 3753 } | 3753 } |
| 3754 UNREACHABLE(); | 3754 UNREACHABLE(); |
| 3755 } | 3755 } |
| 3756 | 3756 |
| 3757 namespace { |
| 3758 |
| 3759 bool OnlyLastArgIsSpread(ZoneList<Expression*>* args) { |
| 3760 for (int i = 0; i < args->length() - 1; i++) { |
| 3761 if (args->at(i)->IsSpread()) { |
| 3762 return false; |
| 3763 } |
| 3764 } |
| 3765 return args->at(args->length() - 1)->IsSpread(); |
| 3766 } |
| 3767 |
| 3768 } // namespace |
| 3769 |
| 3757 Expression* Parser::SpreadCall(Expression* function, | 3770 Expression* Parser::SpreadCall(Expression* function, |
| 3758 ZoneList<Expression*>* args, int pos) { | 3771 ZoneList<Expression*>* args, int pos, |
| 3772 Call::PossiblyEval is_possibly_eval) { |
| 3759 if (function->IsSuperCallReference()) { | 3773 if (function->IsSuperCallReference()) { |
| 3760 // Super calls | 3774 // Super calls |
| 3761 // $super_constructor = %_GetSuperConstructor(<this-function>) | 3775 // $super_constructor = %_GetSuperConstructor(<this-function>) |
| 3762 // %reflect_construct($super_constructor, args, new.target) | 3776 // %reflect_construct($super_constructor, args, new.target) |
| 3763 | 3777 |
| 3764 bool only_last_arg_is_spread = false; | 3778 if (OnlyLastArgIsSpread(args)) { |
| 3765 for (int i = 0; i < args->length(); i++) { | |
| 3766 if (args->at(i)->IsSpread()) { | |
| 3767 if (i == args->length() - 1) { | |
| 3768 only_last_arg_is_spread = true; | |
| 3769 } | |
| 3770 break; | |
| 3771 } | |
| 3772 } | |
| 3773 | |
| 3774 if (only_last_arg_is_spread) { | |
| 3775 // Handle in BytecodeGenerator. | 3779 // Handle in BytecodeGenerator. |
| 3776 Expression* super_call_ref = NewSuperCallReference(pos); | 3780 Expression* super_call_ref = NewSuperCallReference(pos); |
| 3777 return factory()->NewCall(super_call_ref, args, pos); | 3781 return factory()->NewCall(super_call_ref, args, pos); |
| 3778 } | 3782 } |
| 3779 args = PrepareSpreadArguments(args); | 3783 args = PrepareSpreadArguments(args); |
| 3780 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); | 3784 ZoneList<Expression*>* tmp = new (zone()) ZoneList<Expression*>(1, zone()); |
| 3781 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); | 3785 tmp->Add(function->AsSuperCallReference()->this_function_var(), zone()); |
| 3782 Expression* super_constructor = factory()->NewCallRuntime( | 3786 Expression* super_constructor = factory()->NewCallRuntime( |
| 3783 Runtime::kInlineGetSuperConstructor, tmp, pos); | 3787 Runtime::kInlineGetSuperConstructor, tmp, pos); |
| 3784 args->InsertAt(0, super_constructor, zone()); | 3788 args->InsertAt(0, super_constructor, zone()); |
| 3785 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); | 3789 args->Add(function->AsSuperCallReference()->new_target_var(), zone()); |
| 3786 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, | 3790 return factory()->NewCallRuntime(Context::REFLECT_CONSTRUCT_INDEX, args, |
| 3787 pos); | 3791 pos); |
| 3788 } else { | 3792 } else { |
| 3793 if (OnlyLastArgIsSpread(args)) { |
| 3794 // Handle in BytecodeGenerator. |
| 3795 return factory()->NewCall(function, args, pos, is_possibly_eval); |
| 3796 } |
| 3797 |
| 3789 args = PrepareSpreadArguments(args); | 3798 args = PrepareSpreadArguments(args); |
| 3790 if (function->IsProperty()) { | 3799 if (function->IsProperty()) { |
| 3791 // Method calls | 3800 // Method calls |
| 3792 if (function->AsProperty()->IsSuperAccess()) { | 3801 if (function->AsProperty()->IsSuperAccess()) { |
| 3793 Expression* home = ThisExpression(kNoSourcePosition); | 3802 Expression* home = ThisExpression(kNoSourcePosition); |
| 3794 args->InsertAt(0, function, zone()); | 3803 args->InsertAt(0, function, zone()); |
| 3795 args->InsertAt(1, home, zone()); | 3804 args->InsertAt(1, home, zone()); |
| 3796 } else { | 3805 } else { |
| 3797 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); | 3806 Variable* temp = NewTemporary(ast_value_factory()->empty_string()); |
| 3798 VariableProxy* obj = factory()->NewVariableProxy(temp); | 3807 VariableProxy* obj = factory()->NewVariableProxy(temp); |
| (...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5129 | 5138 |
| 5130 return final_loop; | 5139 return final_loop; |
| 5131 } | 5140 } |
| 5132 | 5141 |
| 5133 #undef CHECK_OK | 5142 #undef CHECK_OK |
| 5134 #undef CHECK_OK_VOID | 5143 #undef CHECK_OK_VOID |
| 5135 #undef CHECK_FAILED | 5144 #undef CHECK_FAILED |
| 5136 | 5145 |
| 5137 } // namespace internal | 5146 } // namespace internal |
| 5138 } // namespace v8 | 5147 } // namespace v8 |
| OLD | NEW |