| 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 // Handle stepping into constructors if step into is active. | 510 // Handle stepping into constructors if step into is active. |
| 511 if (debug->StepInActive()) debug->HandleStepIn(function, true); | 511 if (debug->StepInActive()) debug->HandleStepIn(function, true); |
| 512 return *isolate->factory()->undefined_value(); | 512 return *isolate->factory()->undefined_value(); |
| 513 } | 513 } |
| 514 | 514 |
| 515 | 515 |
| 516 RUNTIME_FUNCTION(Runtime_DefaultConstructorCallSuper) { | 516 RUNTIME_FUNCTION(Runtime_DefaultConstructorCallSuper) { |
| 517 HandleScope scope(isolate); | 517 HandleScope scope(isolate); |
| 518 DCHECK(args.length() == 2); | 518 DCHECK(args.length() == 2); |
| 519 CONVERT_ARG_HANDLE_CHECKED(JSFunction, original_constructor, 0); | 519 CONVERT_ARG_HANDLE_CHECKED(JSFunction, original_constructor, 0); |
| 520 CONVERT_ARG_HANDLE_CHECKED(JSFunction, actual_constructor, 1); | 520 CONVERT_ARG_HANDLE_CHECKED(JSFunction, super_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 | |
| 524 // the prototype of the constructor we are currently executing. | |
| 525 Handle<Object> super_constructor; | |
| 526 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 527 isolate, super_constructor, | |
| 528 Runtime::GetPrototype(isolate, actual_constructor)); | |
| 529 | |
| 530 // Determine the actual arguments passed to the function. | 523 // Determine the actual arguments passed to the function. |
| 531 int argument_count = 0; | 524 int argument_count = 0; |
| 532 base::SmartArrayPointer<Handle<Object>> arguments = | 525 base::SmartArrayPointer<Handle<Object>> arguments = |
| 533 Runtime::GetCallerArguments(isolate, 0, &argument_count); | 526 Runtime::GetCallerArguments(isolate, 0, &argument_count); |
| 534 | 527 |
| 535 // Prepare the array containing all passed arguments. | 528 // Prepare the array containing all passed arguments. |
| 536 Handle<FixedArray> elements = | 529 Handle<FixedArray> elements = |
| 537 isolate->factory()->NewUninitializedFixedArray(argument_count); | 530 isolate->factory()->NewUninitializedFixedArray(argument_count); |
| 538 for (int i = 0; i < argument_count; ++i) { | 531 for (int i = 0; i < argument_count; ++i) { |
| 539 elements->set(i, *arguments[i]); | 532 elements->set(i, *arguments[i]); |
| 540 } | 533 } |
| 541 Handle<JSArray> array = isolate->factory()->NewJSArrayWithElements( | 534 Handle<JSArray> array = isolate->factory()->NewJSArrayWithElements( |
| 542 elements, FAST_ELEMENTS, argument_count); | 535 elements, FAST_ELEMENTS, argument_count); |
| 543 | 536 |
| 544 // Call %reflect_construct(<super>, <args>, <new.target>) now. | 537 // Call %reflect_construct(<super>, <args>, <new.target>) now. |
| 545 Handle<JSFunction> reflect = isolate->reflect_construct(); | 538 Handle<JSFunction> reflect = isolate->reflect_construct(); |
| 546 Handle<Object> argv[] = {super_constructor, array, original_constructor}; | 539 Handle<Object> argv[] = {super_constructor, array, original_constructor}; |
| 547 Handle<Object> result; | 540 Handle<Object> result; |
| 548 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 541 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 549 isolate, result, | 542 isolate, result, |
| 550 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(), | 543 Execution::Call(isolate, reflect, isolate->factory()->undefined_value(), |
| 551 arraysize(argv), argv)); | 544 arraysize(argv), argv)); |
| 552 | 545 |
| 553 return *result; | 546 return *result; |
| 554 } | 547 } |
| 555 } // namespace internal | 548 } // namespace internal |
| 556 } // namespace v8 | 549 } // namespace v8 |
| OLD | NEW |