summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/js/builtins/weakrefs/finalizationregistry-cleanupCallback-gets-a-microtask.optional.any.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/js/builtins/weakrefs/finalizationregistry-cleanupCallback-gets-a-microtask.optional.any.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.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/finalizationregistry-cleanupCallback-gets-a-microtask.optional.any.js')
-rw-r--r--testing/web-platform/tests/js/builtins/weakrefs/finalizationregistry-cleanupCallback-gets-a-microtask.optional.any.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/testing/web-platform/tests/js/builtins/weakrefs/finalizationregistry-cleanupCallback-gets-a-microtask.optional.any.js b/testing/web-platform/tests/js/builtins/weakrefs/finalizationregistry-cleanupCallback-gets-a-microtask.optional.any.js
new file mode 100644
index 0000000000..c3a84418f3
--- /dev/null
+++ b/testing/web-platform/tests/js/builtins/weakrefs/finalizationregistry-cleanupCallback-gets-a-microtask.optional.any.js
@@ -0,0 +1,61 @@
+// META: script=/common/gc.js
+// META: script=resources/maybe-garbage-collect.js
+// ├──> maybeGarbageCollectAsync
+// └──> resolveGarbageCollection
+/*---
+esid: sec-finalization-registry-target
+info: |
+ FinalizationRegistry ( cleanupCallback )
+
+ Execution
+ At any time, if a set of objects S is not live, an ECMAScript implementation may perform the
+ following steps atomically:
+
+ For each obj of S, do
+ For each WeakRef ref such that ref.[[WeakRefTarget]] is obj, do
+ Set ref.[[WeakRefTarget]] to empty.
+ For each FinalizationRegistry fg such that fg.[[Cells]] contains cell, such that
+ cell.[[WeakRefTarget]] is obj,
+ Set cell.[[WeakRefTarget]] to empty.
+ Optionally, perform ! HostCleanupFinalizationRegistry(fg).
+
+ HostCleanupFinalizationRegistry(finalizationRegistry)
+
+ HostCleanupFinalizationRegistry is an implementation-defined abstract operation that is expected
+ to call CleanupFinalizationRegistry(finalizationRegistry) at some point in the future, if
+ possible. The host's responsibility is to make this call at a time which does not interrupt
+ synchronous ECMAScript code execution.
+---*/
+
+let count = 1_000;
+let calls = 0;
+let registries = [];
+let callback = function() {
+ calls++;
+};
+for (let i = 0; i < count; i++) {
+ registries.push(
+ new FinalizationRegistry(callback)
+ );
+}
+setup({ allow_uncaught_exception: true });
+
+promise_test((test) => {
+ assert_implements(
+ typeof FinalizationRegistry.prototype.register === 'function',
+ 'FinalizationRegistry.prototype.register is not implemented.'
+ );
+ return (async () => {
+
+ {
+ let target = {};
+ for (let registry of registries) {
+ registry.register(target, 1);
+ }
+ target = null;
+ }
+
+ await maybeGarbageCollectAsync();
+ await test.step_wait(() => calls === count, `Expected ${count} registry cleanups.`);
+ })().catch(resolveGarbageCollection);
+}, 'HostCleanupFinalizationRegistry is an implementation-defined abstract operation that is expected to call CleanupFinalizationRegistry(finalizationRegistry) at some point in the future, if possible.');