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
Add module initializer with context corresponding to NODE_MODULE_INITIALIZER #844
Node 10 added Context-aware addons, using the NODE_MODULE_INITIALIZER. To be able to make such an addon with compatibility with older versions we need a corresponding macro in nan.
That does look relevant, but it looks like it just ignores the context parameter, instead of providing some kind of shim or fallback. So, it looks like it doesn't help with actually writing an addon that is context-aware in Node 10+.
@NickNaso are there any plans to resolve this issue or is there anything I could contribute?
This one is currently blocking grpc/grpc-node#778 which in turn is causing other trouble further down stream (vercel/next.js#7894) so I would be interested in getting this resolved.
According to electron/electron#18397, as of Electron 11 this will be required to load all native addons in Electron. Therefore, changing this should be a priority.
That applies to the version range we are interested in, and it discards the context parameter instead of passing it to the registration function. This macro appears to correspond to the NODE_MODULE_INIT macro described in the Context-aware addons documentation, and that documentation states that the context variable is available in the function body passed to that macro. Based on this information, it seems like NAN_MODULE_WORKER_ENABLED does not facilitate the creation of a context-aware addon the way NODE_MODULE_INIT does.
Honestly, I was unaware of Nan::GetCurrentContext() and nobody mentioned it in this issue before, and the documentation doesn't clearly indicate that it can be used in that function as a replacement for the context variable.
I don't know what the right change here is. I'm just a user of this library; that doesn't mean I'm knowledgeable about the nuances of the Node API or its changes across versions.
In particular, you say that Nan::GetCurrentContext() can access the current context in the module initializer. If that is the case, why does Node's API also pass it in as an argument to the initializer? I think someone who knows the answer to that question is in a better position to determine what change should be made here.
Activity
NickNaso commentedon Mar 27, 2019
Hi @murgatroid99,
I think that
NAN_MODULE_WORKER_ENALBEDis the macro that you need. https://github.com/nodejs/nan/blob/master/nan.h#L158Can someone say if I'm right or not?
murgatroid99 commentedon Mar 27, 2019
That does look relevant, but it looks like it just ignores the
contextparameter, instead of providing some kind of shim or fallback. So, it looks like it doesn't help with actually writing an addon that is context-aware in Node 10+.ctavan commentedon Oct 25, 2019
@NickNaso are there any plans to resolve this issue or is there anything I could contribute?
This one is currently blocking grpc/grpc-node#778 which in turn is causing other trouble further down stream (vercel/next.js#7894) so I would be interested in getting this resolved.
murgatroid99 commentedon Aug 4, 2020
According to electron/electron#18397, as of Electron 11 this will be required to load all native addons in Electron. Therefore, changing this should be a priority.
bnoordhuis commentedon Aug 5, 2020
What should that shim/fallback do in your opinion? Add-ons can already obtain the context in their initializer with
Nan::GetCurrentContext().murgatroid99 commentedon Aug 5, 2020
Look, you have this definition:
That applies to the version range we are interested in, and it discards the
contextparameter instead of passing it to theregistrationfunction. This macro appears to correspond to theNODE_MODULE_INITmacro described in the Context-aware addons documentation, and that documentation states that thecontextvariable is available in the function body passed to that macro. Based on this information, it seems likeNAN_MODULE_WORKER_ENABLEDdoes not facilitate the creation of a context-aware addon the wayNODE_MODULE_INITdoes.Honestly, I was unaware of
Nan::GetCurrentContext()and nobody mentioned it in this issue before, and the documentation doesn't clearly indicate that it can be used in that function as a replacement for thecontextvariable.bnoordhuis commentedon Aug 6, 2020
@murgatroid99 Do you want to update the API or the docs? In both cases a pull request is the best way forward. :-)
murgatroid99 commentedon Aug 6, 2020
I don't know what the right change here is. I'm just a user of this library; that doesn't mean I'm knowledgeable about the nuances of the Node API or its changes across versions.
In particular, you say that
Nan::GetCurrentContext()can access the current context in the module initializer. If that is the case, why does Node's API also pass it in as an argument to the initializer? I think someone who knows the answer to that question is in a better position to determine what change should be made here.bnoordhuis commentedon Aug 9, 2020
As the one who introduced the original multi-context support in Node: because it seemed like a good idea at the time. :-)