diff --git a/doc/api/errors.md b/doc/api/errors.md
index f2de6717a57ee2..c7264b083f2d98 100755
--- a/doc/api/errors.md
+++ b/doc/api/errors.md
@@ -991,6 +991,24 @@ While using `N-API`, a constructor passed was not a function.
While using `N-API`, `Constructor.prototype` was not an object.
+
+### ERR_NAPI_INVALID_DATAVIEW_ARGS
+
+While calling `napi_create_dataview()`, a given `offset` was outside the bounds
+of the dataview or `offset + length` was larger than a length of given `buffer`.
+
+
+### ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT
+
+While calling `napi_create_typedarray()`, the provided `offset` was not a
+multiple of the element size.
+
+
+### ERR_NAPI_INVALID_TYPEDARRAY_LENGTH
+
+While calling `napi_create_typedarray()`, `(length * size_of_element) +
+byte_offset` was larger than the length of given `buffer`.
+
### ERR_NO_ICU
diff --git a/doc/api/n-api.md b/doc/api/n-api.md
index f9c24fe4a0e2b1..7ac2ab39448273 100644
--- a/doc/api/n-api.md
+++ b/doc/api/n-api.md
@@ -71,7 +71,7 @@ N-API exposes the following fundamental datatypes as abstractions that are
consumed by the various APIs. These APIs should be treated as opaque,
introspectable only with other N-API calls.
-### *napi_status*
+### napi_status
Integral status code indicating the success or failure of a N-API call.
Currently, the following status codes are supported.
```C
@@ -94,7 +94,7 @@ typedef enum {
If additional information is required upon an API returning a failed status,
it can be obtained by calling `napi_get_last_error_info`.
-### *napi_extended_error_info*
+### napi_extended_error_info
```C
typedef struct {
const char* error_message;
@@ -114,7 +114,7 @@ typedef struct {
See the [Error Handling][] section for additional information.
-### *napi_env*
+### napi_env
`napi_env` is used to represent a context that the underlying N-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
@@ -123,11 +123,11 @@ 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 is
not allowed.
-### *napi_value*
+### napi_value
This is an opaque pointer that is used to represent a JavaScript value.
### N-API Memory Management types
-#### *napi_handle_scope*
+#### 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
@@ -145,11 +145,11 @@ referenced from the current stack frame.
For more details, review the [Object Lifetime Management][].
-#### *napi_escapable_handle_scope*
+#### napi_escapable_handle_scope
Escapable handle scopes are a special type of handle scope to return values
created within a particular handle scope to a parent scope.
-#### *napi_ref*
+#### napi_ref
This is the abstraction to use to reference a `napi_value`. This allows for
users to manage the lifetimes of JavaScript values, including defining their
minimum lifetimes explicitly.
@@ -157,12 +157,12 @@ minimum lifetimes explicitly.
For more details, review the [Object Lifetime Management][].
### N-API Callback types
-#### *napi_callback_info*
+#### napi_callback_info
Opaque datatype that is passed to a callback function. It can be used for
getting additional information about the context in which the callback was
invoked.
-#### *napi_callback*
+#### napi_callback
Function pointer type for user-provided native functions which are to be
exposed to JavaScript via N-API. Callback functions should satisfy the
following signature:
@@ -170,7 +170,7 @@ following signature:
typedef napi_value (*napi_callback)(napi_env, napi_callback_info);
```
-#### *napi_finalize*
+#### napi_finalize
Function pointer type for add-on provided functions that allow the user to be
notified when externally-owned data is ready to be cleaned up because the
object with which it was associated with, has been garbage-collected. The user
@@ -279,6 +279,8 @@ valid up until an n-api function is called on the same `env`.
information as it is not subject to SemVer and may change at any time.
It is intended only for logging purposes.
+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
@@ -504,7 +506,6 @@ Returns `napi_ok` if the API succeeded.
This API returns a JavaScript RangeError with the text provided.
-
#### napi_get_and_clear_last_exception
+```C
+napi_status napi_fatal_exception(napi_env env, napi_value err);
+```
+
+- `[in] env`: The environment that the API is invoked under.
+- `[in] err`: The error you want to pass to `uncaughtException`.
+
+Trigger an `uncaughtException` in JavaScript. Useful if an async
+callback throws an exception with no way to recover.
+
### Fatal Errors
In the event of an unrecoverable error in a native module, a fatal error can be
@@ -554,14 +573,16 @@ NAPI_NO_RETURN void napi_fatal_error(const char* location,
- `[in] location`: Optional location at which the error occurred.
- `[in] location_len`: The length of the location in bytes, or
-NAPI_AUTO_LENGTH if it is null-terminated.
+`NAPI_AUTO_LENGTH` if it is null-terminated.
- `[in] message`: The message associated with the error.
- `[in] message_len`: The length of the message in bytes, or
-NAPI_AUTO_LENGTH if it is
+`NAPI_AUTO_LENGTH` if it is
null-terminated.
The function call does not return, the process will be terminated.
+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
@@ -589,7 +610,7 @@ that has a loop which iterates through the elements in a large array:
```C
for (int i = 0; i < 1000000; i++) {
napi_value result;
- napi_status status = napi_get_element(e object, i, &result);
+ napi_status status = napi_get_element(e, object, i, &result);
if (status != napi_ok) {
break;
}
@@ -608,7 +629,7 @@ 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 hiearchy of scopes. There is only one
+N-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
@@ -626,7 +647,7 @@ for (int i = 0; i < 1000000; i++) {
break;
}
napi_value result;
- status = napi_get_element(e object, i, &result);
+ status = napi_get_element(e, object, i, &result);
if (status != napi_ok) {
break;
}
@@ -682,6 +703,8 @@ Returns `napi_ok` if the API succeeded.
This API closes the scope passed in. Scopes must be closed in the
reverse order from which they were created.
+This API can be called even if there is a pending JavaScript exception.
+
#### napi_open_escapable_handle_scope
@@ -1038,7 +1066,7 @@ JavaScript arrays are described in
[Section 22.1](https://tc39.github.io/ecma262/#sec-array-objects) of the
ECMAScript Language Specification.
-#### *napi_create_array_with_length*
+#### napi_create_array_with_length
@@ -1067,7 +1095,7 @@ JavaScript arrays are described in
[Section 22.1](https://tc39.github.io/ecma262/#sec-array-objects) of the
ECMAScript Language Specification.
-#### *napi_create_arraybuffer*
+#### napi_create_arraybuffer
@@ -1099,7 +1127,7 @@ JavaScript ArrayBuffer objects are described in
[Section 24.1](https://tc39.github.io/ecma262/#sec-arraybuffer-objects)
of the ECMAScript Language Specification.
-#### *napi_create_buffer*
+#### napi_create_buffer
@@ -1120,7 +1148,7 @@ Returns `napi_ok` if the API succeeded.
This API allocates a `node::Buffer` object. While this is still a
fully-supported data structure, in most cases using a TypedArray will suffice.
-#### *napi_create_buffer_copy*
+#### napi_create_buffer_copy
@@ -1145,7 +1173,7 @@ This API allocates a `node::Buffer` object and initializes it with data copied
from the passed-in buffer. While this is still a fully-supported data
structure, in most cases using a TypedArray will suffice.
-#### *napi_create_external*
+#### napi_create_external
@@ -1212,7 +1240,7 @@ JavaScript ArrayBuffers are described in
[Section 24.1](https://tc39.github.io/ecma262/#sec-arraybuffer-objects)
of the ECMAScript Language Specification.
-#### *napi_create_external_buffer*
+#### napi_create_external_buffer
@@ -1243,7 +1271,7 @@ structure, in most cases using a TypedArray will suffice.
*Note*: For Node.js >=4 `Buffers` are Uint8Arrays.
-#### *napi_create_function*
+#### napi_create_function
@@ -1260,7 +1288,7 @@ napi_status napi_create_function(napi_env env,
- `[in] utf8name`: A string representing the name of the function encoded as
UTF8.
- `[in] length`: The length of the utf8name in bytes, or
-NAPI_AUTO_LENGTH if it is null-terminated.
+`NAPI_AUTO_LENGTH` if it is null-terminated.
- `[in] cb`: A function pointer to the native function to be invoked when the
created function is invoked from JavaScript.
- `[in] data`: Optional arbitrary context data to be passed into the native
@@ -1276,7 +1304,7 @@ JavaScript Functions are described in
[Section 19.2](https://tc39.github.io/ecma262/#sec-function-objects)
of the ECMAScript Language Specification.
-#### *napi_create_object*
+#### napi_create_object
@@ -1296,7 +1324,7 @@ The JavaScript Object type is described in
[Section 6.1.7](https://tc39.github.io/ecma262/#sec-object-type) of the
ECMAScript Language Specification.
-#### *napi_create_symbol*
+#### napi_create_symbol
@@ -1319,7 +1347,7 @@ The JavaScript Symbol type is described in
[Section 19.4](https://tc39.github.io/ecma262/#sec-symbol-objects)
of the ECMAScript Language Specification.
-#### *napi_create_typedarray*
+#### napi_create_typedarray
@@ -1355,7 +1383,7 @@ JavaScript TypedArray Objects are described in
of the ECMAScript Language Specification.
-#### *napi_create_dataview*
+#### napi_create_dataview
@@ -1389,7 +1417,7 @@ JavaScript DataView Objects are described in
[Section 24.3][] of the ECMAScript Language Specification.
### Functions to convert from C types to N-API
-#### *napi_create_int32*
+#### napi_create_int32
@@ -1410,7 +1438,7 @@ The JavaScript Number type is described in
[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
of the ECMAScript Language Specification.
-#### *napi_create_uint32*
+#### napi_create_uint32
@@ -1431,7 +1459,7 @@ The JavaScript Number type is described in
[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
of the ECMAScript Language Specification.
-#### *napi_create_int64*
+#### napi_create_int64
@@ -1458,7 +1486,7 @@ outside the range of
[`Number.MAX_SAFE_INTEGER`](https://tc39.github.io/ecma262/#sec-number.max_safe_integer)
(2^53 - 1) will lose precision.
-#### *napi_create_double*
+#### napi_create_double
@@ -1479,7 +1507,7 @@ The JavaScript Number type is described in
[Section 6.1.6](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-number-type)
of the ECMAScript Language Specification.
-#### *napi_create_string_latin1*
+#### napi_create_string_latin1
@@ -1493,7 +1521,7 @@ napi_status napi_create_string_latin1(napi_env env,
- `[in] env`: The environment that the API is invoked under.
- `[in] str`: Character buffer representing a ISO-8859-1-encoded string.
- `[in] length`: The length of the string in bytes, or
-NAPI_AUTO_LENGTH if it is null-terminated.
+`NAPI_AUTO_LENGTH` if it is null-terminated.
- `[out] result`: A `napi_value` representing a JavaScript String.
Returns `napi_ok` if the API succeeded.
@@ -1504,7 +1532,7 @@ The JavaScript String type is described in
[Section 6.1.4](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type)
of the ECMAScript Language Specification.
-#### *napi_create_string_utf16*
+#### napi_create_string_utf16
@@ -1518,7 +1546,7 @@ napi_status napi_create_string_utf16(napi_env env,
- `[in] env`: The environment that the API is invoked under.
- `[in] str`: Character buffer representing a UTF16-LE-encoded string.
- `[in] length`: The length of the string in two-byte code units, or
-NAPI_AUTO_LENGTH if it is null-terminated.
+`NAPI_AUTO_LENGTH` if it is null-terminated.
- `[out] result`: A `napi_value` representing a JavaScript String.
Returns `napi_ok` if the API succeeded.
@@ -1529,7 +1557,7 @@ The JavaScript String type is described in
[Section 6.1.4](https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type)
of the ECMAScript Language Specification.
-#### *napi_create_string_utf8*
+#### napi_create_string_utf8
@@ -1542,7 +1570,7 @@ napi_status napi_create_string_utf8(napi_env env,
- `[in] env`: The environment that the API is invoked under.
- `[in] str`: Character buffer representing a UTF8-encoded string.
-- `[in] length`: The length of the string in bytes, or NAPI_AUTO_LENGTH
+- `[in] length`: The length of the string in bytes, or `NAPI_AUTO_LENGTH`
if it is null-terminated.
- `[out] result`: A `napi_value` representing a JavaScript String.
@@ -1555,7 +1583,7 @@ The JavaScript String type is described in
of the ECMAScript Language Specification.
### Functions to convert from N-API to C types
-#### *napi_get_array_length*
+#### napi_get_array_length
@@ -1578,7 +1606,7 @@ Array length is described in
[Section 22.1.4.1](https://tc39.github.io/ecma262/#sec-properties-of-array-instances-length)
of the ECMAScript Language Specification.
-#### *napi_get_arraybuffer_info*
+#### napi_get_arraybuffer_info
@@ -1606,7 +1634,7 @@ which can be used to guarantee control over the lifetime of the
ArrayBuffer. It's also safe to use the returned data buffer within the same
callback as long as there are no calls to other APIs that might trigger a GC.
-#### *napi_get_buffer_info*
+#### napi_get_buffer_info
@@ -1630,7 +1658,7 @@ and it's length.
*Warning*: Use caution while using this API since the underlying data buffer's
lifetime is not guaranteed if it's managed by the VM.
-#### *napi_get_prototype*
+#### napi_get_prototype
@@ -1648,7 +1676,7 @@ not the same as the function's `prototype` property).
Returns `napi_ok` if the API succeeded.
-#### *napi_get_typedarray_info*
+#### napi_get_typedarray_info
@@ -1678,9 +1706,7 @@ This API returns various properties of a typed array.
*Warning*: Use caution while using this API since the underlying data buffer
is managed by the VM
-
-
-#### *napi_get_dataview_info*
+#### napi_get_dataview_info
@@ -1707,8 +1733,7 @@ Returns `napi_ok` if the API succeeded.
This API returns various properties of a DataView.
-
-#### *napi_get_value_bool*
+#### napi_get_value_bool
@@ -1727,7 +1752,7 @@ passed in it returns `napi_boolean_expected`.
This API returns the C boolean primitive equivalent of the given JavaScript
Boolean.
-#### *napi_get_value_double*
+#### napi_get_value_double
@@ -1748,8 +1773,7 @@ in it returns `napi_number_expected`.
This API returns the C double primitive equivalent of the given JavaScript
Number.
-
-#### *napi_get_value_external*
+#### napi_get_value_external
@@ -1769,7 +1793,7 @@ passed in it returns `napi_invalid_arg`.
This API retrieves the external data pointer that was previously passed to
`napi_create_external()`.
-#### *napi_get_value_int32*
+#### napi_get_value_int32
@@ -1784,15 +1808,19 @@ napi_status napi_get_value_int32(napi_env env,
- `[out] result`: C int32 primitive equivalent of the given JavaScript Number.
Returns `napi_ok` if the API succeeded. If a non-number `napi_value`
-is passed in `napi_number_expected .
+is passed in `napi_number_expected`.
This API returns the C int32 primitive equivalent
-of the given JavaScript Number. If the number exceeds the range of the
-32 bit integer, then the result is truncated to the equivalent of the
-bottom 32 bits. This can result in a large positive number becoming
-a negative number if the value is > 2^31 -1.
+of the given JavaScript Number.
-#### *napi_get_value_int64*
+If the number exceeds the range of the 32 bit integer, then the result is
+truncated to the equivalent of the bottom 32 bits. This can result in a large
+positive number becoming a negative number if the value is > 2^31 -1.
+
+Non-finite number values (NaN, positive infinity, or negative infinity) set the
+result to zero.
+
+#### napi_get_value_int64
@@ -1809,10 +1837,19 @@ napi_status napi_get_value_int64(napi_env env,
Returns `napi_ok` if the API succeeded. If a non-number `napi_value`
is passed in it returns `napi_number_expected`.
-This API returns the C int64 primitive equivalent of the given
-JavaScript Number
+This API returns the C int64 primitive equivalent of the given JavaScript
+Number.
-#### *napi_get_value_string_latin1*
+Number values outside the range of
+[`Number.MIN_SAFE_INTEGER`](https://tc39.github.io/ecma262/#sec-number.min_safe_integer)
+-(2^53 - 1) -
+[`Number.MAX_SAFE_INTEGER`](https://tc39.github.io/ecma262/#sec-number.max_safe_integer)
+(2^53 - 1) will lose precision.
+
+Non-finite number values (NaN, positive infinity, or negative infinity) set the
+result to zero.
+
+#### napi_get_value_string_latin1
@@ -1839,7 +1876,7 @@ is passed in it returns `napi_string_expected`.
This API returns the ISO-8859-1-encoded string corresponding the value passed
in.
-#### *napi_get_value_string_utf8*
+#### napi_get_value_string_utf8
@@ -1865,7 +1902,7 @@ is passed in it returns `napi_string_expected`.
This API returns the UTF8-encoded string corresponding the value passed in.
-#### *napi_get_value_string_utf16*
+#### napi_get_value_string_utf16
@@ -1891,7 +1928,7 @@ is passed in it returns `napi_string_expected`.
This API returns the UTF16-encoded string corresponding the value passed in.
-#### *napi_get_value_uint32*
+#### napi_get_value_uint32
@@ -1913,7 +1950,7 @@ This API returns the C primitive equivalent of the given `napi_value` as a
`uint32_t`.
### Functions to get global instances
-#### *napi_get_boolean*
+#### napi_get_boolean
@@ -1931,7 +1968,7 @@ Returns `napi_ok` if the API succeeded.
This API is used to return the JavaScript singleton object that is used to
represent the given boolean value
-#### *napi_get_global*
+#### napi_get_global
@@ -1946,7 +1983,7 @@ Returns `napi_ok` if the API succeeded.
This API returns the global Object.
-#### *napi_get_null*
+#### napi_get_null
@@ -1961,7 +1998,7 @@ Returns `napi_ok` if the API succeeded.
This API returns the null Object.
-#### *napi_get_undefined*
+#### napi_get_undefined
@@ -1989,7 +2026,7 @@ These APIs support doing one of the following:
2. Check the type of a JavaScript value
3. Check for equality between two JavaScript values
-### *napi_coerce_to_bool*
+### napi_coerce_to_bool
@@ -2010,7 +2047,7 @@ This API implements the abstract operation ToBoolean as defined in
of the ECMAScript Language Specification.
This API can be re-entrant if getters are defined on the passed-in Object.
-### *napi_coerce_to_number*
+### napi_coerce_to_number
@@ -2031,7 +2068,7 @@ This API implements the abstract operation ToNumber as defined in
of the ECMAScript Language Specification.
This API can be re-entrant if getters are defined on the passed-in Object.
-### *napi_coerce_to_object*
+### napi_coerce_to_object
@@ -2052,7 +2089,7 @@ This API implements the abstract operation ToObject as defined in
of the ECMAScript Language Specification.
This API can be re-entrant if getters are defined on the passed-in Object.
-### *napi_coerce_to_string*
+### napi_coerce_to_string
@@ -2073,7 +2110,7 @@ This API implements the abstract operation ToString as defined in
of the ECMAScript Language Specification.
This API can be re-entrant if getters are defined on the passed-in Object.
-### *napi_typeof*
+### napi_typeof
@@ -2094,7 +2131,7 @@ the object as defined in [Section 12.5.5][] of the ECMAScript Language
Specification. However, it has support for detecting an External value.
If `value` has a type that is invalid, an error is returned.
-### *napi_instanceof*
+### napi_instanceof
@@ -2119,7 +2156,7 @@ defined in
[Section 12.10.4](https://tc39.github.io/ecma262/#sec-instanceofoperator)
of the ECMAScript Language Specification.
-### *napi_is_array*
+### napi_is_array
@@ -2137,7 +2174,7 @@ This API represents invoking the `IsArray` operation on the object
as defined in [Section 7.2.2](https://tc39.github.io/ecma262/#sec-isarray)
of the ECMAScript Language Specification.
-### *napi_is_arraybuffer*
+### napi_is_arraybuffer
@@ -2151,9 +2188,9 @@ napi_status napi_is_arraybuffer(napi_env env, napi_value value, bool* result)
Returns `napi_ok` if the API succeeded.
-This API checks if the Object passsed in is an array buffer.
+This API checks if the Object passed in is an array buffer.
-### *napi_is_buffer*
+### napi_is_buffer
@@ -2168,9 +2205,9 @@ object.
Returns `napi_ok` if the API succeeded.
-This API checks if the Object passsed in is a buffer.
+This API checks if the Object passed in is a buffer.
-### *napi_is_error*
+### napi_is_error
@@ -2184,9 +2221,9 @@ napi_status napi_is_error(napi_env env, napi_value value, bool* result)
Returns `napi_ok` if the API succeeded.
-This API checks if the Object passsed in is an Error.
+This API checks if the Object passed in is an Error.
-### *napi_is_typedarray*
+### napi_is_typedarray
@@ -2200,11 +2237,9 @@ napi_status napi_is_typedarray(napi_env env, napi_value value, bool* result)
Returns `napi_ok` if the API succeeded.
-This API checks if the Object passsed in is a typed array.
-
+This API checks if the Object passed in is a typed array.
-
-### *napi_is_dataview*
+### napi_is_dataview
@@ -2221,7 +2256,7 @@ Returns `napi_ok` if the API succeeded.
This API checks if the Object passed in is a DataView.
-### *napi_strict_equals*
+### napi_strict_equals
@@ -2364,8 +2399,8 @@ if (status != napi_ok) return status;
// Set the properties
napi_property_descriptor descriptors[] = {
- { "foo", nullptr, 0, 0, 0, fooValue, napi_default, 0 },
- { "bar", nullptr, 0, 0, 0, barValue, napi_default, 0 }
+ { "foo", NULL, 0, 0, 0, fooValue, napi_default, 0 },
+ { "bar", NULL, 0, 0, 0, barValue, napi_default, 0 }
}
status = napi_define_properties(env,
obj,
@@ -2375,7 +2410,7 @@ if (status != napi_ok) return status;
```
### Structures
-#### *napi_property_attributes*
+#### napi_property_attributes
```C
typedef enum {
napi_default = 0,
@@ -2409,7 +2444,7 @@ a static property on a class as opposed to an instance property, which is the
default. This is used only by [`napi_define_class`][]. It is ignored by
`napi_define_properties`.
-#### *napi_property_descriptor*
+#### napi_property_descriptor
```C
typedef struct {
// One of utf8name or name should be NULL.
@@ -2455,7 +2490,7 @@ this function is invoked.
See [`napi_property_attributes`](#n_api_napi_property_attributes).
### Functions
-#### *napi_get_property_names*
+#### napi_get_property_names
@@ -2474,9 +2509,9 @@ and [`napi_get_element`][].
Returns `napi_ok` if the API succeeded.
-This API returns the array of propertys for the Object passed in
+This API returns the array of properties for the Object passed in
-#### *napi_set_property*
+#### napi_set_property
@@ -2496,7 +2531,7 @@ Returns `napi_ok` if the API succeeded.
This API set a property on the Object passed in.
-#### *napi_get_property*
+#### napi_get_property
@@ -2517,7 +2552,7 @@ Returns `napi_ok` if the API succeeded.
This API gets the requested property from the Object passed in.
-#### *napi_has_property*
+#### napi_has_property
@@ -2538,7 +2573,7 @@ Returns `napi_ok` if the API succeeded.
This API checks if the Object passed in has the named property.
-#### *napi_delete_property*
+#### napi_delete_property
@@ -2560,7 +2595,7 @@ Returns `napi_ok` if the API succeeded.
This API attempts to delete the `key` own property from `object`.
-#### *napi_has_own_property*
+#### napi_has_own_property
@@ -2583,7 +2618,7 @@ be a string or a Symbol, or an error will be thrown. N-API will not perform any
conversion between data types.
-#### *napi_set_named_property*
+#### napi_set_named_property
@@ -2604,7 +2639,7 @@ Returns `napi_ok` if the API succeeded.
This method is equivalent to calling [`napi_set_property`][] with a `napi_value`
created from the string passed in as `utf8Name`
-#### *napi_get_named_property*
+#### napi_get_named_property
@@ -2625,7 +2660,7 @@ Returns `napi_ok` if the API succeeded.
This method is equivalent to calling [`napi_get_property`][] with a `napi_value`
created from the string passed in as `utf8Name`
-#### *napi_has_named_property*
+#### napi_has_named_property
@@ -2646,7 +2681,7 @@ Returns `napi_ok` if the API succeeded.
This method is equivalent to calling [`napi_has_property`][] with a `napi_value`
created from the string passed in as `utf8Name`
-#### *napi_set_element*
+#### napi_set_element
@@ -2666,7 +2701,7 @@ Returns `napi_ok` if the API succeeded.
This API sets and element on the Object passed in.
-#### *napi_get_element*
+#### napi_get_element
@@ -2686,7 +2721,7 @@ Returns `napi_ok` if the API succeeded.
This API gets the element at the requested index.
-#### *napi_has_element*
+#### napi_has_element
@@ -2707,7 +2742,7 @@ Returns `napi_ok` if the API succeeded.
This API returns if the Object passed in has an element at the
requested index.
-#### *napi_delete_element*
+#### napi_delete_element
@@ -2728,7 +2763,7 @@ Returns `napi_ok` if the API succeeded.
This API attempts to delete the specified `index` from `object`.
-#### *napi_define_properties*
+#### napi_define_properties
@@ -2771,7 +2806,7 @@ like a regular JavaScript function call, or as a constructor
function.
-### *napi_call_function*
+### napi_call_function
@@ -2837,7 +2872,7 @@ status = napi_get_value_int32(env, return_val, &result);
if (status != napi_ok) return;
```
-### *napi_create_function*
+### napi_create_function
@@ -2876,18 +2911,18 @@ object. A sample module might look as follows:
```C
napi_value SayHello(napi_env env, napi_callback_info info) {
printf("Hello\n");
- return nullptr;
+ return NULL;
}
napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_value fn;
- status = napi_create_function(env, nullptr, 0, SayHello, nullptr, &fn);
- if (status != napi_ok) return nullptr;
+ status = napi_create_function(env, NULL, 0, SayHello, nullptr, &fn);
+ if (status != napi_ok) return NULL;
status = napi_set_named_property(env, exports, "sayHello", fn);
- if (status != napi_ok) return nullptr;
+ if (status != napi_ok) return NULL;
return exports;
}
@@ -2905,7 +2940,7 @@ myaddon.sayHello();
`NAPI_MODULE` in the earlier snippet but the name of the target in `binding.gyp`
responsible for creating the `.node` file.
-### *napi_get_cb_info*
+### napi_get_cb_info
@@ -2935,7 +2970,7 @@ Returns `napi_ok` if the API succeeded.
This method is used within a callback function to retrieve details about the
call like the arguments and the `this` pointer from a given callback info.
-### *napi_get_new_target*
+### napi_get_new_target
@@ -2952,9 +2987,9 @@ napi_status napi_get_new_target(napi_env env,
Returns `napi_ok` if the API succeeded.
This API returns the `new.target` of the constructor call. If the current
-callback is not a constructor call, the result is `nullptr`.
+callback is not a constructor call, the result is `NULL`.
-### *napi_new_instance*
+### napi_new_instance
@@ -3034,7 +3069,7 @@ reference to the class constructor for later `instanceof` checks.
As an example:
```C
-napi_value MyClass_constructor = nullptr;
+napi_value MyClass_constructor = NULL;
status = napi_get_reference_value(env, MyClass::es_constructor, &MyClass_constructor);
assert(napi_ok == status);
bool is_instance = false;
@@ -3049,7 +3084,7 @@ if (is_instance) {
The reference must be freed once it is no longer needed.
-### *napi_define_class*
+### napi_define_class
@@ -3068,7 +3103,7 @@ napi_status napi_define_class(napi_env env,
- `[in] utf8name`: Name of the JavaScript constructor function; this is
not required to be the same as the C++ class name, though it is recommended
for clarity.
- - `[in] length`: The length of the utf8name in bytes, or NAPI_AUTO_LENGTH
+ - `[in] length`: The length of the utf8name in bytes, or `NAPI_AUTO_LENGTH`
if it is null-terminated.
- `[in] constructor`: Callback function that handles constructing instances
of the class. (This should be a static method on the class, not an actual
@@ -3105,7 +3140,7 @@ case, to prevent the function value from being garbage-collected, create a
persistent reference to it using [`napi_create_reference`][] and ensure the
reference count is kept >= 1.
-### *napi_wrap*
+### napi_wrap
@@ -3161,13 +3196,10 @@ required in order to enable correct proper of the reference.
Afterward, additional manipulation of the wrapper's prototype chain may cause
`napi_unwrap()` to fail.
-*Note*: Calling `napi_wrap()` a second time on an object that already has a
-native instance associated with it by virtue of a previous call to
-`napi_wrap()` will cause an error to be returned. If you wish to associate
-another native instance with the given object, call `napi_remove_wrap()` on it
-first.
+Calling napi_wrap() a second time on an object will return an error. To associate
+another native instance with the object, use napi_remove_wrap() first.
-### *napi_unwrap*
+### napi_unwrap
@@ -3192,7 +3224,7 @@ method or accessor, then the `this` argument to the callback is the wrapper
object; the wrapped C++ instance that is the target of the call can be obtained
then by calling `napi_unwrap()` on the wrapper object.
-### *napi_remove_wrap*
+### napi_remove_wrap
@@ -3283,12 +3315,14 @@ napi_status napi_create_async_work(napi_env env,
- `[in] env`: The environment that the API is invoked under.
- `[in] async_resource`: An optional object associated with the async work
that will be passed to possible async_hooks [`init` hooks][].
-- `[in] async_resource_name`: An identifier for the kind of resource that is
+- `[in] async_resource_name`: Identifier for the kind of resource that is
being provided for diagnostic information exposed by the `async_hooks` API.
-- `[in] execute`: The native function which should be called to excute
-the logic asynchronously.
+- `[in] execute`: The native function which should be called to execute
+the logic asynchronously. The given function is called from a worker pool
+thread and can execute in parallel with the main event loop thread.
- `[in] complete`: The native function which will be called when the
-asynchronous logic is comple or is cancelled.
+asynchronous logic is completed or is cancelled. The given function is called
+from the main event loop thread.
- `[in] data`: User-provided data context. This will be passed back into the
execute and complete functions.
- `[out] result`: `napi_async_work*` which is the handle to the newly created
@@ -3324,6 +3358,8 @@ Returns `napi_ok` if the API succeeded.
This API frees a previously allocated work object.
+This API can be called even if there is a pending JavaScript exception.
+
### napi_queue_async_work
@@ -3382,14 +3420,14 @@ napi_status napi_async_init(napi_env env,
- `[in] env`: The environment that the API is invoked under.
- `[in] async_resource`: An optional object associated with the async work
that will be passed to possible `async_hooks` [`init` hooks][].
-- `[in] async_resource_name`: Required identifier for the kind of resource
+- `[in] async_resource_name`: Identifier for the kind of resource
that is being provided for diagnostic information exposed by the
`async_hooks` API.
- `[out] result`: The initialized async context.
Returns `napi_ok` if the API succeeded.
-### *napi_async_destroy**
+### napi_async_destroy
@@ -3403,7 +3441,9 @@ napi_status napi_async_destroy(napi_env env,
Returns `napi_ok` if the API succeeded.
-### *napi_make_callback*
+This API can be called even if there is a pending JavaScript exception.
+
+### napi_make_callback
+```C
+NAPI_EXTERN napi_status napi_open_callback_scope(napi_env env,
+ napi_value resource_object,
+ napi_async_context context,
+ napi_callback_scope* result)
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] resource_object`: An optional object associated with the async work
+ that will be passed to possible async_hooks [`init` hooks][].
+- `[in] context`: Context for the async operation that is
+invoking the callback. This should be a value previously obtained
+from [`napi_async_init`][].
+- `[out] result`: The newly created scope.
+
+There are cases (for example resolving promises) where it is
+necessary to have the equivalent of the scope associated with a callback
+in place when making certain N-API calls. If there is no other script on
+the stack the [`napi_open_callback_scope`][] and
+[`napi_close_callback_scope`][] functions can be used to open/close
+the required scope.
+
+### *napi_close_callback_scope*
+
+```C
+NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,
+ napi_callback_scope scope)
+```
+- `[in] env`: The environment that the API is invoked under.
+- `[in] scope`: The scope to be closed.
+
+This API can be called even if there is a pending JavaScript exception.
+
## Version Management
### napi_get_node_version
@@ -3728,6 +3806,7 @@ NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env,
[`napi_async_init`]: #n_api_napi_async_init
[`napi_cancel_async_work`]: #n_api_napi_cancel_async_work
[`napi_close_escapable_handle_scope`]: #n_api_napi_close_escapable_handle_scope
+[`napi_close_callback_scope`]: #n_api_napi_close_callback_scope
[`napi_close_handle_scope`]: #n_api_napi_close_handle_scope
[`napi_create_async_work`]: #n_api_napi_create_async_work
[`napi_create_error`]: #n_api_napi_create_error
@@ -3753,6 +3832,7 @@ NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env,
[`napi_get_last_error_info`]: #n_api_napi_get_last_error_info
[`napi_get_and_clear_last_exception`]: #n_api_napi_get_and_clear_last_exception
[`napi_make_callback`]: #n_api_napi_make_callback
+[`napi_open_callback_scope`]: #n_api_napi_open_callback_scope
[`napi_open_escapable_handle_scope`]: #n_api_napi_open_escapable_handle_scope
[`napi_open_handle_scope`]: #n_api_napi_open_handle_scope
[`napi_property_descriptor`]: #n_api_napi_property_descriptor
diff --git a/lib/internal/errors.js b/lib/internal/errors.js
index 9a1bc0ee38d519..7dbcce28ce6d00 100644
--- a/lib/internal/errors.js
+++ b/lib/internal/errors.js
@@ -262,6 +262,12 @@ E('ERR_MODULE_RESOLUTION_LEGACY', '%s not found by import in %s.' +
' Legacy behavior in require() would have found it at %s');
E('ERR_NAPI_CONS_FUNCTION', 'Constructor must be a function');
E('ERR_NAPI_CONS_PROTOTYPE_OBJECT', 'Constructor.prototype must be an object');
+E('ERR_NAPI_INVALID_DATAVIEW_ARGS',
+ 'byte_offset + byte_length should be less than or eqaul to the size in ' +
+ 'bytes of the array passed in');
+E('ERR_NAPI_INVALID_TYPEDARRAY_ALIGNMENT', 'start offset of %s should be a ' +
+ 'multiple of %s');
+E('ERR_NAPI_INVALID_TYPEDARRAY_LENGTH', 'Invalid typed array length');
E('ERR_NO_CRYPTO', 'Node.js is not compiled with OpenSSL crypto support');
E('ERR_NO_ICU', '%s is not supported on Node.js compiled without ICU');
E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s');
diff --git a/src/env.h b/src/env.h
index 6113e6d2de26ea..0dc180bf7489e1 100644
--- a/src/env.h
+++ b/src/env.h
@@ -93,6 +93,8 @@ class ModuleWrap;
V(processed_private_symbol, "node:processed") \
V(selected_npn_buffer_private_symbol, "node:selectedNpnBuffer") \
V(domain_private_symbol, "node:domain") \
+ V(napi_env, "node:napi:env") \
+ V(napi_wrapper, "node:napi:wrapper") \
// Strings are per-isolate primitives but Environment proxies them
// for the sake of convenience. Strings should be ASCII-only.
diff --git a/src/node.cc b/src/node.cc
index d17752bbad38f5..67c8a808ffb00e 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -3374,6 +3374,12 @@ void SetupProcessObject(Environment* env,
"nghttp2",
FIXED_ONE_BYTE_STRING(env->isolate(), NGHTTP2_VERSION));
+ const char node_napi_version[] = NODE_STRINGIFY(NAPI_VERSION);
+ READONLY_PROPERTY(
+ versions,
+ "napi",
+ FIXED_ONE_BYTE_STRING(env->isolate(), node_napi_version));
+
// process._promiseRejectEvent
Local