Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / LayoutTests / intersection-observer / intersection-observer-entry-keeps-js-wrappers-of-rects-alive.html
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <p>This tests that JS wrappers of rects in an IntersectionObserverEntry do not get collected.</p>
5 <pre id="log"></pre>
6 <script src="../resources/gc.js"></script>
7 <script>
8
9 if (window.testRunner)
10     testRunner.dumpAsText();
11
12 const targetCount = 5;
13 const iterationCount = 5;
14
15 for (let i = 0; i < targetCount; ++i) {
16     let target = document.createElement('div');
17     document.body.appendChild(target);
18 }
19
20 async function observe() {
21     return new Promise((resolve) => {
22         const observer = new IntersectionObserver(entries => {
23             for (const entry of entries) {
24                 entry.rootBounds.myState = 'live';
25                 entry.boundingClientRect.myState = 'live';
26                 entry.intersectionRect.myState = 'live';
27             }
28             resolve(entries);
29             observer.disconnect();
30         });
31         document.querySelectorAll('div').forEach(target => { observer.observe(target); });
32     });
33 }
34
35 function check(entries) {
36     let deadCount = 0;
37     for (const entry of entries) {
38         if (entry.rootBounds.myState != 'live')
39             deadCount++;
40         if (entry.boundingClientRect.myState != 'live')
41             deadCount++;
42         if (entry.intersectionRect.myState != 'live')
43             deadCount++;
44     }
45     document.getElementById('log').textContent += (deadCount ? `FAIL - ${deadCount} rects lost JS wrappers` : 'PASS') + '\n';
46 }
47
48 async function runAll() {
49     if (window.testRunner)
50         testRunner.waitUntilDone();
51
52     for (let j = 0; j < iterationCount; ++j) {
53         const entries = await observe();
54         await Promise.resolve();
55         gc();
56         check(entries);
57     }
58
59     if (window.testRunner)
60         testRunner.notifyDone();
61 }
62
63 runAll();
64
65 </script>
66 </body>
67 </html>