-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Description
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 symbol
s, 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.