Skip to content

Retrieve the finalizer for an object #311

@gabrielschulhof

Description

@gabrielschulhof

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions