-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IntersectionObserverEntry doesn't keep JS wrappers of rects alive
https://bugs.webkit.org/show_bug.cgi?id=191330 Reviewed by Chris Dumez. Source/WebCore: Retain wrappers of each rect in an IntersectionObserverEntry as long as the entry's wrapper is alive, by adding these wrappers as opaque roots. Test: intersection-observer/intersection-observer-entry-keeps-js-wrappers-of-rects-alive.html * bindings/js/JSIntersectionObserverEntryCustom.cpp: (WebCore::JSIntersectionObserverEntry::visitAdditionalChildren): * dom/DOMRectReadOnly.idl: * page/IntersectionObserverEntry.h: (WebCore::IntersectionObserverEntry::rootBounds const): Make this return a raw pointer instead of a RefPtr so that it can be called in JSIntersectionObserverEntry::visitAdditionalChildren, which can be called from non-main threads. (WebCore::IntersectionObserverEntry::boundingClientRect const): Ditto. (WebCore::IntersectionObserverEntry::intersectionRect const): Ditto. LayoutTests: Add test coverage. * intersection-observer/intersection-observer-entry-keeps-js-wrappers-of-rects-alive-expected.txt: Added. * intersection-observer/intersection-observer-entry-keeps-js-wrappers-of-rects-alive.html: Added. Canonical link: https://commits.webkit.org/206168@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237929 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
7 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ection-observer/intersection-observer-entry-keeps-js-wrappers-of-rects-alive-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This tests that JS wrappers of rects in an IntersectionObserverEntry do not get collected. | ||
|
||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
PASS | ||
|
67 changes: 67 additions & 0 deletions
67
...s/intersection-observer/intersection-observer-entry-keeps-js-wrappers-of-rects-alive.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<p>This tests that JS wrappers of rects in an IntersectionObserverEntry 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 = 5; | ||
|
||
for (let i = 0; i < targetCount; ++i) { | ||
let target = document.createElement('div'); | ||
document.body.appendChild(target); | ||
} | ||
|
||
async function observe() { | ||
return new Promise((resolve) => { | ||
const observer = new IntersectionObserver(entries => { | ||
for (const entry of entries) { | ||
entry.rootBounds.myState = 'live'; | ||
entry.boundingClientRect.myState = 'live'; | ||
entry.intersectionRect.myState = 'live'; | ||
} | ||
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.rootBounds.myState != 'live') | ||
deadCount++; | ||
if (entry.boundingClientRect.myState != 'live') | ||
deadCount++; | ||
if (entry.intersectionRect.myState != 'live') | ||
deadCount++; | ||
} | ||
document.getElementById('log').textContent += (deadCount ? `FAIL - ${deadCount} rects lost JS wrappers` : 'PASS') + '\n'; | ||
} | ||
|
||
async function runAll() { | ||
if (window.testRunner) | ||
testRunner.waitUntilDone(); | ||
|
||
for (let j = 0; j < iterationCount; ++j) { | ||
const entries = await observe(); | ||
await Promise.resolve(); | ||
gc(); | ||
check(entries); | ||
} | ||
|
||
if (window.testRunner) | ||
testRunner.notifyDone(); | ||
} | ||
|
||
runAll(); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters