diff --git a/src/api/hooks.cc b/src/api/hooks.cc index f3f685b167f3cd..514706d4c87c30 100644 --- a/src/api/hooks.cc +++ b/src/api/hooks.cc @@ -145,7 +145,7 @@ static void RunAsyncCleanupHook(void* arg) { info->fun(info->arg, FinishAsyncCleanupHook, info); } -AsyncCleanupHookHandle AddEnvironmentCleanupHook( +ACHHandle* AddEnvironmentCleanupHookRaw( Isolate* isolate, AsyncCleanupHook fun, void* arg) { @@ -157,11 +157,11 @@ AsyncCleanupHookHandle AddEnvironmentCleanupHook( info->arg = arg; info->self = info; env->AddCleanupHook(RunAsyncCleanupHook, info.get()); - return AsyncCleanupHookHandle(new ACHHandle { info }); + return new ACHHandle { info }; } -void RemoveEnvironmentCleanupHook( - AsyncCleanupHookHandle handle) { +void RemoveEnvironmentCleanupHookRaw( + ACHHandle* handle) { if (handle->info->started) return; handle->info->self.reset(); handle->info->env->RemoveCleanupHook(RunAsyncCleanupHook, handle->info.get()); diff --git a/src/node.h b/src/node.h index 5313f49e0bc2c0..74d22b25f03510 100644 --- a/src/node.h +++ b/src/node.h @@ -925,12 +925,22 @@ struct ACHHandle; struct NODE_EXTERN DeleteACHHandle { void operator()(ACHHandle*) const; }; typedef std::unique_ptr AsyncCleanupHookHandle; -NODE_EXTERN AsyncCleanupHookHandle AddEnvironmentCleanupHook( +NODE_EXTERN ACHHandle* AddEnvironmentCleanupHookRaw( v8::Isolate* isolate, void (*fun)(void* arg, void (*cb)(void*), void* cbarg), void* arg); +inline AsyncCleanupHookHandle AddEnvironmentCleanupHook( + v8::Isolate* isolate, + void (*fun)(void* arg, void (*cb)(void*), void* cbarg), + void* arg) { + return AsyncCleanupHookHandle(AddEnvironmentCleanupHookRaw(isolate, fun, + arg)); +} -NODE_EXTERN void RemoveEnvironmentCleanupHook(AsyncCleanupHookHandle holder); +NODE_EXTERN void RemoveEnvironmentCleanupHookRaw(ACHHandle* holder); +inline void RemoveEnvironmentCleanupHook(AsyncCleanupHookHandle holder) { + RemoveEnvironmentCleanupHookRaw(holder.get()); +} /* Returns the id of the current execution context. If the return value is * zero then no execution has been set. This will happen if the user handles