From 0eaeaea45425396e74b5e21333f4771d91c3fcfb Mon Sep 17 00:00:00 2001 From: Gabriel Schulhof Date: Sat, 6 Feb 2021 19:40:36 -0800 Subject: [PATCH] doc: rename N-API to Node-API Refs: https://github.com/nodejs/abi-stable-node/issues/420 PR-URL: https://github.com/nodejs/node/pull/37259 Reviewed-By: Rich Trott Reviewed-By: Gireesh Punathil --- doc/api/addons.md | 25 +-- doc/api/errors.md | 4 +- doc/api/index.md | 2 +- doc/api/n-api.md | 298 +++++++++++++++--------------- doc/guides/adding-new-napi-api.md | 14 +- doc/guides/collaborator-guide.md | 12 +- 6 files changed, 178 insertions(+), 177 deletions(-) diff --git a/doc/api/addons.md b/doc/api/addons.md index 25df09dbc73913..979f04f82ce225 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -7,12 +7,13 @@ _Addons_ are dynamically-linked shared objects written in C++. The [`require()`][require] function can load addons as ordinary Node.js modules. Addons provide an interface between JavaScript and C/C++ libraries. -There are three options for implementing addons: N-API, nan, or direct +There are three options for implementing addons: Node-API, nan, or direct use of internal V8, libuv and Node.js libraries. Unless there is a need for -direct access to functionality which is not exposed by N-API, use N-API. -Refer to [C/C++ addons with N-API](n-api.md) for more information on N-API. +direct access to functionality which is not exposed by Node-API, use Node-API. +Refer to [C/C++ addons with Node-API](n-api.md) for more information on +Node-API. -When not using N-API, implementing addons is complicated, +When not using Node-API, implementing addons is complicated, involving knowledge of several components and APIs: * V8: the C++ library Node.js uses to provide the @@ -243,7 +244,7 @@ changes: In order to be loaded from multiple Node.js environments, such as a main thread and a Worker thread, an add-on needs to either: -* Be an N-API addon, or +* Be an Node-API addon, or * Be declared as context-aware using `NODE_MODULE_INIT()` as described above In order to support [`Worker`][] threads, addons need to clean up any resources @@ -435,11 +436,11 @@ addon developers are recommended to use to keep compatibility between past and future releases of V8 and Node.js. See the `nan` [examples][] for an illustration of how it can be used. -## N-API +## Node-API > Stability: 2 - Stable -N-API is an API for building native addons. It is independent from +Node-API is an API for building native addons. It is independent from the underlying JavaScript runtime (e.g. V8) and is maintained as part of Node.js itself. This API will be Application Binary Interface (ABI) stable across versions of Node.js. It is intended to insulate addons from @@ -449,17 +450,17 @@ recompilation. Addons are built/packaged with the same approach/tools outlined in this document (node-gyp, etc.). The only difference is the set of APIs that are used by the native code. Instead of using the V8 or [Native Abstractions for Node.js][] APIs, the functions available -in the N-API are used. +in the Node-API are used. Creating and maintaining an addon that benefits from the ABI stability -provided by N-API carries with it certain +provided by Node-API carries with it certain [implementation considerations](n-api.md#n_api_implications_of_abi_stability). -To use N-API in the above "Hello world" example, replace the content of +To use Node-API in the above "Hello world" example, replace the content of `hello.cc` with the following. All other instructions remain the same. ```cpp -// hello.cc using N-API +// hello.cc using Node-API #include namespace demo { @@ -491,7 +492,7 @@ NAPI_MODULE(NODE_GYP_MODULE_NAME, init) ``` The functions available and how to use them are documented in -[C/C++ addons with N-API](n-api.md). +[C/C++ addons with Node-API](n-api.md). ## Addon examples diff --git a/doc/api/errors.md b/doc/api/errors.md index 4bd02a224ae207..8135b1cc5b02ec 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1642,7 +1642,7 @@ would be possible by calling a callback more than once. ### `ERR_NAPI_CONS_FUNCTION` -While using `N-API`, a constructor passed was not a function. +While using `Node-API`, a constructor passed was not a function. ### `ERR_NAPI_INVALID_DATAVIEW_ARGS` @@ -2361,7 +2361,7 @@ added: v9.0.0 removed: v10.0.0 --> -Used by the `N-API` when `Constructor.prototype` is not an object. +Used by the `Node-API` when `Constructor.prototype` is not an object. ### `ERR_NO_LONGER_SUPPORTED` diff --git a/doc/api/index.md b/doc/api/index.md index 393110e134cad7..8bfa1ffab3679e 100644 --- a/doc/api/index.md +++ b/doc/api/index.md @@ -14,7 +14,7 @@ * [Async hooks](async_hooks.md) * [Buffer](buffer.md) * [C++ addons](addons.md) -* [C/C++ addons with N-API](n-api.md) +* [C/C++ addons with Node-API](n-api.md) * [C++ embedder API](embedding.md) * [Child processes](child_process.md) * [Cluster](cluster.md) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index a51279ee1482ba..0da7cd21b503bc 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -1,30 +1,29 @@ -# N-API +# Node-API > Stability: 2 - Stable -N-API (pronounced N as in the letter, followed by API) -is an API for building native Addons. It is independent from -the underlying JavaScript runtime (for example, V8) and is maintained as part of -Node.js itself. This API will be Application Binary Interface (ABI) stable -across versions of Node.js. It is intended to insulate Addons from -changes in the underlying JavaScript engine and allow modules +Node-API (formerly N-API) is an API for building native Addons. It is +independent from the underlying JavaScript runtime (for example, V8) and is +maintained as part of Node.js itself. This API will be Application Binary +Interface (ABI) stable across versions of Node.js. It is intended to insulate +addons from changes in the underlying JavaScript engine and allow modules compiled for one major version to run on later major versions of Node.js without recompilation. The [ABI Stability][] guide provides a more in-depth explanation. Addons are built/packaged with the same approach/tools outlined in the section titled [C++ Addons][]. The only difference is the set of APIs that are used by the native code. Instead of using the V8 or [Native Abstractions for Node.js][] -APIs, the functions available in the N-API are used. +APIs, the functions available in Node-API are used. -APIs exposed by N-API are generally used to create and manipulate +APIs exposed by Node-API are generally used to create and manipulate JavaScript values. Concepts and operations generally map to ideas specified in the ECMA-262 Language Specification. The APIs have the following properties: -* All N-API calls return a status code of type `napi_status`. This +* All Node-API calls return a status code of type `napi_status`. This status indicates whether the API call succeeded or failed. * The API's return value is passed via an out parameter. * All JavaScript values are abstracted behind an opaque type named @@ -33,14 +32,14 @@ properties: using `napi_get_last_error_info`. More information can be found in the error handling section [Error handling][]. -The N-API is a C API that ensures ABI stability across Node.js versions +Node-API-API is a C API that ensures ABI stability across Node.js versions and different compiler levels. A C++ API can be easier to use. To support using C++, the project maintains a C++ wrapper module called [`node-addon-api`][]. This wrapper provides an inlineable C++ API. Binaries built -with `node-addon-api` will depend on the symbols for the N-API C-based +with `node-addon-api` will depend on the symbols for the Node-API C-based functions exported by Node.js. `node-addon-api` is a more -efficient way to write code that calls N-API. Take, for example, the +efficient way to write code that calls Node-API. Take, for example, the following `node-addon-api` code. The first section shows the `node-addon-api` code and the second section shows what actually gets used in the addon. @@ -78,13 +77,13 @@ it still gets the benefits of the ABI stability provided by the C API. When using `node-addon-api` instead of the C APIs, start with the API [docs][] for `node-addon-api`. -The [N-API Resource](https://nodejs.github.io/node-addon-examples/) offers an -excellent orientation and tips for developers just getting started with N-API -and `node-addon-api`. +The [Node-API Resource](https://nodejs.github.io/node-addon-examples/) offers +an excellent orientation and tips for developers just getting started with +Node-API and `node-addon-api`. ## Implications of ABI stability -Although N-API provides an ABI stability guarantee, other parts of Node.js do +Although Node-API provides an ABI stability guarantee, other parts of Node.js do not, and any external libraries used from the addon may not. In particular, none of the following APIs provide an ABI stability guarantee across major versions: @@ -111,19 +110,19 @@ versions: ``` Thus, for an addon to remain ABI-compatible across Node.js major versions, it -must use N-API exclusively by restricting itself to using +must use Node-API exclusively by restricting itself to using ```c #include ``` and by checking, for all external libraries that it uses, that the external -library makes ABI stability guarantees similar to N-API. +library makes ABI stability guarantees similar to Node-API. ## Building Unlike modules written in JavaScript, developing and deploying Node.js -native addons using N-API requires an additional set of tools. Besides the +native addons using Node-API requires an additional set of tools. Besides the basic tools required to develop for Node.js, the native addon developer requires a toolchain that can compile C and C++ code into a binary. In addition, depending upon how the native addon is deployed, the *user* of @@ -207,15 +206,15 @@ available to the module user when the native module is installed. ## Usage -In order to use the N-API functions, include the file [`node_api.h`][] which is -located in the src directory in the node development tree: +In order to use the Node-API functions, include the file [`node_api.h`][] which +is located in the src directory in the node development tree: ```c #include ``` This will opt into the default `NAPI_VERSION` for the given release of Node.js. -In order to ensure compatibility with specific versions of N-API, the version +In order to ensure compatibility with specific versions of Node-API, the version can be specified explicitly when including the header: ```c @@ -223,10 +222,10 @@ can be specified explicitly when including the header: #include ``` -This restricts the N-API surface to just the functionality that was available in -the specified (and earlier) versions. +This restricts the Node-API surface to just the functionality that was available +in the specified (and earlier) versions. -Some of the N-API surface is experimental and requires explicit opt-in: +Some of the Node-API surface is experimental and requires explicit opt-in: ```c #define NAPI_EXPERIMENTAL @@ -236,9 +235,9 @@ Some of the N-API surface is experimental and requires explicit opt-in: In this case the entire API surface, including any experimental APIs, will be available to the module code. -## N-API version matrix +## Node-API version matrix -N-API versions are additive and versioned independently from Node.js. +Node-API versions are additive and versioned independently from Node.js. Version 4 is an extension to version 3 in that it has all of the APIs from version 3 with some additions. This means that it is not necessary to recompile for new versions of Node.js which are @@ -325,37 +324,38 @@ listed as supporting a later version. -\* N-API was experimental. +\* Node-API was experimental. -\*\* Node.js 8.0.0 included N-API as experimental. It was released as N-API -version 1 but continued to evolve until Node.js 8.6.0. The API is different in -versions prior to Node.js 8.6.0. We recommend N-API version 3 or later. +\*\* Node.js 8.0.0 included Node-API as experimental. It was released as +Node-API version 1 but continued to evolve until Node.js 8.6.0. The API is +different in versions prior to Node.js 8.6.0. We recommend Node-API version 3 or +later. -Each API documented for N-API will have a header named `added in:`, and APIs -which are stable will have the additional header `N-API version:`. +Each API documented for Node-API will have a header named `added in:`, and APIs +which are stable will have the additional header `Node-API version:`. APIs are directly usable when using a Node.js version which supports -the N-API version shown in `N-API version:` or higher. +the Node-API version shown in `Node-API version:` or higher. When using a Node.js version that does not support the -`N-API version:` listed or if there is no `N-API version:` listed, +`Node-API version:` listed or if there is no `Node-API version:` listed, then the API will only be available if `#define NAPI_EXPERIMENTAL` precedes the inclusion of `node_api.h` or `js_native_api.h`. If an API appears not to be available on a version of Node.js which is later than the one shown in `added in:` then this is most likely the reason for the apparent absence. -The N-APIs associated strictly with accessing ECMAScript features from native +The Node-APIs associated strictly with accessing ECMAScript features from native code can be found separately in `js_native_api.h` and `js_native_api_types.h`. The APIs defined in these headers are included in `node_api.h` and `node_api_types.h`. The headers are structured in this way in order to allow -implementations of N-API outside of Node.js. For those implementations the +implementations of Node-API outside of Node.js. For those implementations the Node.js specific APIs may not be applicable. The Node.js-specific parts of an addon can be separated from the code that exposes the actual functionality to the JavaScript environment so that the -latter may be used with multiple implementations of N-API. In the example below, -`addon.c` and `addon.h` refer only to `js_native_api.h`. This ensures that -`addon.c` can be reused to compile against either the Node.js implementation of -N-API or any implementation of N-API outside of Node.js. +latter may be used with multiple implementations of Node-API. In the example +below, `addon.c` and `addon.h` refer only to `js_native_api.h`. This ensures +that `addon.c` can be reused to compile against either the Node.js +implementation of Node-API or any implementation of Node-API outside of Node.js. `addon_node.c` is a separate file that contains the Node.js specific entry point to the addon and which instantiates the addon by calling into `addon.c` when the @@ -456,8 +456,8 @@ Native addons may need to allocate global state which they use during their entire life cycle such that the state must be unique to each instance of the addon. -To this end, N-API provides a way to allocate data such that its life cycle is -tied to the life cycle of the Agent. +To this end, Node-API provides a way to allocate data such that its life cycle +is tied to the life cycle of the Agent. ### napi_set_instance_data -Integral status code indicating the success or failure of a N-API call. +Integral status code indicating the success or failure of a Node-API call. Currently, the following status codes are supported. ```c @@ -578,18 +578,18 @@ typedef struct { not implemented for any VM. * `engine_error_code`: VM-specific error code. This is currently not implemented for any VM. -* `error_code`: The N-API status code that originated with the last error. +* `error_code`: The Node-API status code that originated with the last error. See the [Error handling][] section for additional information. ### napi_env -`napi_env` is used to represent a context that the underlying N-API +`napi_env` is used to represent a context that the underlying Node-API implementation can use to persist VM-specific state. This structure is passed to native functions when they're invoked, and it must be passed back when -making N-API calls. Specifically, the same `napi_env` that was passed in when +making Node-API calls. Specifically, the same `napi_env` that was passed in when the initial native function was called must be passed to any subsequent -nested N-API calls. Caching the `napi_env` for the purpose of general reuse, +nested Node-API calls. Caching the `napi_env` for the purpose of general reuse, and passing the `napi_env` between instances of the same addon running on different [`Worker`][] threads is not allowed. The `napi_env` becomes invalid when an instance of a native addon is unloaded. Notification of this event is @@ -645,14 +645,14 @@ typedef enum { } napi_threadsafe_function_call_mode; ``` -### N-API memory management types +### Node-API memory management types #### napi_handle_scope This is an abstraction used to control and modify the lifetime of objects -created within a particular scope. In general, N-API values are created within -the context of a handle scope. When a native method is called from +created within a particular scope. In general, Node-API values are created +within the context of a handle scope. When a native method is called from JavaScript, a default handle scope will exist. If the user does not explicitly -create a new handle scope, N-API values will be created in the default handle +create a new handle scope, Node-API values will be created in the default handle scope. For any invocations of code outside the execution of a native method (for instance, during a libuv callback invocation), the module is required to create a scope before invoking any functions that can result in the creation @@ -717,7 +717,7 @@ An opaque value returned by [`napi_add_async_cleanup_hook`][]. It must be passed to [`napi_remove_async_cleanup_hook`][] when the chain of asynchronous cleanup events completes. -### N-API callback types +### Node-API callback types #### napi_callback_info Function pointer type for user-provided native functions which are to be -exposed to JavaScript via N-API. Callback functions should satisfy the +exposed to JavaScript via Node-API. Callback functions should satisfy the following signature: ```c @@ -777,8 +777,8 @@ operations. Callback functions must satisfy the following signature: typedef void (*napi_async_execute_callback)(napi_env env, void* data); ``` -Implementations of this function must avoid making N-API calls that execute -JavaScript or interact with JavaScript objects. N-API calls should be in the +Implementations of this function must avoid making Node-API calls that execute +JavaScript or interact with JavaScript objects. Node-API calls should be in the `napi_async_complete_callback` instead. Do not use the `napi_env` parameter as it will likely result in execution of JavaScript. @@ -815,7 +815,7 @@ The data arriving from the secondary thread via the queue is given in the `data` parameter and the JavaScript function to call is given in the `js_callback` parameter. -N-API sets up the environment prior to calling this callback, so it is +Node-API sets up the environment prior to calling this callback, so it is sufficient to call the JavaScript function via `napi_call_function` rather than via `napi_make_callback`. @@ -837,7 +837,7 @@ typedef void (*napi_threadsafe_function_call_js)(napi_env env, * `[in] context`: The optional data with which the thread-safe function was created. * `[in] data`: Data created by the secondary thread. It is the responsibility of - the callback to convert this native data to JavaScript values (with N-API + the callback to convert this native data to JavaScript values (with Node-API functions) that can be passed as parameters when `js_callback` is invoked. This pointer is managed entirely by the threads and this callback. Thus this callback should free the data. @@ -871,12 +871,12 @@ end of which `handle` must be passed in a call to ## Error handling -N-API uses both return values and JavaScript exceptions for error handling. +Node-API uses both return values and JavaScript exceptions for error handling. The following sections explain the approach for each case. ### Return values -All of the N-API functions share the same error handling pattern. The +All of the Node-API functions share the same error handling pattern. The return type of all API functions is `napi_status`. The return value will be `napi_ok` if the request was successful and @@ -919,10 +919,10 @@ typedef struct napi_extended_error_info { * `error_message`: Textual representation of the error that occurred. * `engine_reserved`: Opaque handle reserved for engine use only. * `engine_error_code`: VM specific error code. -* `error_code`: n-api status code for the last error. +* `error_code`: Node-API status code for the last error. [`napi_get_last_error_info`][] returns the information for the last -N-API call that was made. +Node-API call that was made. Do not rely on the content or format of any of the extended information as it is not subject to SemVer and may change at any time. It is intended only for @@ -950,7 +950,7 @@ This API retrieves a `napi_extended_error_info` structure with information about the last error that occurred. The content of the `napi_extended_error_info` returned is only valid up until -an n-api function is called on the same `env`. +a Node-API function is called on the same `env`. Do not rely on the content or format of any of the extended information as it is not subject to SemVer and may change at any time. It is intended only for @@ -960,7 +960,7 @@ This API can be called even if there is a pending JavaScript exception. ### Exceptions -Any N-API function call may result in a pending JavaScript exception. This is +Any Node-API function call may result in a pending JavaScript exception. This is the case for any of the API functions, even those that may not cause the execution of JavaScript. @@ -971,10 +971,10 @@ exception is pending and no additional action is required. If the instead of simply returning immediately, [`napi_is_exception_pending`][] must be called in order to determine if an exception is pending or not. -In many cases when an N-API function is called and an exception is +In many cases when a Node-API function is called and an exception is already pending, the function will return immediately with a `napi_status` of `napi_pending_exception`. However, this is not the case -for all functions. N-API allows a subset of the functions to be +for all functions. Node-API allows a subset of the functions to be called to allow for some minimal cleanup before returning to JavaScript. In that case, `napi_status` will reflect the status for the function. It will not reflect previous pending exceptions. To avoid confusion, check @@ -985,7 +985,7 @@ When an exception is pending one of two approaches can be employed. The first approach is to do any appropriate cleanup and then return so that execution will return to JavaScript. As part of the transition back to JavaScript, the exception will be thrown at the point in the JavaScript -code where the native method was invoked. The behavior of most N-API calls +code where the native method was invoked. The behavior of most Node-API calls is unspecified while an exception is pending, and many will simply return `napi_pending_exception`, so do as little as possible and then return to JavaScript where the exception can be handled. @@ -1018,7 +1018,7 @@ generated internally. The goal is for applications to use these error codes for all error checking. The associated error messages will remain, but will only be meant to be used for logging and display with the expectation that the message can change without -SemVer applying. In order to support this model with N-API, both +SemVer applying. In order to support this model with Node-API, both in internal functionality and for module specific functionality (as its good practice), the `throw_` and `create_` functions take an optional code parameter which is the string for the code @@ -1290,7 +1290,7 @@ This API can be called even if there is a pending JavaScript exception. ## Object lifetime management -As N-API calls are made, handles to objects in the heap for the underlying +As Node-API calls are made, handles to objects in the heap for the underlying VM may be returned as `napi_values`. These handles must hold the objects 'live' until they are no longer required by the native code, otherwise the objects could be collected before the native code was @@ -1304,7 +1304,7 @@ held live for the lifespan of the native method call. In many cases, however, it is necessary that the handles remain valid for either a shorter or longer lifespan than that of the native method. -The sections which follow describe the N-API functions that can be used +The sections which follow describe the Node-API functions that can be used to change the handle lifespan from the default. ### Making handle lifespan shorter than that of the native method @@ -1328,13 +1328,13 @@ substantial resources. In addition, even though the native code could only use the most recent handle, all of the associated objects would also be kept alive since they all share the same scope. -To handle this case, N-API provides the ability to establish a new 'scope' to +To handle this case, Node-API provides the ability to establish a new 'scope' to which newly created handles will be associated. Once those handles are no longer required, the scope can be 'closed' and any handles associated with the scope are invalidated. The methods available to open/close scopes are [`napi_open_handle_scope`][] and [`napi_close_handle_scope`][]. -N-API only supports a single nested hierarchy of scopes. There is only one +Node-API only supports a single nested hierarchy of scopes. There is only one active scope at any time, and all new handles will be associated with that scope while it is active. Scopes must be closed in the reverse order from which they are opened. In addition, all scopes created within a native method @@ -1365,8 +1365,8 @@ for (int i = 0; i < 1000000; i++) { ``` When nesting scopes, there are cases where a handle from an -inner scope needs to live beyond the lifespan of that scope. N-API supports an -'escapable scope' in order to support this case. An escapable scope +inner scope needs to live beyond the lifespan of that scope. Node-API supports +an 'escapable scope' in order to support this case. An escapable scope allows one handle to be 'promoted' so that it 'escapes' the current scope and the lifespan of the handle changes from the current scope to that of the outer scope. @@ -1499,7 +1499,7 @@ described in the earlier section. The lifespan of a normal handle is managed by scopes and all scopes must be closed before the end of a native method. -N-API provides methods to create persistent references to an object. +Node-API provides methods to create persistent references to an object. Each persistent reference has an associated count with a value of 0 or higher. The count determines if the reference will keep the corresponding object live. References with a count of 0 do not @@ -1643,7 +1643,7 @@ While a Node.js process typically releases all its resources when exiting, embedders of Node.js, or future Worker support, may require addons to register clean-up hooks that will be run once the current Node.js instance exits. -N-API provides functions for registering and un-registering such callbacks. +Node-API provides functions for registering and un-registering such callbacks. When those callbacks are run, all resources that are being held by the addon should be freed up. @@ -1758,7 +1758,7 @@ This must be called on any `napi_async_cleanup_hook_handle` value obtained from [`napi_add_async_cleanup_hook`][]. ## Module registration -N-API modules are registered in a manner similar to other modules +Node-API modules are registered in a manner similar to other modules except that instead of using the `NODE_MODULE` macro the following is used: @@ -1766,7 +1766,7 @@ is used: NAPI_MODULE(NODE_GYP_MODULE_NAME, Init) ``` -The next difference is the signature for the `Init` method. For a N-API +The next difference is the signature for the `Init` method. For a Node-API module it is as follows: ```c @@ -1776,8 +1776,8 @@ napi_value Init(napi_env env, napi_value exports); The return value from `Init` is treated as the `exports` object for the module. The `Init` method is passed an empty object via the `exports` parameter as a convenience. If `Init` returns `NULL`, the parameter passed as `exports` is -exported by the module. N-API modules cannot modify the `module` object but can -specify anything as the `exports` property of the module. +exported by the module. Node-API modules cannot modify the `module` object but +can specify anything as the `exports` property of the module. To add the method `hello` as a function so that it can be called as a method provided by the addon: @@ -1859,7 +1859,7 @@ NAPI_MODULE_INIT() { } ``` -All N-API addons are context-aware, meaning they may be loaded multiple +All Node-API addons are context-aware, meaning they may be loaded multiple times. There are a few design considerations when declaring such a module. The documentation on [context-aware addons][] provides more details. @@ -1873,19 +1873,19 @@ For more details on building addon modules in general, refer to the existing API. ## Working with JavaScript values -N-API exposes a set of APIs to create all types of JavaScript values. +Node-API exposes a set of APIs to create all types of JavaScript values. Some of these types are documented under [Section 6][] of the [ECMAScript Language Specification][]. Fundamentally, these APIs are used to do one of the following: 1. Create a new JavaScript object -2. Convert from a primitive C type to an N-API value -3. Convert from N-API value to a primitive C type +2. Convert from a primitive C type to a Node-API value +3. Convert from Node-API value to a primitive C type 4. Get global instances including `undefined` and `null` -N-API values are represented by the type `napi_value`. -Any N-API call that requires a JavaScript value takes in a `napi_value`. +Node-API values are represented by the type `napi_value`. +Any Node-API call that requires a JavaScript value takes in a `napi_value`. In some cases, the API does check the type of the `napi_value` up-front. However, for better performance, it's better for the caller to make sure that the `napi_value` in question is of the JavaScript type expected by the API. @@ -2013,12 +2013,12 @@ napiVersion: 1 napi_status napi_create_array(napi_env env, napi_value* result) ``` -* `[in] env`: The environment that the N-API call is invoked under. +* `[in] env`: The environment that the Node-API call is invoked under. * `[out] result`: A `napi_value` representing a JavaScript `Array`. Returns `napi_ok` if the API succeeded. -This API returns an N-API value corresponding to a JavaScript `Array` type. +This API returns a Node-API value corresponding to a JavaScript `Array` type. JavaScript arrays are described in [Section 22.1][] of the ECMAScript Language Specification. @@ -2040,7 +2040,7 @@ napi_status napi_create_array_with_length(napi_env env, Returns `napi_ok` if the API succeeded. -This API returns an N-API value corresponding to a JavaScript `Array` type. +This API returns a Node-API value corresponding to a JavaScript `Array` type. The `Array`'s length property is set to the passed-in length parameter. However, the underlying buffer is not guaranteed to be pre-allocated by the VM when the array is created. That behavior is left to the underlying VM @@ -2071,7 +2071,7 @@ napi_status napi_create_arraybuffer(napi_env env, Returns `napi_ok` if the API succeeded. -This API returns an N-API value corresponding to a JavaScript `ArrayBuffer`. +This API returns a Node-API value corresponding to a JavaScript `ArrayBuffer`. `ArrayBuffer`s are used to represent fixed-length binary data buffers. They are normally used as a backing-buffer for `TypedArray` objects. The `ArrayBuffer` allocated will have an underlying byte buffer whose size is @@ -2230,7 +2230,7 @@ napi_create_external_arraybuffer(napi_env env, Returns `napi_ok` if the API succeeded. -This API returns an N-API value corresponding to a JavaScript `ArrayBuffer`. +This API returns a Node-API value corresponding to a JavaScript `ArrayBuffer`. The underlying byte buffer of the `ArrayBuffer` is externally allocated and managed. The caller must ensure that the byte buffer remains valid until the finalize callback is called. @@ -2403,7 +2403,7 @@ raised. JavaScript `DataView` objects are described in [Section 24.3][] of the ECMAScript Language Specification. -### Functions to convert from C types to N-API +### Functions to convert from C types to Node-API #### napi_create_int32