n-api: Sync with back-compat changes
Background: To enable N-API support for node versions back to v4, the N-API code can also be built as an external addon. To make maintenance easier, a single codebase needs to support both built-in and external scenarios, along with Node versions >= 4 (and corresponding V8 versions).
This change includes several minor fixes to avoid using node internal APIs and support older V8 versions:
- Expand
node::arraysize()
- In the
CHECK_ENV()
macro, return an error code instead ofcalling node::FatalError()
. This is more consistent with how other invalid arguments to N-API functions are handled. - In
v8impl::SetterCallbackWrapper::SetReturnValue()
, do nothing instead of callingnode::FatalError()
. This is more consistent with JavaScript setter callbacks, where any returned value is silently ignored. - When queueing async work items, get the uv default loop instead of getting the loop from
node::Environment::GetCurrent()
. Currently that returns the same loop anyway. If/when node supports multiple environments, it should have a public API for getting the environment & event loop, and we can update this implementation then. - Use
v8::Maybe::FromJust()
instead of the newer aliasToChecked()
These changes were copied directly from https://github.com/nodejs/node-api/commit/c7d4df47b786add74a54e203f068723f8f25c8cc where they were reviewed as part of https://github.com/nodejs/node-api/pull/25
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines
Affected core subsystem(s)
n-api