blob: 3cf844522af121afdd002ca7869e10282967f48a [file] [log] [blame]
<!DOCTYPE html><!-- webkit-test-runner [ experimental:ResizeObserverEnabled=true ] -->
<html>
<body>
<p>This tests that JS wrappers of targets in an ResizeObserverEntry do not get collected.</p>
<pre id="log"></pre>
<script src="../resources/gc.js"></script>
<script>
if (window.testRunner)
testRunner.dumpAsText();
const targetCount = 5;
const iterationCount = 10;
async function observe() {
for (let i = 0; i < targetCount; ++i) {
let target = document.createElement('div');
target.myState = 'live';
document.body.appendChild(target);
}
return new Promise((resolve) => {
const observer = new ResizeObserver(entries => {
resolve(entries);
observer.disconnect();
});
document.querySelectorAll('div').forEach(target => observer.observe(target));
});
}
function check(entries) {
let deadCount = 0;
for (const entry of entries) {
if (entry.target.myState != 'live')
deadCount++;
}
document.getElementById('log').textContent += (deadCount ? `FAIL - ${deadCount} targets lost JS wrappers` : 'PASS') + '\n';
}
async function runAll() {
if (window.testRunner)
testRunner.waitUntilDone();
for (let j = 0; j < iterationCount; ++j) {
const entries = await observe();
document.querySelectorAll('div').forEach(target => target.remove());
await Promise.resolve();
gc();
check(entries);
}
if (window.testRunner)
testRunner.notifyDone();
}
runAll();
</script>
</body>
</html>