Index: src/execution.cc |
diff --git a/src/execution.cc b/src/execution.cc |
index 5f24e5e336b373d91d3294d4d9e37e14b367162a..e6a569f33d967d66bdfc0065ef10c7117a3a091a 100644 |
--- a/src/execution.cc |
+++ b/src/execution.cc |
@@ -59,45 +59,6 @@ |
Handle<Object> new_target) { |
DCHECK(!receiver->IsJSGlobalObject()); |
- // API callbacks can be called directly. |
- if (target->IsJSFunction() && |
- Handle<JSFunction>::cast(target)->shared()->IsApiFunction()) { |
- Handle<JSFunction> function = Handle<JSFunction>::cast(target); |
- if (is_construct && !function->IsConstructor()) { |
- THROW_NEW_ERROR(isolate, |
- NewTypeError(MessageTemplate::kNotConstructor, function), |
- Object); |
- } |
- SaveContext save(isolate); |
- isolate->set_context(function->context()); |
- // Do proper receiver conversion for non-strict mode api functions. |
- if (!receiver->IsJSReceiver() && |
- is_sloppy(function->shared()->language_mode())) { |
- if (receiver->IsUndefined() || receiver->IsNull()) { |
- if (is_construct) { |
- receiver = isolate->factory()->the_hole_value(); |
- } else { |
- receiver = handle(function->global_proxy(), isolate); |
- } |
- } else { |
- ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, |
- Object::ToObject(isolate, receiver), Object); |
- } |
- } |
- DCHECK(function->context()->global_object()->IsJSGlobalObject()); |
- auto value = Builtins::InvokeApiFunction(is_construct, function, receiver, |
- argc, args); |
- bool has_exception = value.is_null(); |
- DCHECK(has_exception == isolate->has_pending_exception()); |
- if (has_exception) { |
- isolate->ReportPendingMessages(); |
- return MaybeHandle<Object>(); |
- } else { |
- isolate->clear_pending_message(); |
- } |
- return value; |
- } |
- |
// Entering JavaScript. |
VMState<JS> state(isolate); |
CHECK(AllowJavascriptExecution::IsAllowed(isolate)); |
@@ -169,6 +130,35 @@ |
if (receiver->IsJSGlobalObject()) { |
receiver = |
handle(Handle<JSGlobalObject>::cast(receiver)->global_proxy(), isolate); |
+ } |
+ |
+ // api callbacks can be called directly. |
+ if (callable->IsJSFunction() && |
+ Handle<JSFunction>::cast(callable)->shared()->IsApiFunction()) { |
+ Handle<JSFunction> function = Handle<JSFunction>::cast(callable); |
+ SaveContext save(isolate); |
+ isolate->set_context(function->context()); |
+ // Do proper receiver conversion for non-strict mode api functions. |
+ if (!receiver->IsJSReceiver() && |
+ is_sloppy(function->shared()->language_mode())) { |
+ if (receiver->IsUndefined() || receiver->IsNull()) { |
+ receiver = handle(function->global_proxy(), isolate); |
+ } else { |
+ ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver, |
+ Object::ToObject(isolate, receiver), Object); |
+ } |
+ } |
+ DCHECK(function->context()->global_object()->IsJSGlobalObject()); |
+ auto value = Builtins::InvokeApiFunction(function, receiver, argc, argv); |
+ bool has_exception = value.is_null(); |
+ DCHECK(has_exception == isolate->has_pending_exception()); |
+ if (has_exception) { |
+ isolate->ReportPendingMessages(); |
+ return MaybeHandle<Object>(); |
+ } else { |
+ isolate->clear_pending_message(); |
+ } |
+ return value; |
} |
return Invoke(isolate, false, callable, receiver, argc, argv, |
isolate->factory()->undefined_value()); |