diff options
Diffstat (limited to 'deps/v8/test/mjsunit/harmony/weakrefs/weakref-creation-keeps-alive.js')
-rw-r--r-- | deps/v8/test/mjsunit/harmony/weakrefs/weakref-creation-keeps-alive.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/deps/v8/test/mjsunit/harmony/weakrefs/weakref-creation-keeps-alive.js b/deps/v8/test/mjsunit/harmony/weakrefs/weakref-creation-keeps-alive.js index 78e8865ac0..9b03f03e26 100644 --- a/deps/v8/test/mjsunit/harmony/weakrefs/weakref-creation-keeps-alive.js +++ b/deps/v8/test/mjsunit/harmony/weakrefs/weakref-creation-keeps-alive.js @@ -5,22 +5,29 @@ // Flags: --expose-gc --noincremental-marking let wr; -(function() { +(function () { let o = {}; wr = new WeakRef(o); // Don't deref here, we want to test that the creation is enough to keep the // WeakRef alive until the end of the turn. })(); +// Here we invoke GC synchronously and, with conservative stack scanning, +// there is a chance that the object is not reclaimed now. In any case, +// the WeakRef should not be cleared. gc(); - // Since the WeakRef was created during this turn, it is not cleared by GC. -(function() { - assertNotEquals(undefined, wr.deref()); -})(); +assertNotEquals(undefined, wr.deref()); // Next task. setTimeout(() => { - gc(); - assertEquals(undefined, wr.deref()); + (async function () { + // Trigger GC again to make sure the two WeakRefs are cleared. + // We need to invoke GC asynchronously and wait for it to finish, so that + // it doesn't need to scan the stack. Otherwise, the objects may not be + // reclaimed because of conservative stack scanning and the test may not + // work as intended. + await gc({ type: 'major', execution: 'async' }); + assertEquals(undefined, wr.deref()); + })(); }, 0); |