Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/js_native_api_v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class RefTracker {
struct napi_env__ {
explicit napi_env__(v8::Local<v8::Context> context)
: isolate(context->GetIsolate()),
context_persistent(isolate, context) {
context_persistent(isolate, context),
is_env_teardown(false) {
CHECK_EQ(isolate, context->GetIsolate());
}
virtual ~napi_env__() {
Expand All @@ -63,11 +64,15 @@ struct napi_env__ {
// they delete during their `napi_finalizer` callbacks. If we deleted such
// references here first, they would be doubly deleted when the
// `napi_finalizer` deleted them subsequently.
is_env_teardown = true;
v8impl::RefTracker::FinalizeAll(&finalizing_reflist);
v8impl::RefTracker::FinalizeAll(&reflist);
}
v8::Isolate* const isolate; // Shortcut for context()->GetIsolate()
v8impl::Persistent<v8::Context> context_persistent;
bool is_env_teardown;

inline bool isEnvTeardown() { return is_env_teardown; }

inline v8::Local<v8::Context> context() const {
return v8impl::PersistentToLocal::Strong(context_persistent);
Expand Down
12 changes: 10 additions & 2 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ struct node_napi_env__ : public napi_env__ {

void CallFinalizer(napi_finalize cb, void* data, void* hint) override {
napi_env env = static_cast<napi_env>(this);
node_env()->SetImmediate([=](node::Environment* node_env) {
if (!env->isEnvTeardown()) {
node_env()->SetImmediate([=](node::Environment* node_env) {
v8::HandleScope handle_scope(env->isolate);
v8::Context::Scope context_scope(env->context());
env->CallIntoModule([&](napi_env env) {
cb(env, data, hint);
});
});
} else {
v8::HandleScope handle_scope(env->isolate);
v8::Context::Scope context_scope(env->context());
env->CallIntoModule([&](napi_env env) {
cb(env, data, hint);
});
});
}
}

const char* GetFilename() const { return filename.c_str(); }
Expand Down