Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
e54ddf8
src: support configurable snapshot
joyeecheung Oct 28, 2023
efa13e1
doc: add documentation for --build-snapshot-config
addaleax Nov 16, 2023
e2f8d74
deps: update zlib to 1.3.0.1-motley-dd5fc13
nodejs-github-bot Dec 16, 2023
2c227b0
doc: fix simdjson wrong link
marco-ippolito Dec 16, 2023
3f4fd6e
watch: fix infinite loop when passing --watch=true flag
pulkit-30 Dec 16, 2023
e5017a5
crypto: update CryptoKey symbol properties
panva Nov 25, 2023
13a1241
assert,crypto: make KeyObject and CryptoKey testable for equality
panva Nov 24, 2023
63db82a
test_runner: fixed to run after hook if before throws an error
pulkit-30 Dec 17, 2023
89eee77
http2: addtl http/2 settings
martenrichter Dec 18, 2023
1c71435
doc: fix `TestsStream` parent class
Dec 18, 2023
e636d83
doc: correct note on behavior of stats.isDirectory
NReilingh Dec 18, 2023
5b229d7
fs: validate fd synchronously on c++
anonrig Dec 18, 2023
df8927a
doc: mention native addons are restricted in pm
RafaelGSS Dec 19, 2023
c96ef65
tools: update eslint to 8.56.0
nodejs-github-bot Dec 19, 2023
b2135ae
node-api: segregate nogc APIs from rest via type system
gabrielschulhof Dec 19, 2023
a325746
http: do not override user-provided options object
KuthorX Dec 19, 2023
f9d4e07
doc: remove version from `maintaining-dependencies.md`
aduh95 Dec 19, 2023
d0d2faf
tools: update lint-md-dependencies to [email protected]
nodejs-github-bot Dec 19, 2023
3ecc7dc
deps: update acorn-walk to 8.3.0
nodejs-github-bot Oct 29, 2023
75e5615
deps: update acorn-walk to 8.3.1
nodejs-github-bot Dec 10, 2023
8a2dd93
src: implement FastByteLengthUtf8 with simdutf::utf8_length_from_latin1
lemire Dec 19, 2023
d7c2572
test: fix flakiness in worker*.test-free-called
MrJithil Dec 19, 2023
5453abd
doc: set exit code in custom test runner example
mcollina Dec 20, 2023
7421467
fs: improve mkdtemp performance for buffer prefix
anonrig Dec 20, 2023
6d1bfcb
deps: update googletest to 530d5c8
nodejs-github-bot Dec 20, 2023
a07d6e2
deps: update simdjson to 3.6.3
nodejs-github-bot Dec 10, 2023
3759491
tools: check timezone current version
marco-ippolito Dec 20, 2023
7e9a0b1
test: use tmpdir.refresh() in test-esm-json.mjs
lpinca Dec 20, 2023
8a2178c
test: use tmpdir.refresh() in test-esm-loader-resolve-type.mjs
lpinca Dec 20, 2023
4b19e62
doc: remove ambiguous 'considered'
Trott Dec 20, 2023
e4be5b6
net: add connection attempt events
ShogunPanda Dec 21, 2023
83a99cc
meta: update artifact actions to v4
targos Dec 21, 2023
c13a5c0
doc: mention node:wasi in the Threat Model
RafaelGSS Dec 21, 2023
b6f232e
test: add URL tests to fs-read in pm
RafaelGSS Dec 21, 2023
7e98349
test: replace forEach with for-of in test-v8-serders.js
iannonoss Dec 21, 2023
3310095
repl: fix prepareStackTrace frames array order
legendecas Nov 21, 2023
291265c
lib: expose default prepareStackTrace
legendecas Nov 20, 2023
ec6fcff
doc: fix limitations and known issues in pm
RafaelGSS Dec 21, 2023
8f4325d
permission: fix wildcard when children > 1
RafaelGSS Dec 21, 2023
8ff6bc4
lib,permission: handle buffer on fs.symlink
RafaelGSS Dec 21, 2023
a69c7d7
src,permission: add --allow-addon flag
RafaelGSS Dec 21, 2023
25eba3d
deps: V8: cherry-pick de611e69ad51
kvakil Dec 21, 2023
c7a1359
http: remove misleading warning
lpinca Dec 21, 2023
e24249c
fs: remove `internalModuleReadJSON` binding
anonrig Dec 21, 2023
c87e5d5
fs: add missing jsdoc parameters to `readSync`
anonrig Dec 21, 2023
9bfd84c
test: replace forEach with for of in test-trace-events-api.js
andp97 Nov 18, 2023
b621ada
module: move the CJS exports cache to internal/modules/cjs/loader
joyeecheung Dec 14, 2023
f1cb583
test: replace forEach() with for...of in test/parallel/test-util-log.js
edodusi Nov 18, 2023
38232d1
test: replace forEach with for of in file test-trace-events-net.js
Ianna83 Nov 18, 2023
3db376f
test: skip test-watch-mode-inspect on arm
mhdawson Dec 22, 2023
876743e
doc: run license-builder
github-actions[bot] Dec 22, 2023
88e8651
test: move to for of loop in test-http-hostname-typechecking.js
Puppo Dec 22, 2023
57c6455
test: replace forEach with for-of in test-webcrypto-export-import-ec
cricciardi Dec 22, 2023
3a49205
node-api: type tag external values without v8::Private
legendecas Dec 22, 2023
e5a8fa0
fs: make offset, position & length args in fh.read() optional
pulkit-30 Dec 22, 2023
96d64ed
src: use BignumPointer and use BN_clear_free
jasnell Oct 28, 2023
ed7305e
lib: reduce overhead of `SafePromiseAllSettledReturnVoid` calls
aduh95 Dec 22, 2023
6648a5c
meta: notify tsc on changes in SECURITY.md
RafaelGSS Dec 22, 2023
8f845eb
lib: move function declaration outside of loop
sanjaiyan-dev Dec 23, 2023
efa12a8
deps: update simdutf to 4.0.8
nodejs-github-bot Dec 23, 2023
c31ed51
timers: export timers.promises
marco-ippolito Dec 23, 2023
8ee882a
doc: mark `--jitless` as experimental
aduh95 Dec 23, 2023
6241429
lib: fix use of `--frozen-intrinsics` with `--jitless`
aduh95 Dec 23, 2023
17c73e6
src: fix unix abstract socket path for trace event
theanarkh Dec 23, 2023
941aedc
errors: fix stacktrace of SystemError
Uzlopak Sep 29, 2023
aaf710f
test: replace forEach test-http-server-multiheaders2
mmachera Nov 18, 2023
8412751
doc: improve localWindowSize event descriptions
DavyLandman Dec 6, 2023
47548d9
esm: fix hint on invalid module specifier
aduh95 Dec 23, 2023
979cebc
test_runner: fixed test object is incorrectly passed to setup()
pulkit-30 Dec 24, 2023
917d887
tools: update lint-md-dependencies to [email protected]
nodejs-github-bot Dec 24, 2023
cd61fce
build: add `-flax-vector-conversions` to V8 build
targos Dec 24, 2023
e443953
stream: fix cloned webstreams not being unref'd
jasnell Dec 24, 2023
df31c81
src: eliminate duplicate code in histogram.cc
jasnell Dec 25, 2023
684dd9d
test: fix inconsistency write size in `test-fs-readfile-tostring-fail`
Dec 25, 2023
f4f781d
util: pass invalidSubtypeIndex instead of trimmedSubtype to error
gaurishhs Dec 25, 2023
864ecb0
src: do not treat all paths ending with node_modules as such
targos Dec 25, 2023
54dd978
src: enter isolate before destructing IsolateData
bnoordhuis Dec 25, 2023
4dcc511
benchmark: remove dependency on unshipped tools
AdamMajer Dec 13, 2023
a41dca0
deps: update zlib to 1.3.0.1-motley-40e35a7
nodejs-github-bot Dec 26, 2023
82de660
stream: fix code style
MattiasBuelens Dec 26, 2023
5b32e21
quic: add quic internalBinding, refine Endpoint, add types
jasnell Dec 9, 2023
e03ac83
build: fix arm64 cross-compilation
targos Dec 27, 2023
f00f120
deps: update brotli to 1.1.0
nodejs-github-bot Dec 27, 2023
29b8157
src: refactor `GetCreationContext` calls
anonrig Dec 28, 2023
652af45
test: replace forEach() with for...of
JJJ54321 Nov 7, 2023
091098f
fs: fix fs.promises.realpath for long paths on Windows
sapphi-red Dec 28, 2023
4a5d3bd
doc: the GN files should use Node's license
zcbenz Dec 28, 2023
56e8969
watch: fix null `fileName` on windows systems
vnc5 Dec 28, 2023
c3126fc
tools: update inspector_protocol to ca525fc
cola119 Dec 27, 2023
ef4f46f
tools: update inspector_protocol to 547c5b8
cola119 Dec 27, 2023
d181684
tools: update inspector_protocol to 912eb68
cola119 Dec 27, 2023
60d8048
tools: update inspector_protocol to d7b099b
cola119 Dec 27, 2023
e325f49
tools: update inspector_protocol to 2f51e05
cola119 Dec 27, 2023
69a46ad
tools: update inspector_protocol to 9b4a4aa
cola119 Dec 27, 2023
bdcb5ed
tools: update inspector_protocol to c488ba2
cola119 Dec 27, 2023
d5a5f12
tools: fix dep_updaters dir updates
targos Dec 29, 2023
e53cbb2
deps: update ngtcp2 and nghttp3
jasnell Dec 26, 2023
7ecf994
quic: update quic impl to use latest ngtcp2/nghttp3
jasnell Dec 26, 2023
115e058
src: add fast api for Histogram
jasnell Dec 29, 2023
ef44f9b
test: replace foreach with for of
lucacapocci94-dev Dec 29, 2023
549e4b4
test: replace forEach with for...of
Nov 18, 2023
85ee2f7
test: replace forEach() with for...of
Nov 10, 2023
e7925e6
src,stream: improve WriteString
ywave620 Dec 30, 2023
416b4f8
lib,src,permission: port path.resolve to C++
RafaelGSS Dec 30, 2023
867b484
watch: clarify that the fileName parameter can be null
lpinca Dec 30, 2023
2eb41f8
build: fix for VScode "Reopen in Container"
ohhmm Dec 31, 2023
24a9a72
deps: update acorn to 8.11.3
nodejs-github-bot Jan 2, 2024
c0d2e8b
deps: update corepack to 0.24.0
nodejs-github-bot Jan 2, 2024
fc10f88
tools: update lint-md-dependencies to [email protected]
nodejs-github-bot Jan 2, 2024
a0ff00b
src: avoid draining platform tasks at FreeEnvironment
legendecas Jan 8, 2024
757a84c
test: fix flaky conditions for ppc64 SEA tests
richardlau Jan 11, 2024
f38a9a5
2024-01-15, Version 21.6.0 (Current)
RafaelGSS Jan 2, 2024
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
Prev Previous commit
Next Next commit
node-api: segregate nogc APIs from rest via type system
We define a new type called `node_api_nogc_env` as the `const` version
of `napi_env` and `node_api_nogc_finalize` as a variant of
`napi_finalize` that accepts a `node_api_nogc_env` as its first
argument.

We then modify those APIs which do not affect GC state as accepting a
`node_api_nogc_env`. APIs accepting finalizer callbacks are modified to
accept `node_api_nogc_finalize` callbacks. Thus, the only way to attach
a `napi_finalize` callback, wherein Node-APIs affecting GC state may be
called is to call `node_api_post_finalizer` from a
`node_api_nogc_finalize` callback.

In keeping with the process of introducing new Node-APIs, this feature
is guarded by `NAPI_EXPERIMENTAL`. Since this feature modifies APIs
already marked as stable, it is additionally guared by
`NODE_API_EXPERIMENTAL_NOGC_ENV`, so as to provide a further buffer to
adoption. Nevertheless, both guards must be removed upon releasing a
new version of Node-API.

PR-URL: #50060
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Vladimir Morozov <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
gabrielschulhof authored and RafaelGSS committed Jan 2, 2024
commit b2135ae7dcf62a29f6cf293d52d78005f0e455a7
139 changes: 103 additions & 36 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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 [Node-API Resource](https://nodejs.github.io/node-addon-examples/) offers
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`. Additional media resources can be found on the
[Node-API Media][] page.
Expand Down Expand Up @@ -175,7 +175,8 @@ developers have run into limitations in node-gyp.
[CMake.js][] is an alternative build system based on [CMake][].

CMake.js is a good choice for projects that already use CMake or for
developers affected by limitations in node-gyp.
developers affected by limitations in node-gyp. [`build_with_cmake`][] is an
example of a CMake-based native addon project.

### Uploading precompiled binaries

Expand Down Expand Up @@ -237,6 +238,18 @@ Some of the Node-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.

Occasionally, experimental features are introduced that affect already-released
and stable APIs. These features can be disabled by an opt-out:

```c
#define NAPI_EXPERIMENTAL
#define NODE_API_EXPERIMENTAL_<FEATURE_NAME>_OPT_OUT
#include <node_api.h>
```

where `<FEATURE_NAME>` is the name of an experimental feature that affects both
experimental and stable APIs.

## Node-API version matrix

Up until version 9, Node-API versions were additive and versioned
Expand Down Expand Up @@ -419,7 +432,7 @@ napi_value create_addon(napi_env env) {
#include <node_api.h>
#include "addon.h"

NAPI_MODULE_INIT() {
NAPI_MODULE_INIT(/* napi_env env, napi_value exports */) {
// This function body is expected to return a `napi_value`.
// The variables `napi_env env` and `napi_value exports` may be used within
// the body, as they are provided by the definition of `NAPI_MODULE_INIT()`.
Expand Down Expand Up @@ -464,7 +477,7 @@ napiVersion: 6
-->

```c
napi_status napi_set_instance_data(napi_env env,
napi_status napi_set_instance_data(node_api_nogc_env env,
void* data,
napi_finalize finalize_cb,
void* finalize_hint);
Expand Down Expand Up @@ -496,7 +509,7 @@ napiVersion: 6
-->

```c
napi_status napi_get_instance_data(napi_env env,
napi_status napi_get_instance_data(node_api_nogc_env env,
void** data);
```

Expand Down Expand Up @@ -598,6 +611,22 @@ when an instance of a native addon is unloaded. Notification of this event is
delivered through the callbacks given to [`napi_add_env_cleanup_hook`][] and
[`napi_set_instance_data`][].

### `node_api_nogc_env`

> Stability: 1 - Experimental

This variant of `napi_env` is passed to synchronous finalizers
([`node_api_nogc_finalize`][]). There is a subset of Node-APIs which accept
a parameter of type `node_api_nogc_env` as their first argument. These APIs do
not access the state of the JavaScript engine and are thus safe to call from
synchronous finalizers. Passing a parameter of type `napi_env` to these APIs is
allowed, however, passing a parameter of type `node_api_nogc_env` to APIs that
access the JavaScript engine state is not allowed. Attempting to do so without
a cast will produce a compiler warning or an error when add-ons are compiled
with flags which cause them to emit warnings and/or errors when incorrect
pointer types are passed into a function. Calling such APIs from a synchronous
finalizer will ultimately result in the termination of the application.

### `napi_value`

This is an opaque pointer that is used to represent a JavaScript value.
Expand Down Expand Up @@ -762,32 +791,36 @@ typedef napi_value (*napi_callback)(napi_env, napi_callback_info);
Unless for reasons discussed in [Object Lifetime Management][], creating a
handle and/or callback scope inside a `napi_callback` is not necessary.

#### `napi_finalize`
#### `node_api_nogc_finalize`

<!-- YAML
added: v8.0.0
napiVersion: 1
added: REPLACEME
-->

> Stability: 1 - Experimental

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
must provide a function satisfying the following signature which would get
called upon the object's collection. Currently, `napi_finalize` can be used for
object it was associated with has been garbage-collected. The user must provide
a function satisfying the following signature which would get called upon the
object's collection. Currently, `node_api_nogc_finalize` can be used for
finding out when objects that have external data are collected.

```c
typedef void (*napi_finalize)(napi_env env,
void* finalize_data,
void* finalize_hint);
typedef void (*node_api_nogc_finalize)(node_api_nogc_env env,
void* finalize_data,
void* finalize_hint);
```

Unless for reasons discussed in [Object Lifetime Management][], creating a
handle and/or callback scope inside the function body is not necessary.

Since these functions may be called while the JavaScript engine is in a state
where it cannot execute JavaScript code, some Node-API calls may return
`napi_pending_exception` even when there is no exception pending.
where it cannot execute JavaScript code, only Node-APIs which accept a
`node_api_nogc_env` as their first parameter may be called.
[`node_api_post_finalizer`][] can be used to schedule Node-API calls that
require access to the JavaScript engine's state to run after the current
garbage collection cycle has completed.

In the case of [`node_api_create_external_string_latin1`][] and
[`node_api_create_external_string_utf16`][] the `env` parameter may be null,
Expand All @@ -796,11 +829,39 @@ shutdown.

Change History:

* experimental (`NAPI_EXPERIMENTAL`):

Only Node-API calls that accept a `node_api_nogc_env` as their first
parameter may be called, otherwise the application will be terminated with an
appropriate error message. This feature can be turned off by defining
`NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT`.

#### `napi_finalize`

<!-- YAML
added: v8.0.0
napiVersion: 1
-->

Function pointer type for add-on provided function that allow the user to
schedule a group of calls to Node-APIs in response to a garbage collection
event, after the garbage collection cycle has completed. These function
pointers can be used with [`node_api_post_finalizer`][].

```c
typedef void (*napi_finalize)(napi_env env,
void* finalize_data,
void* finalize_hint);
```

Change History:

* experimental (`NAPI_EXPERIMENTAL` is defined):

Node-API calls made from a finalizer will return `napi_cannot_run_js` when
the JavaScript engine is unable to execute JavaScript, and will return
`napi_exception_pending` if there is a pending exception.
A function of this type may no longer be used as a finalizer, except with
[`node_api_post_finalizer`][]. [`node_api_nogc_finalize`][] must be used
instead. This feature can be turned off by defining
`NODE_API_EXPERIMENTAL_NOGC_ENV_OPT_OUT`.

#### `napi_async_execute_callback`

Expand Down Expand Up @@ -1002,7 +1063,7 @@ napiVersion: 1

```c
napi_status
napi_get_last_error_info(napi_env env,
napi_get_last_error_info(node_api_nogc_env env,
const napi_extended_error_info** result);
```

Expand Down Expand Up @@ -1821,7 +1882,7 @@ napiVersion: 3
-->

```c
NODE_EXTERN napi_status napi_add_env_cleanup_hook(napi_env env,
NODE_EXTERN napi_status napi_add_env_cleanup_hook(node_api_nogc_env env,
napi_cleanup_hook fun,
void* arg);
```
Expand Down Expand Up @@ -1851,7 +1912,7 @@ napiVersion: 3
-->

```c
NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env,
NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(node_api_nogc_env env,
void (*fun)(void* arg),
void* arg);
```
Expand Down Expand Up @@ -1880,7 +1941,7 @@ changes:

```c
NAPI_EXTERN napi_status napi_add_async_cleanup_hook(
napi_env env,
node_api_nogc_env env,
napi_async_cleanup_hook hook,
void* arg,
napi_async_cleanup_hook_handle* remove_handle);
Expand Down Expand Up @@ -2038,7 +2099,7 @@ You can also use the `NAPI_MODULE_INIT` macro, which acts as a shorthand
for `NAPI_MODULE` and defining an `Init` function:

```c
NAPI_MODULE_INIT() {
NAPI_MODULE_INIT(/* napi_env env, napi_value exports */) {
napi_value answer;
napi_status result;

Expand All @@ -2052,6 +2113,9 @@ NAPI_MODULE_INIT() {
}
```

The parameters `env` and `exports` are provided to the body of the
`NAPI_MODULE_INIT` macro.

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.
Expand Down Expand Up @@ -5420,7 +5484,7 @@ napiVersion: 5
napi_status napi_add_finalizer(napi_env env,
napi_value js_object,
void* finalize_data,
napi_finalize finalize_cb,
node_api_nogc_finalize finalize_cb,
void* finalize_hint,
napi_ref* result);
```
Expand Down Expand Up @@ -5458,7 +5522,7 @@ added: v21.0.0
> Stability: 1 - Experimental

```c
napi_status node_api_post_finalizer(napi_env env,
napi_status node_api_post_finalizer(node_api_nogc_env env,
napi_finalize finalize_cb,
void* finalize_data,
void* finalize_hint);
Expand Down Expand Up @@ -5528,7 +5592,7 @@ Once created the async worker can be queued
for execution using the [`napi_queue_async_work`][] function:

```c
napi_status napi_queue_async_work(napi_env env,
napi_status napi_queue_async_work(node_api_nogc_env env,
napi_async_work work);
```

Expand Down Expand Up @@ -5620,7 +5684,7 @@ napiVersion: 1
-->

```c
napi_status napi_queue_async_work(napi_env env,
napi_status napi_queue_async_work(node_api_nogc_env env,
napi_async_work work);
```

Expand All @@ -5641,7 +5705,7 @@ napiVersion: 1
-->

```c
napi_status napi_cancel_async_work(napi_env env,
napi_status napi_cancel_async_work(node_api_nogc_env env,
napi_async_work work);
```

Expand Down Expand Up @@ -5845,7 +5909,7 @@ typedef struct {
const char* release;
} napi_node_version;

napi_status napi_get_node_version(napi_env env,
napi_status napi_get_node_version(node_api_nogc_env env,
const napi_node_version** version);
```

Expand All @@ -5868,7 +5932,7 @@ napiVersion: 1
-->

```c
napi_status napi_get_version(napi_env env,
napi_status napi_get_version(node_api_nogc_env env,
uint32_t* result);
```

Expand Down Expand Up @@ -5901,7 +5965,7 @@ napiVersion: 1
-->

```c
NAPI_EXTERN napi_status napi_adjust_external_memory(napi_env env,
NAPI_EXTERN napi_status napi_adjust_external_memory(node_api_nogc_env env,
int64_t change_in_bytes,
int64_t* result);
```
Expand Down Expand Up @@ -6118,7 +6182,7 @@ napiVersion: 2
-->

```c
NAPI_EXTERN napi_status napi_get_uv_event_loop(napi_env env,
NAPI_EXTERN napi_status napi_get_uv_event_loop(node_api_nogc_env env,
struct uv_loop_s** loop);
```

Expand Down Expand Up @@ -6432,7 +6496,7 @@ napiVersion: 4

```c
NAPI_EXTERN napi_status
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
napi_ref_threadsafe_function(node_api_nogc_env env, napi_threadsafe_function func);
```

* `[in] env`: The environment that the API is invoked under.
Expand All @@ -6458,7 +6522,7 @@ napiVersion: 4

```c
NAPI_EXTERN napi_status
napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
napi_unref_threadsafe_function(node_api_nogc_env env, napi_threadsafe_function func);
```

* `[in] env`: The environment that the API is invoked under.
Expand All @@ -6484,7 +6548,7 @@ napiVersion: 9

```c
NAPI_EXTERN napi_status
node_api_get_module_file_name(napi_env env, const char** result);
node_api_get_module_file_name(node_api_nogc_env env, const char** result);

```

Expand Down Expand Up @@ -6548,6 +6612,7 @@ the add-on's file name during loading.
[`Number.MIN_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.min_safe_integer
[`Worker`]: worker_threads.md#class-worker
[`async_hooks.executionAsyncResource()`]: async_hooks.md#async_hooksexecutionasyncresource
[`build_with_cmake`]: https://github.com/nodejs/node-addon-examples/tree/main/build_with_cmake
[`global`]: globals.md#global
[`init` hooks]: async_hooks.md#initasyncid-type-triggerasyncid-resource
[`napi_add_async_cleanup_hook`]: #napi_add_async_cleanup_hook
Expand Down Expand Up @@ -6611,6 +6676,8 @@ the add-on's file name during loading.
[`node_api_create_external_string_latin1`]: #node_api_create_external_string_latin1
[`node_api_create_external_string_utf16`]: #node_api_create_external_string_utf16
[`node_api_create_syntax_error`]: #node_api_create_syntax_error
[`node_api_nogc_finalize`]: #node_api_nogc_finalize
[`node_api_post_finalizer`]: #node_api_post_finalizer
[`node_api_throw_syntax_error`]: #node_api_throw_syntax_error
[`process.release`]: process.md#processrelease
[`uv_ref`]: https://docs.libuv.org/en/v1.x/handle.html#c.uv_ref
Expand Down
13 changes: 13 additions & 0 deletions doc/contributing/adding-new-napi-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@ Node-API.
to the decision to take an API out of experimental status.
* The API **must** be implemented in a Node.js implementation with an
alternate VM.

Since the adoption of the policy whereby moving to a later version of Node-API
from an earlier version may entail rework of existing code, it is possible to
introduce modifications to already-released Node-APIs, as long as the
modifications affect neither the ABI nor the API of earlier versions. Such
modifications **must** be accompanied by an opt-out flag. This provides add-on
maintainers who take advantage of the initial compile-time flag to track
impending changes to Node-API with

* a quick fix to the breakage caused,
* a notification that such breakage is impending, and thus
* a buffer to adoption above and beyond the one provided by the initial
compile-time flag.
Loading