diff options
author | Anna Henningsen <anna@addaleax.net> | 2017-09-09 22:28:02 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-05-10 14:15:16 +0200 |
commit | 5c6cf30143f3191b043ba0b4e814768efa1069f7 (patch) | |
tree | 630c9aed6f50ee77ebdca48293d16155b36c0d86 /src/node_api.cc | |
parent | 560925fe22bfc23860b04704ff4cae21e4dd19ff (diff) | |
download | android-node-v8-5c6cf30143f3191b043ba0b4e814768efa1069f7.tar.gz android-node-v8-5c6cf30143f3191b043ba0b4e814768efa1069f7.tar.bz2 android-node-v8-5c6cf30143f3191b043ba0b4e814768efa1069f7.zip |
src: add environment cleanup hooks
This adds pairs of methods to the `Environment` class and to public APIs
which can add and remove cleanup handlers.
Unlike `AtExit`, this API targets addon developers rather than
embedders, giving them (and Node’s internals) the ability to register
per-`Environment` cleanup work.
We may want to replace `AtExit` with this API at some point.
Many thanks for Stephen Belanger for reviewing the original version of
this commit in the Ayo.js project.
Refs: https://github.com/ayojs/ayo/pull/82
PR-URL: https://github.com/nodejs/node/pull/19377
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r-- | src/node_api.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/node_api.cc b/src/node_api.cc index 4878cf241e..d5437d70d9 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -902,6 +902,28 @@ void napi_module_register(napi_module* mod) { node::node_module_register(nm); } +napi_status napi_add_env_cleanup_hook(napi_env env, + void (*fun)(void* arg), + void* arg) { + CHECK_ENV(env); + CHECK_ARG(env, fun); + + node::AddEnvironmentCleanupHook(env->isolate, fun, arg); + + return napi_ok; +} + +napi_status napi_remove_env_cleanup_hook(napi_env env, + void (*fun)(void* arg), + void* arg) { + CHECK_ENV(env); + CHECK_ARG(env, fun); + + node::RemoveEnvironmentCleanupHook(env->isolate, fun, arg); + + return napi_ok; +} + // Warning: Keep in-sync with napi_status enum static const char* error_messages[] = {nullptr, |