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/holdings-multiple-values.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/holdings-multiple-values.optional.any.js')
-rw-r--r-- | testing/web-platform/tests/js/builtins/weakrefs/holdings-multiple-values.optional.any.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/testing/web-platform/tests/js/builtins/weakrefs/holdings-multiple-values.optional.any.js b/testing/web-platform/tests/js/builtins/weakrefs/holdings-multiple-values.optional.any.js new file mode 100644 index 0000000000..604174e467 --- /dev/null +++ b/testing/web-platform/tests/js/builtins/weakrefs/holdings-multiple-values.optional.any.js @@ -0,0 +1,66 @@ +// META: script=/common/gc.js +// META: script=resources/maybe-garbage-collect.js +// ├──> maybeGarbageCollectAndCleanupAsync +// └──> resolveGarbageCollection +/*--- +esid: sec-properties-of-the-finalization-registry-constructor +info: | + FinalizationRegistry.prototype.cleanupSome ( [ callback ] ) + + 1. Let finalizationRegistry be the this value. + ... + 5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback). + ... + + CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] ) + + ... + 3. While finalizationRegistry.[[Cells]] contains a Record cell such that cell.[[WeakRefTarget]] is ~empty~, then an implementation may perform the following steps, + a. Choose any such cell. + b. Remove cell from finalizationRegistry.[[Cells]]. + c. Perform ? Call(callback, undefined, << cell.[[HeldValue]] >>). + +---*/ + +function check(value, expectedName) { + let holdings = []; + let called = 0; + let finalizationRegistry = new FinalizationRegistry(function() {}); + + function callback(holding) { + called += 1; + holdings.push(holding); + } + + // This is internal to avoid conflicts + function emptyCells(value) { + let target = {}; + finalizationRegistry.register(target, value); + + let prom = maybeGarbageCollectAndCleanupAsync(target); + target = null; + + return prom; + } + + return emptyCells(value).then(function() { + finalizationRegistry.cleanupSome(callback); + assert_equals(called, 1, expectedName); + assert_equals(holdings.length, 1, expectedName); + assert_equals(holdings[0], value, expectedName); + }); +} + +test(() => + assert_implements( + typeof FinalizationRegistry.prototype.cleanupSome === 'function', + 'FinalizationRegistry.prototype.cleanupSome is not implemented.' +), 'Requires FinalizationRegistry.prototype.cleanupSome'); +promise_test(() => check(undefined, 'undefined'), '`undefined` as registered holding value'); +promise_test(() => check(null, 'null'), '`null` as registered holding value'); +promise_test(() => check('', 'the empty string'), '`""` as registered holding value'); +promise_test(() => check({}, 'object'), '`{}` as registered holding value'); +promise_test(() => check(42, 'number'), '`42` as registered holding value'); +promise_test(() => check(true, 'true'), '`true` as registered holding value'); +promise_test(() => check(false, 'false'), '`false` as registered holding value'); +promise_test(() => check(Symbol(1), 'symbol'), '`Symbol(1)` as registered holding value'); |