Description
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:
const obj = {
name: "john",
[Symbol.toStringTag]: "MyTag"
};
I believe this is not possible to set the Symbol.toStringTag
property 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.toStringTag
and 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 replace napi_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.js
file to add the property dynamically in JavaScript before the export, but it's not pretty.