For objects created using N-API, it would help to have a function to get
the finalizer callback for the value, for example:
napi_get_value_finalizer(napi_env env,napi_value val,napi_finalize*result)
This can be used to determine who created an object, by comparing the
finalizer function pointer (which will be a null pointer if there is no
finalizer callback defined) with the address of the native code's own
functions (there is no point calling the returned finalizer callback).
Re: nodejs/node#14256
Such type-checking can also be accomplished by having the wrapped objects be instances of certain JS classes, and then using napi_instanceof() to decide if a given napi_value containing a JavaScript object has the kind of pointer that is expected.
Are there any other use cases where knowing the identity of the finalizer is helpful?
Re: nodejs/node#14256
Such type-checking can also be accomplished by having the wrapped objects be instances of certain JS classes, and then using
napi_instanceof()to decide if a givennapi_valuecontaining a JavaScript object has the kind of pointer that is expected.Are there any other use cases where knowing the identity of the finalizer is helpful?