Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6db465a

Browse filesBrowse files
mildsunrisedanielleadams
authored andcommitted
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 fad07d5 commit 6db465a
Copy full SHA for 6db465a

File tree

Expand file treeCollapse file tree

1 file changed

+5
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-9
lines changed
Open diff view settings
Collapse file

‎doc/api/n-api.md‎

Copy file name to clipboardExpand all lines: doc/api/n-api.md
+5-9Lines changed: 5 additions & 9 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1853,8 +1853,8 @@ napi_value Init(napi_env env, napi_value exports) {
18531853
}
18541854
```
18551855

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

18591859
```c
18601860
NAPI_MODULE_INIT() {
@@ -1871,13 +1871,9 @@ NAPI_MODULE_INIT() {
18711871
}
18721872
```
18731873

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

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.