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]: New variant napi_set_named_property that treats '\0' as values. #52979
I'm developing rolldown, rust version of rollup. Rollup use \0 as the virtual module name convention.
If your plugin uses 'virtual modules' (e.g. for helper functions), prefix the module ID with \0. This prevents other plugins from trying to process it. link
Rolldown follows this convention and got problems while using napi_set_named_property. napi_set_named_property considers \0 as the terminator rather than values. This makes passing "\0mvirtual-module" to Node using napi_set_named_property become "".
What is the feature you are proposing to solve the problem?
So I propose a new variant napi_set_named_property, maybe call ``napi_set_named_property_len`, which will receive string and the length. This way, it could treat '\0' as values.
For alignment, If this request is accepted, I guess napi_get_named_property need a new variant too.
What alternatives have you considered?
I'm using workaround said in rolldown/rolldown#1115 (comment). Create JsString first, then using napi_set_property. But this cause extra napi calls and it's really not good for a bundler that address speed.
If the property keys are definite, creating property keys with node_api_create_property_key_utf16 beforehand and reuse the created keys in napi_set_property could helps.
If the property keys are definite, creating property keys with node_api_create_property_key_utf16 beforehand and reuse the created keys in napi_set_property could helps.
Thanks for the solution. I'm using the workaround like it, but still there is an extra napi call of node_api_create_property_key_utf16.
Closing issue, as #52984 has landed, adding node_api_create_property_key_utf8 and node_api_create_property_key_latin1. These functions (as well as the existing node_api_create_property_key_utf16) give the developer the ability to pass in a size_t length of the string and bypass using \0 as terminator for deciding string length.
Activity
legendecas commentedon May 14, 2024
If the property keys are definite, creating property keys with
node_api_create_property_key_utf16beforehand and reuse the created keys innapi_set_propertycould helps.hyfdev commentedon May 14, 2024
Thanks for the solution. I'm using the workaround like it, but still there is an extra napi call of
node_api_create_property_key_utf16.mertcanaltin commentedon May 14, 2024
I tried to make a quick improvement for this place @hyf0 @legendecas
KevinEady commentedon Oct 13, 2024
Closing issue, as #52984 has landed, adding
node_api_create_property_key_utf8andnode_api_create_property_key_latin1. These functions (as well as the existingnode_api_create_property_key_utf16) give the developer the ability to pass in asize_t lengthof the string and bypass using\0as terminator for deciding string length.