Skip to content

Commit

Permalink
doc: clarify that N-API addons are context-aware
Browse files Browse the repository at this point in the history
The docs on N-API say that NAPI_MODULE_INIT must
be used for the addon to be context-aware. That seems
to be wrong, i.e. all N-API addons are context-aware(?)

PR-URL: #36640
Reviewed-By: Franziska Hinkelmann <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
mildsunrise authored and targos committed May 1, 2021
1 parent 8f48e77 commit 844a156
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1841,8 +1841,8 @@ napi_value Init(napi_env env, napi_value exports) {
}
```

If the module will be loaded multiple times during the lifetime of the Node.js
process, use the `NAPI_MODULE_INIT` macro to initialize the module:
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() {
Expand All @@ -1859,13 +1859,9 @@ NAPI_MODULE_INIT() {
}
```

This macro includes `NAPI_MODULE`, and declares an `Init` function with a
special name and with visibility beyond the addon. This will allow Node.js to
initialize the module even if it is loaded multiple times.

There are a few design considerations when declaring a module that may be loaded
multiple times. The documentation of [context-aware addons][] provides more
details.
All N-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.

The variables `env` and `exports` will be available inside the function body
following the macro invocation.
Expand Down

0 comments on commit 844a156

Please sign in to comment.