Skip to content
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

module: add support for abi stable module API #11975

Closed
wants to merge 22 commits into from

Commits on Mar 21, 2017

  1. module: add support for abi stable module API

    Add support for abi stable module API (N-API) as "Experimental feature".
    The goal of this API is to provide a stable Node API for native
    module developers. N-API aims to provide ABI compatibility guarantees
    across different Node versions and also across different
    Node VMs - allowing N-API enabled native modules to just work
    across different versions and flavors of Node.js without recompilation.
    
    A more detailed introduction is provided in:
    https:/nodejs/node-eps/blob/master/005-ABI-Stable-Module-API.md
    and https:/nodejs/abi-stable-node/blob/doc/VM%20Summit.pdf.
    
    The feature, during its experimental state, will be guarded by a runtime
    flag "--napi-modules". Only when this flag is added to the command line
    will N-API modules along with regular non N-API modules be supported.
    
    The API is defined by the methods in "src/node_api.h",
    "src/node_api_types.h" and "src/node_api_async.h". This is the best
    starting point to review the API surface. More documentation will follow.
    
    In addition to the implementation of the API using V8, which is included
    in this PR, the API has also been validated against chakracore and that
    port is available in
    https:/nodejs/abi-stable-node/tree/api-prototype-chakracore-8.x.
    
    The current plan is to provide N-API support in versions 8.X and 6.X
    directly. For older versions, such as 4.X or pre N-API versions of 6.X,
    we plan to create an external npm module to provide a migration path
    that will allow modules targeting older Node.js versions to use the API,
    albeit without getting the advantage of not having to recompile.
    
    In addition, we also plan an external npm package with C++ sugar to
    simplify the use of the API. The sugar will be in-line only and will
    only use the exported N-API methods but is not part of the N-API
    itself. The current version is in:
    https:/nodejs/node-api.
    
    This PR is a result of work in the abi-stable-node repo:
    https:/nodejs/abi-stable-node/tree/doc,
    with this PR being the cumulative work on the api-prototype-8.x
    branch with the following contributors in alphabetical order:
    
     Arunesh Chandra (@aruneshchandra)
     Gabriel Schulhof (@gabrielschulhof)
     Hitesh Kanwathirtha (@digitalinfinity)
     Ian Halliday (@ianwjhalliday)
     Jason Ginchereau (@jasongin)
     Michael Dawson (@mhdawson)
     Sampson Gao (@sampsongao)
     Taylor Woll (@boingoing)
    jasongin committed Mar 21, 2017
    Configuration menu
    Copy the full SHA
    43ab5a8 View commit details
    Browse the repository at this point in the history

Commits on Mar 22, 2017

  1. Fix undefined snprintf use for older compiler

    The snprintf API is not available with older versions of MSVC. Found by a CI run.
    jasongin committed Mar 22, 2017
    Configuration menu
    Copy the full SHA
    a5d43d1 View commit details
    Browse the repository at this point in the history

Commits on Mar 23, 2017

  1. all: update --napi-modules flag to not have a yes/no

    This updates the documentation, the error message upon module load
    failure, the command line option parsing of the flag, and the way
    the N-API addon tests pass the flag to node.
    
    Re nodejs#11975 (comment)
    Re nodejs#11975 (comment)
    Fixes nodejs/abi-stable-node#184
    Closes nodejs/abi-stable-node#186
    Gabriel Schulhof authored and jasongin committed Mar 23, 2017
    Configuration menu
    Copy the full SHA
    87c42e7 View commit details
    Browse the repository at this point in the history
  2. doc: mention experimental status of --napi-modules flag

    Gabriel Schulhof authored and jasongin committed Mar 23, 2017
    Configuration menu
    Copy the full SHA
    876e6c8 View commit details
    Browse the repository at this point in the history
  3. src: improve message regarding N-API experimental status

    Gabriel Schulhof authored and jasongin committed Mar 23, 2017
    Configuration menu
    Copy the full SHA
    b129624 View commit details
    Browse the repository at this point in the history
  4. test: convert most addons-napi tests to C

    Some tests need to stay C++ because they define classes.
    
    Fixes nodejs/abi-stable-node#183
    Closes nodejs/abi-stable-node#190
    Gabriel Schulhof authored and jasongin committed Mar 23, 2017
    Configuration menu
    Copy the full SHA
    66944b8 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    9e3ab83 View commit details
    Browse the repository at this point in the history
  6. Convert all locals and parameter names to snake_case (nodejs#193)

    * Convert all locals and parameter names to snake_case
    
    Standardize some parameter names across the N-API surface such as ```napi_env env``` and ```size_t length```. Make all the parameter names in the header match the cc file and expand some parameter names from single characters into meaningful words.
    
    Also addresses a couple of minor PR feedback items:
     - Rename ```napi_reference_addref``` and ```napi_reference_release``` to ```napi_reference_ref``` and ```napi_reference_unref``` (respectively)
     - Rename ```Reference::AddRef``` and ```Reference::Release``` to ```Reference::Ref``` and ```Reference::Unref``` (respectively)
     - Remove ```napi_create_boolean```, ```napi_get_true```, and ```napi_get_false``` and replace them with ```napi_get_boolean```
     - Rename ```napi_get_type_of_value``` to ```napi_typeof```
     - Add a ```result_data``` out parameter to ```napi_create_buffer_copy``` which returns the data pointer of the new buffer
     - Change ```napi_get_value_string_utf8``` and ```napi_get_value_string_utf16``` to accept a null output buffer and return the length of the source string in that case via the ```result``` parameter
     - Remove ```napi_get_value_string_utf8_length``` and ```napi_get_value_string_utf16_length``` due to the above
     - Change ```Reference``` ctor and dtor to be protected and added public ```static Reference* Reference::New``` and ```static void Reference::Delete``` methods to make it more clear how the ```Reference``` objects are allocated and cleaned-up
     - Add a type check to ``napi_get_array_length``` which returns an error if the argument is not an array object
     - Change ```napi_create_symbol``` to take a ```napi_value``` instead of a ```const char*``` for the symbol description string. The API now throws if description is not a string but NULL is allowed.
    
    * Remove UTF-8 BOM characters and other non-ANSI whitespace
    
    * Change parameter names for create string APIs and address other feedback
    
    * Fixes for unit tests
    
    * Fix lint errors found via CI
    boingoing authored and jasongin committed Mar 23, 2017
    Configuration menu
    Copy the full SHA
    fb8ced4 View commit details
    Browse the repository at this point in the history
  7. Address some minor PR feedback (nodejs#187)

     - Simplify conversion to/from napi_value
     - Better names for CallbackWrapper template params
     - Fatal error when trying to set setter return value
     - Use node::arraysize
     - Replace v8::Handle with v8::Local
     - Align the star after v8::Isolate
    jasongin committed Mar 23, 2017
    Configuration menu
    Copy the full SHA
    116bd19 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    1b2f2db View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    1427b33 View commit details
    Browse the repository at this point in the history
  10. Add some type checking (nodejs#195)

     - Check the type before casting to string when creating error objects.
     - Return an error when napi_typeof does not find any valid type.
    jasongin committed Mar 23, 2017
    Configuration menu
    Copy the full SHA
    6b4ce53 View commit details
    Browse the repository at this point in the history

Commits on Mar 25, 2017

  1. Updates for review feedback (nodejs#199)

     - Delete the node_api_*internal.h headers
     - Don't crash when casting numbers when
       V8_ENABLE_CHECKS is defined
     - Return 0 when getting NaN value as an integer
     - Always set callback data internal field to prevent
       crashing when V8_ENABLE_CHECKS is defined
     - Style: replace `if (ptr)` with `if (ptr != nullptr)`
     - Fix extern "C" in node_api_async.h
     - Minor doc changes
    jasongin committed Mar 25, 2017
    Configuration menu
    Copy the full SHA
    f21ab80 View commit details
    Browse the repository at this point in the history

Commits on Mar 28, 2017

  1. Address PR feedback (nodejs#201)

     - Consistent documentation for --napi-modules
     - Add underscore to napi_get_property_names
     - Avoid using V8 APIs marked as pending deprecation
     - Avoid unnecessary copying of args arrays
     - Other miscellaneous cleanup
    jasongin committed Mar 28, 2017
    Configuration menu
    Copy the full SHA
    e1ca374 View commit details
    Browse the repository at this point in the history
  2. Updates for review feedback (nodejs#203)

     - Add an env parameter to napi_finalize
     - Remove unnecessary reinterpret_cast<> calls
     - Remove redundant Maybe.IsNothing() checks
     - Make function call result parameters optional
     - Wrap internal field pointer values in External
     - Fix broken callback tests and add error-checking
     - Other misc test cleanup
    jasongin committed Mar 28, 2017
    Configuration menu
    Copy the full SHA
    9c0b151 View commit details
    Browse the repository at this point in the history

Commits on Mar 29, 2017

  1. Refcount for v8impl::Reference should be unsigned (nodejs#207)

    * Refcount for v8impl::Reference should be unsigned
    
    Add ```Reference::RefCount()``` and check the refcount value before trying to call ```Reference::Unref()``` to avoid underflowing the refcount. This allows us to continue returning an error from ```napi_reference_unref``` if it is called with a reference that already has refcount set to zero.
    
    * Add check for _refcount == 0 in Reference::Unref to avoid an underflow
    boingoing authored and jasongin committed Mar 29, 2017
    Configuration menu
    Copy the full SHA
    375af79 View commit details
    Browse the repository at this point in the history
  2. Check value is external in napi_unwrap (nodejs#210)

    - Check that an internal field value is actually an External before casting.
       This prevents a crash if the wrong object is passed to napi_unwrap.
     - Wrap some macro parameters in parentheses.
    jasongin committed Mar 29, 2017
    Configuration menu
    Copy the full SHA
    20b6cf2 View commit details
    Browse the repository at this point in the history
  3. Remove the async API sources (nodejs#212)

    These APIs will be redesigned and added into the master branch after our main PR lands there.
    
    See nodejs/abi-stable-node#204 to see progress on the redesigned APIs.
    boingoing authored and jasongin committed Mar 29, 2017
    Configuration menu
    Copy the full SHA
    7a339c0 View commit details
    Browse the repository at this point in the history
  4. napi: add napi_env to napi_get_last_error_info() (nodejs#211)

    This makes it necessary to pass napi_env to napi_get_last_error_info()
    thereby ensuring that errors can be tied to the napi_env in the future.
    
    Re nodejs/abi-stable-node#198
    Gabriel "_|Nix|_" Schulhof authored and jasongin committed Mar 29, 2017
    Configuration menu
    Copy the full SHA
    232f004 View commit details
    Browse the repository at this point in the history

Commits on Mar 30, 2017

  1. Add the _array suffix to the TypedArray type enum (nodejs#213)

    * Add the _array suffix to the TypedArray type enum
    
    Also remove a stale comment
    boingoing authored and jasongin committed Mar 30, 2017
    Configuration menu
    Copy the full SHA
    aa22a2a View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0e61d00 View commit details
    Browse the repository at this point in the history

Commits on Mar 31, 2017

  1. Configuration menu
    Copy the full SHA
    c87eade View commit details
    Browse the repository at this point in the history