napi_set_instance_data
napi_status napi_set_instance_data(node_api_basic_env env,
void* data,
napi_finalize finalize_cb,
void* finalize_hint); -
[in] env:调用 Node-API 调用的环境。¥
[in] env: The environment that the Node-API call is invoked under. -
[in] data:可用于此实例的绑定的数据项。¥
[in] data: The data item to make available to bindings of this instance. -
[in] finalize_cb:拆除环境时调用的函数。该函数接收data以便释放它。napi_finalize提供了更多详细信息。¥
[in] finalize_cb: The function to call when the environment is being torn down. The function receivesdataso that it might free it.napi_finalizeprovides more details. -
[in] finalize_hint:在收集期间传递给最终回调的可选提示。¥
[in] finalize_hint: Optional hint to pass to the finalize callback during collection.
如果 API 成功,则返回 napi_ok。
¥Returns napi_ok if the API succeeded.
此 API 将 data 与当前运行的 Node.js 环境相关联。稍后可以使用 napi_get_instance_data() 检索 data。通过先前调用 napi_set_instance_data() 设置的与当前运行的 Node.js 环境关联的任何现有数据都将被覆盖。如果之前调用提供了 finalize_cb,则不会调用它。
¥This API associates data with the currently running Node.js environment. data
can later be retrieved using napi_get_instance_data(). Any existing data
associated with the currently running Node.js environment which was set by means
of a previous call to napi_set_instance_data() will be overwritten. If a
finalize_cb was provided by the previous call, it will not be called.