@@ -493,8 +493,12 @@ implementation can use to persist VM-specific state. This structure is passed
493
493
to native functions when they're invoked, and it must be passed back when
494
494
making N-API calls. Specifically, the same `napi_env` that was passed in when
495
495
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`][].
498
502
499
503
### napi_value
500
504
@@ -5304,8 +5308,10 @@ This API may only be called from the main thread.
5304
5308
[Xcode]: https://developer.apple.com/xcode/
5305
5309
[`Number.MAX_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.max_safe_integer
5306
5310
[`Number.MIN_SAFE_INTEGER`]: https://tc39.github.io/ecma262/#sec-number.min_safe_integer
5311
+ [`Worker`]: worker_threads.html#worker_threads_class_worker
5307
5312
[`global`]: globals.html#globals_global
5308
5313
[`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
5309
5315
[`napi_add_finalizer`]: #n_api_napi_add_finalizer
5310
5316
[`napi_async_init`]: #n_api_napi_async_init
5311
5317
[`napi_cancel_async_work`]: #n_api_napi_cancel_async_work
@@ -5341,6 +5347,7 @@ This API may only be called from the main thread.
5341
5347
[`napi_queue_async_work`]: #n_api_napi_queue_async_work
5342
5348
[`napi_reference_ref`]: #n_api_napi_reference_ref
5343
5349
[`napi_reference_unref`]: #n_api_napi_reference_unref
5350
+ [`napi_set_instance_data`]: #n_api_napi_set_instance_data
5344
5351
[`napi_set_property`]: #n_api_napi_set_property
5345
5352
[`napi_throw_error`]: #n_api_napi_throw_error
5346
5353
[`napi_throw_range_error`]: #n_api_napi_throw_range_error
0 commit comments