diff options
author | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2018-08-10 11:43:39 -0400 |
---|---|---|
committer | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2018-09-12 22:37:42 -0400 |
commit | cf0e881b33c841d2f89a23be281e1aaf061a58a3 (patch) | |
tree | fd1ba7df5b6955559bd76eef9c1e276f891201e3 /src/node_api.h | |
parent | 82b752a302f1bb1fb2e82baeabfb8627de0b159f (diff) | |
download | android-node-v8-cf0e881b33c841d2f89a23be281e1aaf061a58a3.tar.gz android-node-v8-cf0e881b33c841d2f89a23be281e1aaf061a58a3.tar.bz2 android-node-v8-cf0e881b33c841d2f89a23be281e1aaf061a58a3.zip |
n-api: add generic finalizer callback
Add `napi_add_finalizer()`, which provides the ability to attach data
to an arbitrary object and be notified when that object is garbage-
collected so as to have an opportunity to delete the data previously
attached.
This differs from `napi_wrap()` in that it does not use up the private
slot on the object, and is therefore neither removable, nor retrievable
after the call to `napi_add_finalizer()`. It is assumed that the data
is accessible by other means, yet it must be tied to the lifetime of
the object. This is the case for data passed to a dynamically created
function which is itself heap-allocated and must therefore be freed
along with the function.
Fixes: https://github.com/nodejs/abi-stable-node/issues/313
PR-URL: https://github.com/nodejs/node/pull/22244
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'src/node_api.h')
-rw-r--r-- | src/node_api.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/node_api.h b/src/node_api.h index 1b2a392a0a..10a2c8ff30 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -695,6 +695,12 @@ NAPI_EXTERN napi_status napi_get_value_bigint_words(napi_env env, int* sign_bit, size_t* word_count, uint64_t* words); +NAPI_EXTERN napi_status napi_add_finalizer(napi_env env, + napi_value js_object, + void* native_object, + napi_finalize finalize_cb, + void* finalize_hint, + napi_ref* result); #endif // NAPI_EXPERIMENTAL EXTERN_C_END |