mirror of https://github.com/tc39/test262.git
Refactor: built-ins/FinalizationRegistry/gc-has-one-chance-to-call-cleanupCallback.js
Per recommendation here: https://github.com/web-platform-tests/wpt/pull/25496/files#r488316588
This commit is contained in:
parent
1cd7d87501
commit
fd26fc17ea
|
@ -27,33 +27,30 @@ info: |
|
|||
b. Optionally, perform ! HostCleanupFinalizationRegistry(finalizationRegistry).
|
||||
features: [cleanupSome, FinalizationRegistry, async-functions, host-gc-required]
|
||||
flags: [async, non-deterministic]
|
||||
includes: [async-gc.js]
|
||||
includes: [async-gc.js, compareArray.js]
|
||||
---*/
|
||||
|
||||
var cleanupCallback = 0;
|
||||
var called = 0;
|
||||
|
||||
let cleanupCallback = 0;
|
||||
let holdings = [];
|
||||
function cb(holding) {
|
||||
assert.sameValue(holding, 'a');
|
||||
called += 1;
|
||||
holdings.push(holding);
|
||||
}
|
||||
|
||||
var finalizationRegistry = new FinalizationRegistry(function() {
|
||||
let finalizationRegistry = new FinalizationRegistry(function() {
|
||||
cleanupCallback += 1;
|
||||
});
|
||||
|
||||
function emptyCells() {
|
||||
var target = {};
|
||||
let target = {};
|
||||
finalizationRegistry.register(target, 'a');
|
||||
|
||||
var prom = asyncGC(target);
|
||||
let prom = asyncGC(target);
|
||||
target = null;
|
||||
|
||||
return prom;
|
||||
}
|
||||
|
||||
emptyCells()
|
||||
.then(async function() {
|
||||
emptyCells().then(async function() {
|
||||
await Promise.resolve(1);
|
||||
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
@ -62,7 +59,7 @@ emptyCells()
|
|||
// cleanupCallback already ran, then cb won't be called.
|
||||
let expectedCalled = cleanupCallback === 1 ? 0 : 1;
|
||||
// This asserts the registered object was emptied in the previous GC.
|
||||
assert.sameValue(called, expectedCalled, 'cleanupSome callback for the first time');
|
||||
assert.sameValue(holdings.length, expectedCalled, 'cleanupSome callback for the first time');
|
||||
|
||||
// At this point, we can't assert if cleanupCallback was called, because it's
|
||||
// optional. Although, we can finally assert it's not gonna be called anymore
|
||||
|
@ -81,7 +78,7 @@ emptyCells()
|
|||
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
||||
assert.sameValue(called, expectedCalled, 'cleanupSome callback is not called anymore, no empty cells');
|
||||
assert.sameValue(holdings.length, expectedCalled, 'cleanupSome callback is not called anymore, no empty cells');
|
||||
assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #1');
|
||||
|
||||
await $262.gc();
|
||||
|
@ -89,9 +86,12 @@ emptyCells()
|
|||
|
||||
finalizationRegistry.cleanupSome(cb);
|
||||
|
||||
assert.sameValue(called, expectedCalled, 'cleanupSome callback is not called again #2');
|
||||
assert.sameValue(holdings.length, expectedCalled, 'cleanupSome callback is not called again #2');
|
||||
assert.sameValue(cleanupCallback, 0, 'cleanupCallback is not called again #2');
|
||||
|
||||
if (holdings.length) {
|
||||
assert.compareArray(holdings, ['a']);
|
||||
}
|
||||
|
||||
await $262.gc();
|
||||
})
|
||||
.then($DONE, resolveAsyncGC);
|
||||
}).then($DONE, resolveAsyncGC);
|
||||
|
|
Loading…
Reference in New Issue