holdings-multiple-values.optional.any.js (2470B)
1 // META: script=/common/gc.js 2 // META: script=resources/maybe-garbage-collect.js 3 // ├──> maybeGarbageCollectAndCleanupAsync 4 // └──> resolveGarbageCollection 5 /*--- 6 esid: sec-properties-of-the-finalization-registry-constructor 7 info: | 8 FinalizationRegistry.prototype.cleanupSome ( [ callback ] ) 9 10 1. Let finalizationRegistry be the this value. 11 ... 12 5. Perform ! CleanupFinalizationRegistry(finalizationRegistry, callback). 13 ... 14 15 CleanupFinalizationRegistry ( finalizationRegistry [ , callback ] ) 16 17 ... 18 3. While finalizationRegistry.[[Cells]] contains a Record cell such that cell.[[WeakRefTarget]] is ~empty~, then an implementation may perform the following steps, 19 a. Choose any such cell. 20 b. Remove cell from finalizationRegistry.[[Cells]]. 21 c. Perform ? Call(callback, undefined, << cell.[[HeldValue]] >>). 22 23 ---*/ 24 25 function check(value, expectedName) { 26 let holdings = []; 27 let called = 0; 28 let finalizationRegistry = new FinalizationRegistry(function() {}); 29 30 function callback(holding) { 31 called += 1; 32 holdings.push(holding); 33 } 34 35 // This is internal to avoid conflicts 36 function emptyCells(value) { 37 let target = {}; 38 finalizationRegistry.register(target, value); 39 40 let prom = maybeGarbageCollectAndCleanupAsync(target); 41 target = null; 42 43 return prom; 44 } 45 46 return emptyCells(value).then(function() { 47 finalizationRegistry.cleanupSome(callback); 48 assert_equals(called, 1, expectedName); 49 assert_equals(holdings.length, 1, expectedName); 50 assert_equals(holdings[0], value, expectedName); 51 }); 52 } 53 54 test(() => 55 assert_implements( 56 typeof FinalizationRegistry.prototype.cleanupSome === 'function', 57 'FinalizationRegistry.prototype.cleanupSome is not implemented.' 58 ), 'Requires FinalizationRegistry.prototype.cleanupSome'); 59 promise_test(() => check(undefined, 'undefined'), '`undefined` as registered holding value'); 60 promise_test(() => check(null, 'null'), '`null` as registered holding value'); 61 promise_test(() => check('', 'the empty string'), '`""` as registered holding value'); 62 promise_test(() => check({}, 'object'), '`{}` as registered holding value'); 63 promise_test(() => check(42, 'number'), '`42` as registered holding value'); 64 promise_test(() => check(true, 'true'), '`true` as registered holding value'); 65 promise_test(() => check(false, 'false'), '`false` as registered holding value'); 66 promise_test(() => check(Symbol(1), 'symbol'), '`Symbol(1)` as registered holding value');