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 82b447c

Browse filesBrowse files
legendecasMylesBorins
authored andcommitted
doc,src: clarify that one napi_env is per-module
PR-URL: #31102 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent c1333ea commit 82b447c
Copy full SHA for 82b447c

File tree

Expand file treeCollapse file tree

2 files changed

+10
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-4
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
+9-2Lines changed: 9 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,12 @@ implementation can use to persist VM-specific state. This structure is passed
493493
to native functions when they're invoked, and it must be passed back when
494494
making N-API calls. Specifically, the same `napi_env` that was passed in when
495495
the initial native function was called must be passed to any subsequent
496-
nested N-API calls. Caching the `napi_env` for the purpose of general reuse is
497-
not allowed.
496+
nested N-API calls. Caching the `napi_env` for the purpose of general reuse,
497+
and passing the `napi_env` between instances of the same addon running on
498+
different [`Worker`][] threads is not allowed. The `napi_env` becomes invalid
499+
when an instance of a native addon is unloaded. Notification of this event is
500+
delivered through the callbacks given to [`napi_add_env_cleanup_hook`][] and
501+
[`napi_set_instance_data`][].
498502

499503
### napi_value
500504

@@ -5304,8 +5308,10 @@ This API may only be called from the main thread.
53045308
[Xcode]: https://developer.apple.com/xcode/
53055309
[`Number.MAX_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.max_safe_integer
53065310
[`Number.MIN_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.min_safe_integer
5311+
[`Worker`]: worker_threads.html#worker_threads_class_worker
53075312
[`global`]: globals.html#globals_global
53085313
[`init` hooks]: async_hooks.html#async_hooks_init_asyncid_type_triggerasyncid_resource
5314+
[`napi_add_env_cleanup_hook`]: #n_api_napi_add_env_cleanup_hook
53095315
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
53105316
[`napi_async_init`]: #n_api_napi_async_init
53115317
[`napi_cancel_async_work`]: #n_api_napi_cancel_async_work
@@ -5341,6 +5347,7 @@ This API may only be called from the main thread.
53415347
[`napi_queue_async_work`]: #n_api_napi_queue_async_work
53425348
[`napi_reference_ref`]: #n_api_napi_reference_ref
53435349
[`napi_reference_unref`]: #n_api_napi_reference_unref
5350+
[`napi_set_instance_data`]: #n_api_napi_set_instance_data
53445351
[`napi_set_property`]: #n_api_napi_set_property
53455352
[`napi_throw_error`]: #n_api_napi_throw_error
53465353
[`napi_throw_range_error`]: #n_api_napi_throw_range_error
Collapse file

‎src/node_api.cc‎

Copy file name to clipboardExpand all lines: src/node_api.cc
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
471471
return;
472472
}
473473

474-
// Create a new napi_env for this module or reference one if a pre-existing
475-
// one is found.
474+
// Create a new napi_env for this specific module.
476475
napi_env env = v8impl::NewEnv(context);
477476

478477
napi_value _exports;

0 commit comments

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