n-api: Enable scope and ref APIs during exception
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.
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: https://github.com/nodejs/abi-stable-node/issues/122
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines