Support the primitive type: `JsSymbol`(NEON) as `Symbol`(JS)
I found the lacks to supporting to these primitive types in my working at the https://github.com/neon-bindings/examples/issues/51 :
-
Symbol-> This issue -
BigInt-> #376
Note: Symbol is not a frequently used primitive type. So this issue may have a lower priority. However, this is a necessary task for NEON as a language binding core feature.
As a workaround for first class support, since Symbol is not a primitive, it can be used by accessing it on the global object.
fn symbol(mut cx: FunctionContext) -> JsResult<JsValue> {
let global = cx.global();
let symbol_ctor = global
.get(&mut cx, "Symbol")?
.downcast::<JsFunction>()
.or_throw(&mut cx)?;
let symbol_label = cx.string("MySymbol");
let my_symbol = symbol_ctor.call(&mut cx, global, vec![symbol_label])?;
Ok(my_symbol)
}
Thank you @kjvalencik , your alternative technique is useful for the current implementation level of NEON. 👍
But, I have one disagreement. Symbol is a primitive type. My souce is ECMA-262 and MDN. And supplementary Node.js N-API docs:
- ECMA-262 "§4.2 ECMAScript Overview", "§19.4 Symbol Objects"
- MDN "Primitive" https://developer.mozilla.org/en-US/docs/Glossary/Primitive
- Node.js N-API "napi_create_symbol" and etc. https://nodejs.org/api/n-api.html#n_api_napi_create_symbol
I think, JsSymbol supporting is good things for a API structure unifying and completeness. Of cource, I wrote "So this issue may have a lower priority" in the previous note. However, it should be at least including in the implementation plan even if the priority is actually very low.

I stand corrected, that Symbol is a primitive type. That's good to know! Also, I didn't mean to indicate that this shouldn't be done, I only wanted to provide a workaround in the feature's absence.