Skip to content

node-api: allow symbol values as reference target #39131

Description

@legendecas

Is your feature request related to a problem? Please describe.
napi_create_reference puts a constraint on the value type that the reference can be created on. Currently only object or function (non-primitive types) are allowed. This should be okay-ish in most cases for undefined, null, boolean, string, number, and bigint, we can convert those primitive values to a native representative to keep a "reference" to their values. But this is not the case for symbols, as they are unique values and there is no means to convert them to native values. As such, we can not prevent the symbol values to be GC'ed on the native side.

Describe the solution you'd like
There is a TC39 stage 2 proposal Symbols as WeakMap keys that intends to loosen the constraint on WeakMap keys to allow symbol values. The goal of WeakMap is to have unique values that can be eventually GC'ed. Similarly, the values to be referenced in napi_create_reference have to be unique values and can be eventually GC'ed. Allowing symbols in this case will be helpful to managing those unique values on the native side.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    node-apiIssues and PRs related to Node-API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions