summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/js/builtins/weakrefs/reentrancy.optional.any.js
diff options
context:
space:
mode:
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.js51
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.');