-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Class property and descriptor" example crashes in Electron render process on reload #1011
Comments
Hi @ToadKing , Thanks for pointing this out. The example in the documentation predates some modern APIs for handling context-sensitivity, particularly Napi::FunctionReference *constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
env.SetInstanceData(constructor); electron-reload.mp4[NB: SetInstanceData will overwrite any existing instance data set. See #744 for some examples on how to store multiple constructors on the instance data.] |
Note that |
Thank you, this change fixes my PoC app and the app I found it in. Should this issue be left open and be changed to update the documentation or is it good to close? |
@ToadKing I am not sure... We will leave it open to discuss at this week's Node-API meeting. We'll need to discuss a hopefully context-sensitive approach for Node-API version <= 5. I will leave this issue open until we discuss it. Thanks, Kevin |
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>
PoC Project: https://github.com/ToadKing/electron-native-module-poc (The native module part is an exact copy of the example in the node-addon-api docs.)
The class example in the docs makes the constructor reference persistent using
Napi::Persistent
on module initialization. However, in Electron when a render process reloads a page, the native module is re-initialized without reloading the shared library itself. When a new constructor reference is loaded into theconstructor
variable it tries to delete the former reference, which causes a crash of the Electron render process.The text was updated successfully, but these errors were encountered: