-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
[Node-API] Symbol.toStringTag support #41358
Copy link
Copy link
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.node-apiIssues and PRs related to the Node-API.Issues and PRs related to the Node-API.
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.node-apiIssues and PRs related to the Node-API.Issues and PRs related to the Node-API.
Type
Fields
Give feedbackNo fields configured for issues without a type.
What is the problem this feature will solve?
Using Node-API, I would like my C/C++ addon to generate a JavaScript object decorated with a tag name, like this:
So I can get:

I believe this is not possible to set the
Symbol.toStringTagproperty to an object created with the current Node-API.What is the feature you are proposing to solve the problem?
I guess we need access to the global
Symbol.toStringTagand other well-known Symbols defined in JavaScript.Below is the Node.js example to create a new Symbol and set it as a property for an object (along other properties):
node/test/js-native-api/test_properties/test_properties.c
Lines 72 to 96 in e46c680
Instead of creating a new Symbol we would have to use the existing
Symbol.toStringTag.Maybe you could consider to have a method like
napi_get_symbol_tostringtag(env, &name_symbol)to replacenapi_create_symbol(..used on line 78.What alternatives have you considered?
Explored the Node-API but I have no clue for a workaround in the C/C++ code.
For a root object returned by the add-on, one may use the add-on
main.jsfile to add the property dynamically in JavaScript before the export, but it's not pretty.