diff --git a/src/api/api.cc b/src/api/api.cc index 646d640870..05d70ef5ad 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -328,6 +328,7 @@ class CallDepthScope { bool CheckKeptObjectsClearedAfterMicrotaskCheckpoint( i::MicrotaskQueue* microtask_queue) { bool did_perform_microtask_checkpoint = + isolate_->thread_local_top()->CallDepthIsZero() && do_callback && microtask_queue && microtask_queue->microtasks_policy() == MicrotasksPolicy::kAuto; return !did_perform_microtask_checkpoint || diff --git a/test/mjsunit/harmony/weakrefs/clearkeptobjects-on-quit.js b/test/mjsunit/harmony/weakrefs/clearkeptobjects-on-quit.js new file mode 100644 index 0000000000..6007f9c360 --- /dev/null +++ b/test/mjsunit/harmony/weakrefs/clearkeptobjects-on-quit.js @@ -0,0 +1,13 @@ +// Copyright 2020 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Flags: --harmony-weak-refs + +// A newly created WeakRef is kept alive until the end of the next microtask +// checkpoint. V8 asserts that the kept objects list is cleared at the end of +// microtask checkpoints when the microtask policy is auto. Test that d8, which +// uses the auto policy, upholds the assert when manually quitting. +let obj = {}; +let wr = new WeakRef(obj); +testRunner.quit();