node_api_nogc_env
napi_env 的这个变体会传递给同步终结器(node_api_nogc_finalize)。Node-API 中有一部分 API 接受类型为 node_api_nogc_env 的参数作为它们的第一个参数。这些 API 不会访问 JavaScript 引擎的状态,因此可以安全地从同步终结器中调用。将类型为 napi_env 的参数传递给这些 API 是允许的,但将类型为 node_api_nogc_env 的参数传递给访问 JavaScript 引擎状态的 API 是不允许的。如果在没有进行类型转换的情况下尝试这样做,在使用导致当传入函数错误指针类型时产生警告和/或错误的标志编译附加模块时,将会产生编译器警告或错误。从同步终结器调用这样的 API 最终会导致应用终止。
【This variant of napi_env is passed to synchronous finalizers
(node_api_nogc_finalize). There is a subset of Node-APIs which accept
a parameter of type node_api_nogc_env as their first argument. These APIs do
not access the state of the JavaScript engine and are thus safe to call from
synchronous finalizers. Passing a parameter of type napi_env to these APIs is
allowed, however, passing a parameter of type node_api_nogc_env to APIs that
access the JavaScript engine state is not allowed. Attempting to do so without
a cast will produce a compiler warning or an error when add-ons are compiled
with flags which cause them to emit warnings and/or errors when incorrect
pointer types are passed into a function. Calling such APIs from a synchronous
finalizer will ultimately result in the termination of the application.】