ladybird/Tests/LibWeb/Crash/JS/finalization-registry-basic.html
Andreas Kling 51a91771b8 LibJS+LibGC: Run FinalizationRegistry cleanup host hook *after* GC
Before this change, it was possible for a second GC to get triggered
in the middle of a first GC, due to allocations happening in the
FinalizationRegistry cleanup host hook. To avoid this causing problems,
we add a "post-GC task" mechanism and use that to invoke the host hook
once all other GC activity is finished, and we've unset the "collecting
garbage" flag.

Note that the test included here only fails reliably when running with
the -g flag (collect garbage after each allocation).

Fixes #3051
2025-01-23 12:10:21 +01:00

19 lines
393 B
HTML

<script src="../include.js"></script>
<script>
// NOTE: This test is only reliable when GC'ing after each allocation.
const registry = new FinalizationRegistry((heldValue) => {
console.log(heldValue);
});
const makeGarbage = () => {
registry.register(new String("ok"), "hello");
};
makeGarbage();
if (window.internals !== undefined)
internals.gc();
println("PASS");
</script>