You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to implement custom inspect into ObjectWrap class? #919
But this doesn't get called by console.log(). It makes sense because it needs to be a public symbol, but how do I register a method for a public symbol? Here is no Napi::Symbol::For().
Have you tried Napi::Symbol::WellKnown? Otherwise, you could either pass the JavaScript value of Symbol.for(...) to your addon so it can be used, or you can grab it from global, something like:
auto Symbol = env.Global().Get("Symbol").As<Object>();
auto inspectSym = Symbol.Get("for").As<Function>().Call(Symbol, { Napi::String::New(env, "nodejs.util.inspect.custom") });
As discussed in the Node-API meeting, the implementation for Symbol::WellKnown is correct: it is used to retrieve values like Symbol.toStringTag, which is a direct property on Symbol.
Activity
KevinEady commentedon Mar 3, 2021
Have you tried
Napi::Symbol::WellKnown? Otherwise, you could either pass the JavaScript value ofSymbol.for(...)to your addon so it can be used, or you can grab it from global, something like:ThomasWeinert commentedon Mar 3, 2021
Napi::Symbol::WellKnown(env, "nodejs.util.inspect.custom")returnsNapi::Env::Undefined().Fetching it from JS works. I put that into a utility function:
And then
Thank you.
gabrielschulhof commentedon Mar 5, 2021
@KevinEady is it a problem with
Napi::Symbol::WellKnownthat it returnsundefinedin this case?KevinEady commentedon Mar 26, 2021
@gabrielschulhof hmmm... the implementation for WellKnown is:
node-addon-api/napi-inl.h
Lines 996 to 998 in 8ef0725
This is the equivalent of:
Which is different than
Is the
WellKnownimplementation incorrect?KevinEady commentedon Apr 16, 2021
As discussed in the Node-API meeting, the implementation for
Symbol::WellKnownis correct: it is used to retrieve values likeSymbol.toStringTag, which is a direct property onSymbol.Closing issue.