doc: update examples for context sensitivity#1013
doc: update examples for context sensitivity#1013KevinEady wants to merge 1 commit intonodejs:mainfrom
Conversation
| constructor.SuppressDestruct(); | ||
| Napi::FunctionReference *constructor = new Napi::FunctionReference(); | ||
| *constructor = Napi::Persistent(func); | ||
| env.SetInstanceData(constructor); |
There was a problem hiding this comment.
A finalizer is required for this FunctionReference pointer right?
There was a problem hiding this comment.
Hi @legendecas ,
Good question... I was under the impression that the instance data would be deleted, so there would be no need for a Finalizer.
- In the case of multiple calls to
Example::Init, the previous instance data would be overwritten via most recent call toenv.SetInstanceData. https://github.com/nodejs/node/blob/d615aeb7583b15bb5a8d1ec666ea29b8c7377455/src/js_native_api_v8.cc#L3201-L3205 does this delete the data? - The final data would be
deleted on environment cleanup.
Is my understanding correct?
There was a problem hiding this comment.
Eh, IIUC, it's node-addon-api's default finalizer deleted the data pointer: https://github.com/nodejs/node-addon-api/blob/main/napi.h#L208. Not quite intuitive tho... So no finalizer is required here.
There was a problem hiding this comment.
The Delete you point out only deleting the RefBase structure allocated in Node.js core, which would invoke the finalizer provided by node-addon-api. (Update: no, the lines don't invoke finalizers as they are replacing existing instance data)
|
Landed as 627dbf3 |
Fixes: nodejs#1011 PR-URL: nodejs#1013 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Fixes: nodejs#1011 PR-URL: nodejs#1013 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Fixes: nodejs/node-addon-api#1011 PR-URL: nodejs/node-addon-api#1013 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Fixes: nodejs/node-addon-api#1011 PR-URL: nodejs/node-addon-api#1013 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Fixes: nodejs/node-addon-api#1011 PR-URL: nodejs/node-addon-api#1013 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Fixes: nodejs/node-addon-api#1011 PR-URL: nodejs/node-addon-api#1013 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Closes: #1011