diff --git a/src/node_external_reference.h b/src/node_external_reference.h index b1b6ca31766326..f35376a623a811 100644 --- a/src/node_external_reference.h +++ b/src/node_external_reference.h @@ -13,6 +13,7 @@ namespace node { using CFunctionCallbackWithOneByteString = uint32_t (*)(v8::Local, const v8::FastOneByteString&); using CFunctionCallback = void (*)(v8::Local receiver); +using CFunctionCallbackReturnVoid = void (*)(v8::Local receiver); using CFunctionCallbackReturnDouble = double (*)(v8::Local receiver); using CFunctionCallbackValueReturnDouble = @@ -39,6 +40,7 @@ class ExternalReferenceRegistry { #define ALLOWED_EXTERNAL_REFERENCE_TYPES(V) \ V(CFunctionCallback) \ V(CFunctionCallbackWithOneByteString) \ + V(CFunctionCallbackReturnVoid) \ V(CFunctionCallbackReturnDouble) \ V(CFunctionCallbackValueReturnDouble) \ V(CFunctionCallbackWithInt64) \ diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index 0a5aba6e31fa79..07ebc5b1d06123 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -13,6 +13,7 @@ namespace node { using errors::TryCatchScope; +using v8::CFunction; using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; @@ -142,6 +143,13 @@ static void RunMicrotasks(const FunctionCallbackInfo& args) { env->context()->GetMicrotaskQueue()->PerformCheckpoint(env->isolate()); } +static void FastRunMicrotasks(Local recv) { + Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked()); + env->context()->GetMicrotaskQueue()->PerformCheckpoint(env->isolate()); +} + +static CFunction fast_run_microtasks_(CFunction::Make(FastRunMicrotasks)); + static void SetTickCallback(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); CHECK(args[0]->IsFunction()); @@ -165,7 +173,8 @@ static void Initialize(Local target, SetMethod(context, target, "enqueueMicrotask", EnqueueMicrotask); SetMethod(context, target, "setTickCallback", SetTickCallback); - SetMethod(context, target, "runMicrotasks", RunMicrotasks); + SetFastMethod( + context, target, "runMicrotasks", RunMicrotasks, &fast_run_microtasks_); target->Set(env->context(), FIXED_ONE_BYTE_STRING(isolate, "tickInfo"), env->tick_info()->fields().GetJSArray()).Check(); @@ -187,6 +196,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(EnqueueMicrotask); registry->Register(SetTickCallback); registry->Register(RunMicrotasks); + registry->Register(FastRunMicrotasks); + registry->Register(fast_run_microtasks_.GetTypeInfo()); registry->Register(SetPromiseRejectCallback); }