Restrictions for Napi::String references #4752
Replies: 0 comments 3 replies
-
While it's not very clear from the node-addon-api docs, here's a quote from a section of the Node-API docs "Node-API provides methods for creating persistent references to values. Currently Node-API only allows references to be created for a limited set of value types, including object, external, function, and symbol." As far as why this isn't yet supported, I'm not sure 🤷🏿♂️. It might be fun to look into though! I'd be open to following up on an issue w/ you if you're interested. |
Beta Was this translation helpful? Give feedback.
-
References started as a way to be able to keep alive Objects (and types that are subclasses of Objects) that can be collected by the Garbage collector. Strings are a primitive type and therefore were not included in what could be supported, possibly because References depend on actions/callbacks available for Objects, I've have to look at the code to be more specific.. As mentioned there has been some discussion about creating some APIs with difference semantics, but it has not been completed yet. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there,
I hope you're doing well. I've come across an issue while attempting to create a weak reference for an Napi::String as shown in the code snippet below:
Unfortunately, this resulted in an napi_invalid_arg exception. After investigating, it appears that the problem originates from the following section of the source code:
I was wondering if you could kindly shed some light on the reason behind the restriction that prevents using a Napi::String to create a Napi::Reference. Alternatively, would it be feasible to consider loosing this restriction and allowing strings to be accepted as well? If this change aligns with the project's goals, I'd be more than willing to work on the Pull Request to implement it.
Am I perhaps overlooking something, and there is an alternative method for creating a reference to a string that I'm not aware of?
Thank you for your time and assistance. Looking forward to your guidance on this matter.
Best regards,
Leonardo Boquillon
Beta Was this translation helpful? Give feedback.
All reactions