Index: src/builtins.cc |
diff --git a/src/builtins.cc b/src/builtins.cc |
index 347b428d5c250d00d8d3f3f096fdb84d42926536..6e5c66bc9e6ddbcc1b224a45be1077256ff5bea4 100644 |
--- a/src/builtins.cc |
+++ b/src/builtins.cc |
@@ -4362,6 +4362,20 @@ MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function, |
Handle<Object> receiver, |
int argc, |
Handle<Object> args[]) { |
+ Isolate* isolate = function->GetIsolate(); |
+ // Do proper receiver conversion for non-strict mode api functions. |
+ if (!receiver->IsJSReceiver()) { |
+ DCHECK(function->IsFunctionTemplateInfo() || function->IsJSFunction()); |
+ if (function->IsFunctionTemplateInfo() || |
+ is_sloppy(JSFunction::cast(*function)->shared()->language_mode())) { |
+ if (receiver->IsUndefined() || receiver->IsNull()) { |
+ receiver = handle(isolate->global_proxy(), isolate); |
+ } else { |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, |
+ Object::ToObject(isolate, receiver), Object); |
+ } |
+ } |
+ } |
// Construct BuiltinArguments object: function, arguments reversed, receiver. |
const int kBufferSize = 32; |
Object* small_argv[kBufferSize]; |
@@ -4378,7 +4392,6 @@ MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function, |
argv[0] = *function; |
MaybeHandle<Object> result; |
{ |
- auto isolate = function->GetIsolate(); |
RelocatableArguments arguments(isolate, argc + 2, &argv[argc + 1]); |
result = HandleApiCallHelper<false>(isolate, arguments); |
} |