Skip to content

[node-api]: New variant napi_set_named_property that treats '\0' as values. #52979

@hyf0

Description

@hyf0

What is the problem this feature will solve?

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 "".

Related issues:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.node-apiIssues and PRs related to the Node-API.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions