OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 CONVERT_ARG_HANDLE_CHECKED(JSFunction, actual_constructor, 1); | 520 CONVERT_ARG_HANDLE_CHECKED(JSFunction, actual_constructor, 1); |
521 JavaScriptFrameIterator it(isolate); | 521 JavaScriptFrameIterator it(isolate); |
522 | 522 |
523 // Prepare the callee to the super call. The super constructor is stored as | 523 // Prepare the callee to the super call. The super constructor is stored as |
524 // the prototype of the constructor we are currently executing. | 524 // the prototype of the constructor we are currently executing. |
525 Handle<Object> super_constructor; | 525 Handle<Object> super_constructor; |
526 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 526 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
527 isolate, super_constructor, | 527 isolate, super_constructor, |
528 Runtime::GetPrototype(isolate, actual_constructor)); | 528 Runtime::GetPrototype(isolate, actual_constructor)); |
529 | 529 |
530 // Find the frame that holds the actual arguments passed to the function. | 530 // Determine the actual arguments passed to the function. |
531 it.AdvanceToArgumentsFrame(); | 531 int argument_count = 0; |
532 JavaScriptFrame* frame = it.frame(); | 532 base::SmartArrayPointer<Handle<Object>> arguments = |
| 533 Runtime::GetCallerArguments(isolate, 0, &argument_count); |
533 | 534 |
534 // Prepare the array containing all passed arguments. | 535 // Prepare the array containing all passed arguments. |
535 int argument_count = frame->GetArgumentsLength(); | |
536 Handle<FixedArray> elements = | 536 Handle<FixedArray> elements = |
537 isolate->factory()->NewUninitializedFixedArray(argument_count); | 537 isolate->factory()->NewUninitializedFixedArray(argument_count); |
538 for (int i = 0; i < argument_count; ++i) { | 538 for (int i = 0; i < argument_count; ++i) { |
539 elements->set(i, frame->GetParameter(i)); | 539 elements->set(i, *arguments[i]); |
540 } | 540 } |
541 Handle<JSArray> arguments = isolate->factory()->NewJSArrayWithElements( | 541 Handle<JSArray> array = isolate->factory()->NewJSArrayWithElements( |
542 elements, FAST_ELEMENTS, argument_count); | 542 elements, FAST_ELEMENTS, argument_count); |
543 | 543 |
544 // Call %reflect_construct(<super>, <args>, <new.target>) now. | 544 // Call %reflect_construct(<super>, <args>, <new.target>) now. |
545 Handle<JSFunction> reflect = isolate->reflect_construct(); | 545 Handle<JSFunction> reflect = isolate->reflect_construct(); |
546 Handle<Object> argv[] = {super_constructor, arguments, original_constructor}; | 546 Handle<Object> argv[] = {super_constructor, array, original_constructor}; |
547 Handle<Object> result; | 547 Handle<Object> result; |
548 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 548 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
549 isolate, result, | 549 isolate, result, |
550 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(), | 550 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(), |
551 arraysize(argv), argv)); | 551 arraysize(argv), argv)); |
552 | 552 |
553 return *result; | 553 return *result; |
554 } | 554 } |
555 } // namespace internal | 555 } // namespace internal |
556 } // namespace v8 | 556 } // namespace v8 |
OLD | NEW |