summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/FinalizationRegistry/prototype/cleanupSome/holdings-multiple-values.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/FinalizationRegistry/prototype/cleanupSome/holdings-multiple-values.js')
-rw-r--r--js/src/tests/test262/built-ins/FinalizationRegistry/prototype/cleanupSome/holdings-multiple-values.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/FinalizationRegistry/prototype/cleanupSome/holdings-multiple-values.js b/js/src/tests/test262/built-ins/FinalizationRegistry/prototype/cleanupSome/holdings-multiple-values.js
new file mode 100644
index 0000000000..4c8d99b11a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/FinalizationRegistry/prototype/cleanupSome/holdings-multiple-values.js
@@ -0,0 +1,70 @@
+// |reftest| skip-if(!this.hasOwnProperty('FinalizationRegistry')) async -- FinalizationRegistry is not enabled unconditionally
+// Copyright (C) 2019 Leo Balter. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-properties-of-the-finalization-registry-constructor
+description: >
+ Iterates over different type values in holdings
+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]] >>).
+ ...
+
+
+features: [FinalizationRegistry.prototype.cleanupSome, FinalizationRegistry, Symbol, host-gc-required]
+includes: [async-gc.js]
+flags: [async, non-deterministic]
+---*/
+
+function check(value, expectedName) {
+ var holdings = [];
+ var called = 0;
+ var finalizationRegistry = new FinalizationRegistry(function() {});
+
+ function callback(holding) {
+ called += 1;
+ holdings.push(holding);
+ }
+
+ // This is internal to avoid conflicts
+ function emptyCells(value) {
+ var target = {};
+ finalizationRegistry.register(target, value);
+
+ var prom = asyncGC(target);
+ target = null;
+
+ return prom;
+ }
+
+ return emptyCells(value).then(function() {
+ finalizationRegistry.cleanupSome(callback);
+ assert.sameValue(called, 1, expectedName);
+ assert.sameValue(holdings.length, 1, expectedName);
+ assert.sameValue(holdings[0], value, expectedName);
+ });
+}
+
+Promise.all([
+ check(undefined, 'undefined'),
+ check(null, 'null'),
+ check('', 'the empty string'),
+ check({}, 'object'),
+ check(42, 'number'),
+ check(true, 'true'),
+ check(false, 'false'),
+ check(Symbol(1), 'symbol'),
+]).then(() => $DONE(), resolveAsyncGC);