blob: fcc335e7a82da9a6a9b431ed0ce8ae67d2370ce8 [file] [log] [blame]
ajuma@chromium.orgab1bef32018-11-06 20:52:51 +00001<!DOCTYPE html>
2<html>
3<body>
4<p>This tests that JS wrappers of targets in an IntersectionObserverEntry do not get collected.</p>
5<pre id="log"></pre>
6<script src="../resources/gc.js"></script>
7<script>
8
9if (window.testRunner)
10 testRunner.dumpAsText();
11
12const targetCount = 5;
13const iterationCount = 5;
14
15async function observe() {
16 for (let i = 0; i < targetCount; ++i) {
17 let target = document.createElement('div');
18 target.myState = 'live';
19 document.body.appendChild(target);
20 }
21
22 return new Promise((resolve) => {
23 const observer = new IntersectionObserver(entries => {
24 resolve(entries);
25 observer.disconnect();
26 });
27 document.querySelectorAll('div').forEach(target => { observer.observe(target); });
28 });
29}
30
31function check(entries) {
32 let deadCount = 0;
33 for (const entry of entries) {
34 if (entry.target.myState != 'live')
35 deadCount++;
36 }
37 document.getElementById('log').textContent += (deadCount ? `FAIL - ${deadCount} targets lost JS wrappers` : 'PASS') + '\n';
38}
39
40async function runAll() {
41 if (window.testRunner)
42 testRunner.waitUntilDone();
43
44 for (let j = 0; j < iterationCount; ++j) {
45 const entries = await observe();
46 document.querySelectorAll('div').forEach(target => { target.remove(); });
47 await Promise.resolve();
48 gc();
49 check(entries);
50 }
51
52 if (window.testRunner)
53 testRunner.notifyDone();
54}
55
56runAll();
57
58</script>
59</body>
60</html>