Index: src/builtins.cc |
diff --git a/src/builtins.cc b/src/builtins.cc |
index de5817188d95db5b9c63cb773f8592b0e08ad5ab..0a1262ffa062ce602c026262c300c97d998e9074 100644 |
--- a/src/builtins.cc |
+++ b/src/builtins.cc |
@@ -3523,22 +3523,33 @@ MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
Isolate* isolate, BuiltinArguments<BuiltinExtraArguments::kTarget> args) { |
HandleScope scope(isolate); |
Handle<JSFunction> function = args.target(); |
- DCHECK(args.receiver()->IsJSReceiver()); |
+ Handle<JSReceiver> receiver; |
// TODO(ishell): turn this back to a DCHECK. |
CHECK(function->shared()->IsApiFunction()); |
Handle<FunctionTemplateInfo> fun_data( |
function->shared()->get_api_func_data(), isolate); |
if (is_construct) { |
- ASSIGN_RETURN_ON_EXCEPTION( |
- isolate, fun_data, |
- ApiNatives::ConfigureInstance(isolate, fun_data, |
- Handle<JSObject>::cast(args.receiver())), |
- Object); |
+ DCHECK(args.receiver()->IsTheHole()); |
+ if (fun_data->instance_template()->IsUndefined()) { |
+ v8::Local<ObjectTemplate> templ = |
+ ObjectTemplate::New(reinterpret_cast<v8::Isolate*>(isolate), |
+ ToApiHandle<v8::FunctionTemplate>(fun_data)); |
+ fun_data->set_instance_template(*Utils::OpenHandle(*templ)); |
+ } |
+ Handle<ObjectTemplateInfo> instance_template( |
+ ObjectTemplateInfo::cast(fun_data->instance_template()), isolate); |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, |
+ ApiNatives::InstantiateObject(instance_template), |
+ Object); |
+ args[0] = *receiver; |
+ DCHECK_EQ(*receiver, *args.receiver()); |
+ } else { |
+ DCHECK(args.receiver()->IsJSReceiver()); |
+ receiver = args.at<JSReceiver>(0); |
} |
if (!is_construct && !fun_data->accept_any_receiver()) { |
- Handle<JSReceiver> receiver = args.at<JSReceiver>(0); |
if (receiver->IsJSObject() && receiver->IsAccessCheckNeeded()) { |
Handle<JSObject> js_receiver = Handle<JSObject>::cast(receiver); |
if (!isolate->MayAccess(handle(isolate->context()), js_receiver)) { |
@@ -3548,7 +3559,7 @@ MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
} |
} |
- Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, args[0]); |
+ Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, *receiver); |
if (raw_holder->IsNull()) { |
// This function cannot be called with the given receiver. Abort! |
@@ -3592,7 +3603,7 @@ MUST_USE_RESULT MaybeHandle<Object> HandleApiCallHelper( |
} |
} |
- return scope.CloseAndEscape(args.receiver()); |
+ return scope.CloseAndEscape(receiver); |
} |
} // namespace |