Bug 1673107 [wpt PR 26072] - [weakref] HostCleanupFinalizationRegistry is expected to call CleanupFinalizationRegistry(finalizationRegistry) at some point in the future, if possible., a=testonly

Automatic update from web-platform-tests
[weakref] HostCleanupFinalizationRegistry is expected to call CleanupFinalizationRegistry(finalizationRegistry) at some point in the future, if possible.

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.

--
Update per review

--

wpt-commits: 603a02ac17d31900edd2701780dab1df68445192, 731cc1d303d9a72422144690101765492e1d3e6c
wpt-pr: 26072
This commit is contained in:
Rick Waldron 2020-10-27 04:56:37 +00:00 коммит произвёл moz-wptsync-bot
Родитель a41ba44f58
Коммит ec6a66331b
1 изменённых файлов: 60 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,60 @@
// 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.');