summaryrefslogtreecommitdiff
path: root/src/js_native_api_v8.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_native_api_v8.cc')
-rw-r--r--src/js_native_api_v8.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc
index 602ded2156..664aa2d41b 100644
--- a/src/js_native_api_v8.cc
+++ b/src/js_native_api_v8.cc
@@ -374,8 +374,11 @@ class Reference : public RefBase {
inline void Finalize(bool is_env_teardown = false) override {
// During env teardown, `~napi_env()` alone is responsible for finalizing.
// Thus, we don't want any stray gc passes to trigger a second call to
- // `Finalize()`, so let's reset the persistent here.
- if (is_env_teardown) _persistent.ClearWeak();
+ // `Finalize()`, so let's reset the persistent here if nothing is
+ // keeping it alive.
+ if (is_env_teardown && _persistent.IsWeak()) {
+ _persistent.ClearWeak();
+ }
// Chain up to perform the rest of the finalization.
RefBase::Finalize(is_env_teardown);