Skip to content

Commit 844a156

Browse files
mildsunrisetargos
authored andcommittedMay 1, 2021
doc: clarify that N-API addons are context-aware
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 <franziska.hinkelmann@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 8f48e77 commit 844a156

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed
 

‎doc/api/n-api.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -1841,8 +1841,8 @@ napi_value Init(napi_env env, napi_value exports) {
18411841
}
18421842
```
18431843

1844-
If the module will be loaded multiple times during the lifetime of the Node.js
1845-
process, use the `NAPI_MODULE_INIT` macro to initialize the module:
1844+
You can also use the `NAPI_MODULE_INIT` macro, which acts as a shorthand
1845+
for `NAPI_MODULE` and defining an `Init` function:
18461846

18471847
```c
18481848
NAPI_MODULE_INIT() {
@@ -1859,13 +1859,9 @@ NAPI_MODULE_INIT() {
18591859
}
18601860
```
18611861

1862-
This macro includes `NAPI_MODULE`, and declares an `Init` function with a
1863-
special name and with visibility beyond the addon. This will allow Node.js to
1864-
initialize the module even if it is loaded multiple times.
1865-
1866-
There are a few design considerations when declaring a module that may be loaded
1867-
multiple times. The documentation of [context-aware addons][] provides more
1868-
details.
1862+
All N-API addons are context-aware, meaning they may be loaded multiple
1863+
times. There are a few design considerations when declaring such a module.
1864+
The documentation on [context-aware addons][] provides more details.
18691865

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

0 commit comments

Comments
 (0)
Please sign in to comment.