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] data:要提供给此实例绑定的数据项。[in] finalize_cb:当环境被拆除时要调用的函数。该函数接收data,以便可能释放它。napi_finalize提供了更多详细信息。[in] finalize_hint:在收集期间传递给 finalize 回调的可选提示。
如果 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.】