From 844a15622f7fa36c5678697aef4fed7dfb193e49 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Sat, 26 Dec 2020 21:15:28 +0100 Subject: [PATCH] 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 Reviewed-By: Rich Trott Reviewed-By: Anna Henningsen Reviewed-By: Gabriel Schulhof Reviewed-By: Michael Dawson --- doc/api/n-api.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 2e6260d07602d1..a51279ee1482ba 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -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() { @@ -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.