Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2020-02-04 07:46:37 +0300
committerGabriel Schulhof <gabriel.schulhof@intel.com>2020-02-06 23:43:24 +0300
commit884e287199901853a30781a0b398e6c3e4a07eb1 (patch)
tree72c195167c27beeb6cb9ad76e1330b4ff198a8f2 /src/js_native_api_v8_internals.h
parenta9e26268f5b464f508a033129c1ffaa694e5d361 (diff)
n-api: free instance data as reference
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: https://github.com/nodejs/node-addon-api/pull/663 PR-URL: https://github.com/nodejs/node/pull/31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/js_native_api_v8_internals.h')
-rw-r--r--src/js_native_api_v8_internals.h39
1 files changed, 0 insertions, 39 deletions
diff --git a/src/js_native_api_v8_internals.h b/src/js_native_api_v8_internals.h
index 74afd1172e5..ddd219818cd 100644
--- a/src/js_native_api_v8_internals.h
+++ b/src/js_native_api_v8_internals.h
@@ -28,45 +28,6 @@
namespace v8impl {
-class RefTracker {
- public:
- RefTracker() {}
- virtual ~RefTracker() {}
- virtual void Finalize(bool isEnvTeardown) {}
-
- typedef RefTracker RefList;
-
- inline void Link(RefList* list) {
- prev_ = list;
- next_ = list->next_;
- if (next_ != nullptr) {
- next_->prev_ = this;
- }
- list->next_ = this;
- }
-
- inline void Unlink() {
- if (prev_ != nullptr) {
- prev_->next_ = next_;
- }
- if (next_ != nullptr) {
- next_->prev_ = prev_;
- }
- prev_ = nullptr;
- next_ = nullptr;
- }
-
- static void FinalizeAll(RefList* list) {
- while (list->next_ != nullptr) {
- list->next_->Finalize(true);
- }
- }
-
- private:
- RefList* next_ = nullptr;
- RefList* prev_ = nullptr;
-};
-
template <typename T>
using Persistent = v8::Global<T>;