| Index: src/execution.cc
|
| diff --git a/src/execution.cc b/src/execution.cc
|
| index 4ec18f87353255809d8545ec8ecee22e7e60dc2a..f4c48740db764fc70878df43437a15bdfce4bd83 100644
|
| --- a/src/execution.cc
|
| +++ b/src/execution.cc
|
| @@ -72,6 +72,30 @@ MUST_USE_RESULT MaybeHandle<Object> Invoke(Isolate* isolate, bool is_construct,
|
| }
|
| #endif
|
|
|
| + // api callbacks can be called directly.
|
| + if (target->IsJSFunction()) {
|
| + Handle<JSFunction> function = Handle<JSFunction>::cast(target);
|
| + if ((!is_construct || function->IsConstructor()) &&
|
| + function->shared()->IsApiFunction()) {
|
| + SaveContext save(isolate);
|
| + isolate->set_context(function->context());
|
| + DCHECK(function->context()->global_object()->IsJSGlobalObject());
|
| + if (is_construct) receiver = isolate->factory()->the_hole_value();
|
| + auto value = Builtins::InvokeApiFunction(
|
| + isolate, is_construct, function, receiver, argc, args,
|
| + Handle<HeapObject>::cast(new_target));
|
| + 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));
|
| @@ -145,26 +169,6 @@ MaybeHandle<Object> Execution::Call(Isolate* isolate, Handle<Object> callable,
|
| 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());
|
| - DCHECK(function->context()->global_object()->IsJSGlobalObject());
|
| - auto value =
|
| - Builtins::InvokeApiFunction(isolate, 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());
|
| }
|
|
|