-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node::MakeCallback()
, napi_make_callback()
requires recv to be an object / not empty
#26342
Comments
That restriction cannot be lifted unconditionally because e.g. domain callbacks (as in: If we end up with something where it's technically possible to omit the receiver but practically speaking it's not, then we might as well leave well enough alone. |
Thanks for the reply! The workaround I'm using now is (trimmed for readability): napi_value context_object, recv;
napi_create_object(env, &context_object);
napi_get_undefined(env, &recv);
napi_open_callback_scope(env, context_object, async_context, &callback_scope);
napi_call_function(env, recv, func, ...); Which seems to work fine, as the context object is decoupled from the receiver. I don't really understand why the context object exists, or how domains affect this, is this dumb and wrong? |
@simonbuchan The tl;dr is: It’s not currently used in See e.g. #21313 for a previous attempt at moving into this direction – I don’t know if @mcollina is still interested in changing the async_hooks API to address this? |
Hmm, If I understand what you mean, @addaleax this would mean the If that's intended, I would have expected node to be stashing the I don't currently have a meaningful "context" instance, but it seems a simple |
ping @nodejs/n-api @nodejs/addon-api ... is there anything actionable here? |
I don't think any changes are planned. |
I'm closing this since there has been no follow up questions since my comment over a year ago. Please let us know if you think that was not the right thing to do. |
napi_make_callback()
, likenapi_call_function()
, takes arecv
value to be used asthis
in JS. Unlikenapi_call_function()
, however, it validates that the value is of v8 type object, meaning that you can't pass not onlyNULL
, but also explicit JSundefined
,global
or many other valid(ish) JSthis
values.The immediate error on the N-API side looks like it was in from the start in ba7bac5 where a lot of null checking was added: note that
napi_call_function()
gets lots of checks added, butrecv
is directly passed through to v8.I thought this was a bit strange, so I dug in a bit further to see if it was a requirement for
node::MakeCallback
, and it seems since #14697 the underlyingnode::MakeCallback()
andnode::CallbackScope()
now also requiresrecv
to not be empty withCHECK(!recv.IsEmpty())
on the line https://github.com/nodejs/node/pull/14697/files#diff-cd53544f44aab2c697bcd7b6a57f23ccR1398 despite the previous code taking care to handle it being null (when not using domains, at least), and the new code not requiring the value as far as I could tell?Am I missing something obvious?
The text was updated successfully, but these errors were encountered: