Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
legendecas opened this issue Jun 23, 2021 · 1 comment
Closed

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

legendecas opened this issue Jun 23, 2021 · 1 comment
Labels
node-api Issues and PRs related to the Node-API.

Comments

@legendecas
Copy link
Member

legendecas commented Jun 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

No branches or pull requests

2 participants