ajuma@chromium.org | ab1bef3 | 2018-11-06 20:52:51 +0000 | [diff] [blame] | 1 | <!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 | |
| 9 | if (window.testRunner) |
| 10 | testRunner.dumpAsText(); |
| 11 | |
| 12 | const targetCount = 5; |
| 13 | const iterationCount = 5; |
| 14 | |
| 15 | async 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 | |
| 31 | function 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 | |
| 40 | async 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 | |
| 56 | runAll(); |
| 57 | |
| 58 | </script> |
| 59 | </body> |
| 60 | </html> |