Conversation
4ee44c1 to
42968bc
Compare
|
Hi team. This is ready for review. I have fixed the API privatization, see https://github.com/nodejs/node-addon-api/pull/1014/files#diff-6294f8ee1d8cd7e4e94cfc22a083380fb80058e34f53100d895b9b3b295dd801
|
|
|
||
| template <typename Hook, typename Arg> | ||
| CleanupHook<Hook, Arg> AddCleanupHook(Hook hook, Arg* arg); | ||
|
|
There was a problem hiding this comment.
I think these need to be guarded by NAPI_VERSION > 3 as the cleanup hooks were only added in version 3 as per: https://nodejs.org/api/n-api.html#n_api_napi_add_env_cleanup_hook
There was a problem hiding this comment.
I thought about this, but we dropped support for node 8, and Node-API version is present in 10+. Do we still need a guard?
There was a problem hiding this comment.
I think so, people can still ask for a particular Node-API version and I think we should respect that.
There was a problem hiding this comment.
Note I did not add guards to the tests -- we will always test Node-API 3+ right?
There was a problem hiding this comment.
In terms of guarding the tests its only a 1 line addition here:
Line 84 in 6697c51
There was a problem hiding this comment.
Thinking more I guess there is more to it than that. You also need to guard the compilation but that is pretty easy too. Unlikely anybody will test with napiVersion <3 but for consistency I'd still prefer if we guard since it's not a lot of effort.
| : wrapper(Env::CleanupHook<Hook, Arg>::Wrapper) { | ||
| data = new CleanupData{std::move(hook), nullptr}; | ||
| napi_status status = napi_add_env_cleanup_hook(env, wrapper, data); | ||
| NAPI_FATAL_IF_FAILED(status, |
There was a problem hiding this comment.
What would cause napi_add_env_cleanup_hook to fail ? I'm wondering if we can let the caller trying add a hook know it failed versus causing a FATAL error.
There was a problem hiding this comment.
Looking at the implementation, it looks like it should always return napi_ok ... https://github.com/nodejs/node/blob/663d7e9fb27f017f38b79382a95fec10e5f66f9a/src/node_api.cc#L656-L676
According to the docs it can just abort the process with invalid arguments:
Providing the same fun and arg values multiple times is not allowed and will lead the process to abort.
But we would never provide the same arg value (as we always create a new CallbackData)
Maybe we don't need the check at all...? However napi_add_env_cleanup_hook always returning napi_ok is an implementation detail, maybe we should keep it blackboxed 🤷
How would you recommend "add a hook know it failed" ...?
Thanks, Kevin
There was a problem hiding this comment.
How would you recommend "add a hook know it failed" . What I had in mind was some kind of return value the caller could check. For example if it was documented that the callers should check that the result from AddCleanupHook was non-null would that make any sense?
- add `NAPI_VERSION` guard - add `IsEmpty`
36f13d3 to
36ef600
Compare
| template <typename Hook, typename Arg> | ||
| Env::CleanupHook<Hook, Arg>::CleanupHook(Napi::Env env, Hook hook) | ||
| : wrapper(Env::CleanupHook<Hook, Arg>::Wrapper) { | ||
| data = new CleanupData{std::move(hook), nullptr}; |
There was a problem hiding this comment.
Could this version just call the other one and pass nullptr for data ?
There was a problem hiding this comment.
@mhdawson no because each constructor initializes the instance member wrapper to a different value, Env::CleanupHook<Hook, Arg>::Wrapper (this one) or Env::CleanupHook<Hook, Arg>::WrapperWithArg
Add CleanupHook support to Env PR-URL: #1014 Reviewed-By: Michael Dawson <midawson@redhat.com>
|
Landed as 10564a4 |
Add CleanupHook support to Env PR-URL: nodejs#1014 Reviewed-By: Michael Dawson <midawson@redhat.com>
Add CleanupHook support to Env PR-URL: nodejs#1014 Reviewed-By: Michael Dawson <midawson@redhat.com>
Add CleanupHook support to Env PR-URL: nodejs/node-addon-api#1014 Reviewed-By: Michael Dawson <midawson@redhat.com>
Add CleanupHook support to Env PR-URL: nodejs/node-addon-api#1014 Reviewed-By: Michael Dawson <midawson@redhat.com>
Add CleanupHook support to Env PR-URL: nodejs/node-addon-api#1014 Reviewed-By: Michael Dawson <midawson@redhat.com>
Add CleanupHook support to Env PR-URL: nodejs/node-addon-api#1014 Reviewed-By: Michael Dawson <midawson@redhat.com>
Adds wrapping for
napi_add_env_cleanup_hookandnapi_remove_env_cleanup_hook.