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:
-rw-r--r--src/node_contextify.cc13
-rw-r--r--src/node_contextify.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index c6b9dc18de9..5be774fb91a 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -114,6 +114,19 @@ ContextifyContext::ContextifyContext(
context_.Reset(env->isolate(), v8_context.ToLocalChecked());
context_.SetWeak(this, WeakCallback, WeakCallbackType::kParameter);
+ env->AddCleanupHook(CleanupHook, this);
+}
+
+
+ContextifyContext::~ContextifyContext() {
+ env()->RemoveCleanupHook(CleanupHook, this);
+}
+
+
+void ContextifyContext::CleanupHook(void* arg) {
+ ContextifyContext* self = static_cast<ContextifyContext*>(arg);
+ self->context_.Reset();
+ delete self;
}
diff --git a/src/node_contextify.h b/src/node_contextify.h
index d04bf9ea28e..288b51ef56a 100644
--- a/src/node_contextify.h
+++ b/src/node_contextify.h
@@ -22,6 +22,8 @@ class ContextifyContext {
ContextifyContext(Environment* env,
v8::Local<v8::Object> sandbox_obj,
const ContextOptions& options);
+ ~ContextifyContext();
+ static void CleanupHook(void* arg);
v8::MaybeLocal<v8::Object> CreateDataWrapper(Environment* env);
v8::MaybeLocal<v8::Context> CreateV8Context(Environment* env,