Skip to content

Commit

Permalink
put the _finalize_ran = true back in the else body
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Feb 12, 2021
1 parent 55cfe37 commit 6415c99
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,21 +270,26 @@ class RefBase : protected Finalizer, RefTracker {

protected:
inline void Finalize(bool is_env_teardown = false) override {
// Force deferring behavior if the finalizer happens to delete this
// reference.
// During environment teardown we have to convert a strong reference to
// a weak reference to force the deferring behavior if the user's finalizer
// happens to delete this reference so that the code in this function that
// follows the call to the user's finalizer may safely access variables from
// this instance.
if (is_env_teardown && RefCount() > 0) _refcount = 0;

if (_finalize_callback != nullptr) {
_env->CallFinalizer(_finalize_callback, _finalize_data, _finalize_hint);
// This ensures that we never call the finalizer twice.
_finalize_callback = nullptr;
}

// this is safe because if a request to delete the reference
// is made in the finalize_callback it will defer deletion
// to this block and set _delete_self to true
_finalize_ran = true;

if (_delete_self || is_env_teardown) {
Delete(this);
} else {
_finalize_ran = true;
}
}

Expand Down

0 comments on commit 6415c99

Please sign in to comment.