diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/js/builtins/weakrefs/reentrancy.optional.any.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/js/builtins/weakrefs/reentrancy.optional.any.js')
-rw-r--r-- | testing/web-platform/tests/js/builtins/weakrefs/reentrancy.optional.any.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/testing/web-platform/tests/js/builtins/weakrefs/reentrancy.optional.any.js b/testing/web-platform/tests/js/builtins/weakrefs/reentrancy.optional.any.js new file mode 100644 index 0000000000..fa7b7d55c4 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/weakrefs/reentrancy.optional.any.js @@ -0,0 +1,51 @@ +// META: script=/common/gc.js +// META: script=resources/maybe-garbage-collect.js +// ├──> maybeGarbageCollectAndCleanupAsync +// └──> resolveGarbageCollection +/*--- +esid: sec-properties-of-the-finalization-registry-constructor +---*/ + +let called = 0; +let endOfCall = 0; +let finalizationRegistry = new FinalizationRegistry(function() {}); + +function callback(holding) { + called += 1; + + if (called === 1) { + // Atempt to re-enter the callback. + let nestedCallbackRan = false; + finalizationRegistry.cleanupSome(() => { nestedCallbackRan = true }); + assert_equals(nestedCallbackRan, true); + } + + endOfCall += 1; +} + +function emptyCells() { + let o1 = {}; + let o2 = {}; + // Register more than one objects to test reentrancy. + finalizationRegistry.register(o1, 'holdings 1'); + finalizationRegistry.register(o2, 'holdings 2'); + + let prom = maybeGarbageCollectAndCleanupAsync(o1); + o1 = null; + + return prom; +} + +promise_test(() => { + return (async () => { + assert_implements( + typeof FinalizationRegistry.prototype.cleanupSome === 'function', + 'FinalizationRegistry.prototype.cleanupSome is not implemented.' + ); + await emptyCells(); + finalizationRegistry.cleanupSome(callback); + + assert_equals(called, 1, 'callback was called'); + assert_equals(endOfCall, 1, 'callback finished'); + })().catch(resolveGarbageCollection); +}, 'cleanupCallback has only one optional chance to be called for a GC that cleans up a registered target.'); |