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

NAPI-RS throwing Nul Error while dealing with virtual modules #1115

Open
hyf0 opened this issue May 13, 2024 · 1 comment
Open

NAPI-RS throwing Nul Error while dealing with virtual modules #1115

hyf0 opened this issue May 13, 2024 · 1 comment

Comments

@hyf0
Copy link
Member

hyf0 commented May 13, 2024

refs:

// FIXME: NAPI-RS used CStr under the hood, so it can't handle null byte in the string.
if !module_path.starts_with('\0') {
rendered_modules.insert(module_path, rendered_module);

@hyf0
Copy link
Member Author

hyf0 commented May 14, 2024

This is due to the limitation of node-api. napi_set_named_property and ``napi_set_named_propertyconsider\0` as terminator rather values.

To solve the problem, we first use the workaround:

  • Convert the String to a custom string type that implements ToNapiValue trait and convert the String to JsString under the hood.

This way would cause a extra napi call for creating JsString.

The best practice is to make node-api napi_set_named_property and napi_set_named_property support passing string with length to treat \0 as values instead of terminator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant