Uh oh!
There was an error while loading. Please reload this page.
src: add support for addon instance data - #663
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tniessen
commented
Feb 3, 2020
Is the implicit initialization really helpful? I would imagine most use cases to be one of these:
To work around these issues, most objects would probably have to have a member |
827b995 to
433a1a1Comparegabrielschulhof
commented
Feb 4, 2020
@tniessen@legendecas@addaleax I changed the interface to an accessor pair as @tniessen suggested. Landing this requires nodejs/node#31638 otherwise it crashes 😕 |
Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: nodejs/node-addon-api#663
Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: nodejs/node-addon-api#663 PR-URL: #31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: nodejs/node-addon-api#663 PR-URL: #31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: nodejs/node-addon-api#663 PR-URL: #31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: nodejs/node-addon-api#663 PR-URL: #31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
| return Value(_env, result); | ||
| } | ||
| #ifdef NAPI_EXPERIMENTAL |
There was a problem hiding this comment.
I believe this guard can be replaced with NAPI_VERSION > 5?
| /// | ||
| /// In the V8 JavaScript engine, a N-API environment approximately corresponds to an Isolate. | ||
| class Env { | ||
| #ifdef NAPI_EXPERIMENTAL |
There was a problem hiding this comment.
Same comment as before here as well with respect to NAPI_VERSION > 5 and the next one as well.
62cd556 to
e0d376cCompareInstance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: nodejs/node-addon-api#663 PR-URL: #31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
gabrielschulhof
commented
Apr 7, 2020
@mhdawson@legendecas I have updated the guards. |
e0d376c to
8174b51Compare8174b51 to
7db12f7Compare| napi_status status = | ||
| napi_set_instance_data(_env, data, [](napi_env, void* data, void*) { | ||
| fini(static_cast<T*>(data)); | ||
| }, nullptr); |
There was a problem hiding this comment.
Just noted finalize hint has been hardcoded here. Is this intended?
gabrielschulhof
commented
Apr 14, 2020
@legendecas I added an option that takes a hint. |
f8d6482 to
ed7042cCompareed7042c to
2f6ac14Comparegabrielschulhof
commented
Apr 25, 2020
Investigating .o0o.o0o. |
Support `napi_get_instance_data()` and `napi_set_instance_data()`. Fixes: nodejs#654
2f6ac14 to
a8959b6Comparegabrielschulhof
commented
Apr 25, 2020
The failure was caused by Windows' use of escape characters as path separators. The path to the addon was being passed through an unescape step. |
gabrielschulhof
commented
Apr 25, 2020
Landed in 9c9accf. |
Support `napi_get_instance_data()` and `napi_set_instance_data()`. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Fixes: nodejs/node-addon-api#654 PR-URL: nodejs/node-addon-api#663 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Support `napi_get_instance_data()` and `napi_set_instance_data()`. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Fixes: nodejs/node-addon-api#654 PR-URL: nodejs/node-addon-api#663 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Support `napi_get_instance_data()` and `napi_set_instance_data()`. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Fixes: nodejs/node-addon-api#654 PR-URL: nodejs/node-addon-api#663 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Support `napi_get_instance_data()` and `napi_set_instance_data()`. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Fixes: nodejs/node-addon-api#654 PR-URL: nodejs/node-addon-api#663 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Support
napi_get_instance_data()andnapi_set_instance_data().Fixes: #654