You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
node-api: allow symbol values as reference target #39131
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
gabrielschulhof commentedon Dec 17, 2021
This feature landed in #39926 on commit 33b5107.