diff options
Diffstat (limited to 'deps/v8/test/mjsunit/harmony/weakrefs/finalizationregistry-independent-lifetime-multiple.js')
-rw-r--r-- | deps/v8/test/mjsunit/harmony/weakrefs/finalizationregistry-independent-lifetime-multiple.js | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/deps/v8/test/mjsunit/harmony/weakrefs/finalizationregistry-independent-lifetime-multiple.js b/deps/v8/test/mjsunit/harmony/weakrefs/finalizationregistry-independent-lifetime-multiple.js index 4eb54166ea..02c4e196df 100644 --- a/deps/v8/test/mjsunit/harmony/weakrefs/finalizationregistry-independent-lifetime-multiple.js +++ b/deps/v8/test/mjsunit/harmony/weakrefs/finalizationregistry-independent-lifetime-multiple.js @@ -4,29 +4,49 @@ // Flags: --expose-gc --noincremental-marking --no-concurrent-inlining -let cleanup_called = false; -function cleanup(holdings) { - cleanup_called = true; -}; -let cleanup_called_2 = false; -function cleanup2(holdings) { - cleanup_called_2 = true; -}; -let fg = new FinalizationRegistry(cleanup); -(function() { - let fg2 = new FinalizationRegistry(cleanup2); - (function() { - fg.register({}, {}); - fg2.register({}, {}); +(async function () { + + let cleanup_called = false; + function cleanup(holdings) { + cleanup_called = true; + }; + + let cleanup_called_2 = false; + function cleanup2(holdings) { + cleanup_called_2 = true; + }; + + const fg = new FinalizationRegistry(cleanup); + + let task_1_gc = (async function () { + const fg2 = new FinalizationRegistry(cleanup2); + + (function () { + fg.register({}, "holdings1"); + fg2.register({}, "holdings2"); + })(); + + // Schedule fg and fg2 for cleanup. + await gc({ type: 'major', execution: 'async' }); + assertFalse(cleanup_called); + assertFalse(cleanup_called_2); + })(); + + // Schedule a task to collect fg2, but fg is still alive. + let task_2_gc = (async function () { + await gc({ type: 'major', execution: 'async' }); + assertFalse(cleanup_called); + assertFalse(cleanup_called_2); })(); - // Schedule fg and fg2 for cleanup. - gc(); -})(); -// Collect fg2, but fg is still alive. -gc(); + // Wait for the two GC tasks to be executed. + await task_1_gc; + await task_2_gc; -setTimeout(function() { - assertTrue(cleanup_called); - assertFalse(cleanup_called_2); -}, 0); + // Check that only the cleanup for fg will be called. + setTimeout(function() { + assertTrue(cleanup_called); + assertFalse(cleanup_called_2); + }, 0); + +})(); |