-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
n-api: Enable scope and ref APIs during exception #12524
Conversation
@mhdawson @gabrielschulhof please review. |
src/node_api.cc
Outdated
CHECK_ARG(env, result); | ||
|
||
v8impl::Reference* reference = v8impl::Reference::New( | ||
env, v8impl::V8LocalValueFromJsValue(value), initial_refcount, false); | ||
|
||
*result = reinterpret_cast<napi_ref>(reference); | ||
return GET_RETURN_STATUS(env); | ||
return napi_ok; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAPI_PREAMBLE(env)
clears the last error, whereas CHECK_ENV(env)
does not. So, the public APIs which do not start with NAPI_PREAMBLE(env)
leave the last error status as it was if they simply return napi_ok
. Thus, I was thinking we should change napi_clear_last_error(env)
to always return napi_ok
and then change all these return napi_ok;
statements to return napi_clear_last_error(env);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to discuss what to do about clearing the last error in APIs which do not start with NAPI_PREAMBLE(env)
, but basically LGTM, because it may be good for the result of that discussion to be applied as a pass over the entire API, rather than piecemeal.
... and also LGTM because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This will need to be merged with #12539. It might be better to let that one go first, then I can rebase and update this PR to use the new patterns from that one. |
Ok, I'll wait and land the other one first. |
N-API is somewhat strict about blocking calls to many APIs while there is a pending exception. The NAPI_PREAMBLE macro at the beginning of many API implementations checks for a pending exception. However, a subset of the APIs (which don't call back into JavaScript) still need to work while in a pending-exception state. This changes the reference APIs (equivalent to v8::Persistent) and handle scope APIs so that they can be used for cleanup up while an exception is pending. We may decide to similarly enable a few other APIs later, (which would be a non-breaking change) but we know at least these are needed now to unblock some specific scenarios. Fixes: nodejs/abi-stable-node#122
a8c4e43
to
9956faa
Compare
Rebased, and added a commit to conform to the updated pattern in #12539 where we return |
Oh, this also fixes nodejs/abi-stable-node#228 |
Landed in b7a341d and added the extra Fixes: tag, thanks! |
N-API is somewhat strict about blocking calls to many APIs while there is a pending exception. The NAPI_PREAMBLE macro at the beginning of many API implementations checks for a pending exception. However, a subset of the APIs (which don't call back into JavaScript) still need to work while in a pending-exception state. This changes the reference APIs (equivalent to v8::Persistent) and handle scope APIs so that they can be used for cleanup up while an exception is pending. We may decide to similarly enable a few other APIs later, (which would be a non-breaking change) but we know at least these are needed now to unblock some specific scenarios. Fixes: nodejs/abi-stable-node#122 Fixes: nodejs/abi-stable-node#228 PR-URL: #12524 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
N-API is somewhat strict about blocking calls to many APIs while there is a pending exception. The NAPI_PREAMBLE macro at the beginning of many API implementations checks for a pending exception. However, a subset of the APIs (which don't call back into JavaScript) still need to work while in a pending-exception state. This changes the reference APIs (equivalent to v8::Persistent) and handle scope APIs so that they can be used for cleanup up while an exception is pending. We may decide to similarly enable a few other APIs later, (which would be a non-breaking change) but we know at least these are needed now to unblock some specific scenarios. Fixes: nodejs/abi-stable-node#122 Fixes: nodejs/abi-stable-node#228 PR-URL: nodejs#12524 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
N-API is somewhat strict about blocking calls to many APIs while there is a pending exception. The NAPI_PREAMBLE macro at the beginning of many API implementations checks for a pending exception. However, a subset of the APIs (which don't call back into JavaScript) still need to work while in a pending-exception state. This changes the reference APIs (equivalent to v8::Persistent) and handle scope APIs so that they can be used for cleanup up while an exception is pending. We may decide to similarly enable a few other APIs later, (which would be a non-breaking change) but we know at least these are needed now to unblock some specific scenarios. Fixes: nodejs/abi-stable-node#122 Fixes: nodejs/abi-stable-node#228 Backport-PR-URL: #19447 PR-URL: #12524 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]>
N-API is somewhat strict about blocking calls to many APIs while there is a pending exception. The
NAPI_PREAMBLE
macro at the beginning of many API implementations checks for a pending exception. However, a subset of the APIs (which don't call back into JavaScript) still need to work while in a pending-exception state. This changes the reference APIs (equivalent tov8::Persistent
) and handle scope APIs so that they can be used for cleanup up while an exception is pending.We may decide to similarly enable a few other APIs later, (which would be a non-breaking change) but we know at least these are needed now to unblock some specific scenarios.
There currently isn't good test coverage of the reference APIs; I'm working on that separately. This change only adds a handle scope test case.
Also fixing a couple places where I noticed the argument validation was incorrect.
Fixes: nodejs/abi-stable-node#122
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)