Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: src/runtime/runtime-classes.cc

Issue 1240993002: [turbofan] Support handling of default super calls. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Always install internal functions. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/linkage.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-classes.cc
diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc
index 7b42c1df3877c0b143be460c511b325a4fa0f90b..92df7fe0645d1e4e43017fe68c2ea8e109c0a4a1 100644
--- a/src/runtime/runtime-classes.cc
+++ b/src/runtime/runtime-classes.cc
@@ -521,8 +521,49 @@ RUNTIME_FUNCTION(Runtime_HandleStepInForDerivedConstructors) {
RUNTIME_FUNCTION(Runtime_DefaultConstructorCallSuper) {
- UNIMPLEMENTED();
- return nullptr;
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, original_constructor, 0);
+ CONVERT_ARG_HANDLE_CHECKED(JSFunction, actual_constructor, 1);
+ JavaScriptFrameIterator it(isolate);
+
+ // Prepare the callee to the super call. The super constructor is stored as
+ // the prototype of the constructor we are currently executing.
+ Handle<Object> super_constructor;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, super_constructor,
+ Runtime::GetPrototype(isolate, actual_constructor));
+
+ // Find the frame that holds the actual arguments passed to the function.
+ it.AdvanceToArgumentsFrame();
+ JavaScriptFrame* frame = it.frame();
+
+ // Prepare the array containing all passed arguments.
+ int argument_count = frame->GetArgumentsLength();
+ Handle<FixedArray> elements =
+ isolate->factory()->NewUninitializedFixedArray(argument_count);
+ for (int i = 0; i < argument_count; ++i) {
+ elements->set(i, frame->GetParameter(i));
+ }
+ Handle<JSArray> arguments = isolate->factory()->NewJSArrayWithElements(
+ elements, FAST_ELEMENTS, argument_count);
+
+ // Call $reflectConstruct(<super>, <args>, <new.target>) now.
+ Handle<Object> reflect;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, reflect,
+ Object::GetProperty(isolate,
+ handle(isolate->native_context()->builtins()),
+ "$reflectConstruct"));
+ RUNTIME_ASSERT(reflect->IsJSFunction()); // Depends on --harmony-reflect.
+ Handle<Object> argv[] = {super_constructor, arguments, original_constructor};
+ Handle<Object> result;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, result,
+ Execution::Call(isolate, reflect, isolate->factory()->undefined_value(),
+ arraysize(argv), argv));
+
+ return *result;
}
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/linkage.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698