◐ Shell
clean mode source ↗

Update code to support N-API on older versions of node by jasongin · Pull Request #25 · nodejs/node-addon-api

This was referenced

Apr 17, 2017

gabrielschulhof

addaleax

mhdawson

Copy the latest node_api* source files from the node master branch,
to pick up all the changes from the past few weeks.
Recent changes introduced dependencies on internal node APIs:
 - Environment::GetCurrent()
 - FatalError()
 - arraysize
To enable building this code as an external module, compatible back to Node v4, the internal APIs must be avoided.

Also replace use of v8::Maybe::ToChecked() (available in Node >= 7) with FromJust(), which does excatly the same thing and works in Node v4.

jasongin added a commit to jasongin/nodejs that referenced this pull request

Apr 26, 2017
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 of calling
    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 calling node::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 alias ToChecked()

These changes were copied directly from
nodejs/node-addon-api@c7d4df4
where they were reviewed as part of
nodejs/node-addon-api#25