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

[v10.x] Backport N-API 6 to v10.x #32488

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ tied to the life cycle of the Agent.
### napi_set_instance_data
<!-- YAML
added: REPLACEME
napiVersion: 6
-->

```C
Expand Down Expand Up @@ -216,6 +217,7 @@ by the previous call, it will not be called.
### napi_get_instance_data
<!-- YAML
added: REPLACEME
napiVersion: 6
-->

```C
Expand Down Expand Up @@ -1375,10 +1377,9 @@ the `napi_value` in question is of the JavaScript type expected by the API.
#### napi_key_collection_mode
<!-- YAML
added: REPLACEME
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
typedef enum {
napi_key_include_prototypes,
Expand All @@ -1397,10 +1398,9 @@ of the objects's prototype chain as well.
#### napi_key_filter
<!-- YAML
added: REPLACEME
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
typedef enum {
napi_key_all_properties = 0,
Expand All @@ -1417,10 +1417,9 @@ Property filter bits. They can be or'ed to build a composite filter.
#### napi_key_conversion
<!-- YAML
added: REPLACEME
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
typedef enum {
napi_key_keep_numbers,
Expand Down Expand Up @@ -1940,10 +1939,9 @@ The JavaScript `Number` type is described in
#### napi_create_bigint_int64
<!-- YAML
added: v10.7.0
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
napi_status napi_create_bigint_int64(napi_env env,
int64_t value,
Expand All @@ -1961,10 +1959,9 @@ This API converts the C `int64_t` type to the JavaScript `BigInt` type.
#### napi_create_bigint_uint64
<!-- YAML
added: v10.7.0
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
napi_status napi_create_bigint_uint64(napi_env env,
uint64_t value,
Expand All @@ -1982,10 +1979,9 @@ This API converts the C `uint64_t` type to the JavaScript `BigInt` type.
#### napi_create_bigint_words
<!-- YAML
added: v10.7.0
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
napi_status napi_create_bigint_words(napi_env env,
int sign_bit,
Expand Down Expand Up @@ -2319,10 +2315,9 @@ This API returns the C double primitive equivalent of the given JavaScript
#### napi_get_value_bigint_int64
<!-- YAML
added: v10.7.0
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
napi_status napi_get_value_bigint_int64(napi_env env,
napi_value value,
Expand All @@ -2347,10 +2342,9 @@ This API returns the C `int64_t` primitive equivalent of the given JavaScript
#### napi_get_value_bigint_uint64
<!-- YAML
added: v10.7.0
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
napi_status napi_get_value_bigint_uint64(napi_env env,
napi_value value,
Expand All @@ -2375,10 +2369,9 @@ This API returns the C `uint64_t` primitive equivalent of the given JavaScript
#### napi_get_value_bigint_words
<!-- YAML
added: v10.7.0
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
napi_status napi_get_value_bigint_words(napi_env env,
napi_value value,
Expand Down Expand Up @@ -3189,10 +3182,9 @@ included.
#### napi_get_all_property_names
<!-- YAML
added: REPLACEME
napiVersion: 6
-->

> Stability: 1 - Experimental

```C
napi_get_all_property_names(napi_env env,
napi_value object,
Expand Down
6 changes: 3 additions & 3 deletions src/node_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define NAPI_VERSION 2147483647
#else
// The baseline version for N-API
#define NAPI_VERSION 5
#define NAPI_VERSION 6
#endif
#endif

Expand Down Expand Up @@ -699,7 +699,7 @@ NAPI_EXTERN napi_status napi_add_finalizer(napi_env env,

#endif // NAPI_VERSION >= 5

#ifdef NAPI_EXPERIMENTAL
#if NAPI_VERSION >= 6

// BigInt
NAPI_EXTERN napi_status napi_create_bigint_int64(napi_env env,
Expand Down Expand Up @@ -745,7 +745,7 @@ napi_get_all_property_names(napi_env env,
napi_key_conversion key_conversion,
napi_value* result);

#endif // NAPI_EXPERIMENTAL
#endif // NAPI_VERSION >= 6

EXTERN_C_END

Expand Down
4 changes: 2 additions & 2 deletions src/node_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ typedef struct {
const char* release;
} napi_node_version;

#ifdef NAPI_EXPERIMENTAL
#if NAPI_VERSION >= 6
typedef enum {
napi_key_include_prototypes,
napi_key_own_only
Expand All @@ -166,6 +166,6 @@ typedef enum {
napi_key_keep_numbers,
napi_key_numbers_to_strings
} napi_key_conversion;
#endif
#endif // NAPI_VERSION >= 6

#endif // SRC_NODE_API_TYPES_H_
5 changes: 3 additions & 2 deletions src/node_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
*/
#define NODE_MODULE_VERSION 64

// the NAPI_VERSION provided by this version of the runtime
#define NAPI_VERSION 5
// The NAPI_VERSION provided by this version of the runtime. This is the version
// which the Node binary being built supports.
#define NAPI_VERSION 6

#endif // SRC_NODE_VERSION_H_
2 changes: 0 additions & 2 deletions test/addons-napi/test_bigint/test_bigint.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define NAPI_EXPERIMENTAL

#include <inttypes.h>
#include <stdio.h>
#include <node_api.h>
Expand Down
2 changes: 1 addition & 1 deletion test/addons-napi/test_general/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ assert.notStrictEqual(test_general.testGetPrototype(baseObject),

// test version management functions
// expected version is currently 4
assert.strictEqual(test_general.testGetVersion(), 5);
assert.strictEqual(test_general.testGetVersion(), 6);

const [ major, minor, patch, release ] = test_general.testGetNodeVersion();
assert.strictEqual(process.version.split('-')[0],
Expand Down
14 changes: 14 additions & 0 deletions test/addons-napi/test_instance_data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ if (module.parent) {
// Test that the instance data can be accessed from a finalizer.
test_instance_data.objectWithFinalizer(common.mustCall());
global.gc();

// Test that instance data can be used in an async work callback.
new Promise((resolve) => test_instance_data.asyncWorkCallback(resolve))

// Test that the buffer finalizer can access the instance data.
.then(() => new Promise((resolve) => {
test_instance_data.testBufferFinalizer(resolve);
global.gc();
}))

// Test that the thread-safe function can access the instance data.
.then(() => new Promise((resolve) =>
test_instance_data.testThreadsafeFunction(common.mustCall(),
common.mustCall(resolve))));
} else {
// When launched as a script, run tests in either a child process or in a
// worker thread.
Expand Down
Loading