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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Alba Mendez 2020-12-26 21:15:28 +01:00 committed by Gabriel Schulhof
parent 15164cebce
commit a3fcf24a6c

View File

@ -1853,8 +1853,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() {
@ -1871,13 +1871,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.