node_api_basic_env
这种 napi_env 的变体会传递给同步终结器 (node_api_basic_finalize)。Node-API 中有一部分 API 接受 node_api_basic_env 类型的参数作为它们的第一个参数。这些 API 不会访问 JavaScript 引擎的状态,因此可以安全地从同步终结器中调用。将 napi_env 类型的参数传递给这些 API 是允许的,但是将 node_api_basic_env 类型的参数传递给访问 JavaScript 引擎状态的 API 是不允许的。如果在没有强制类型转换的情况下尝试这样做,当使用会在传入错误指针类型时发出警告和/或错误的标志编译插件时,将会产生编译器警告或错误。从同步终结器中调用此类 API 最终会导致应用终止。
【This variant of napi_env is passed to synchronous finalizers
(node_api_basic_finalize). There is a subset of Node-APIs which accept
a parameter of type node_api_basic_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_basic_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.】