Reviewers: rossberg, adamk,
Message:
Andreas: PTAL.
Adam: FYI.
Description:
[turbofan] Support handling of default super calls.
This implements the missing %DefaultConstructorCallSuper runtime
functionality, thereby allowing all compilers to fall-back to that
implementation when the appropriate intrinsic is missing.
[email protected]
Please review this at https://codereview.chromium.org/1240993002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+44, -4 lines):
M src/compiler/ast-graph-builder.cc
M src/runtime/runtime-classes.cc
Index: src/compiler/ast-graph-builder.cc
diff --git a/src/compiler/ast-graph-builder.cc
b/src/compiler/ast-graph-builder.cc
index
9a28391858ac5995c2650c019999b175d8a33158..6f9371a061f6ffac5812926b5fb0ba71dc37f436
100644
--- a/src/compiler/ast-graph-builder.cc
+++ b/src/compiler/ast-graph-builder.cc
@@ -2583,8 +2583,7 @@ void AstGraphBuilder::VisitCallRuntime(CallRuntime*
expr) {
// TODO(mstarzinger): This bailout is a gigantic hack, the owner is
ashamed.
if (function->function_id == Runtime::kInlineGeneratorNext ||
- function->function_id == Runtime::kInlineGeneratorThrow ||
- function->function_id ==
Runtime::kInlineDefaultConstructorCallSuper) {
+ function->function_id == Runtime::kInlineGeneratorThrow) {
ast_context()->ProduceValue(jsgraph()->TheHoleConstant());
return SetStackOverflow();
}
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
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.