mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb: Avoid infinite loop in HTMLElement.scrollParent
Some checks failed
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
Push notes / build (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Build Dev Container Image / build (push) Has been cancelled
Some checks failed
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
Push notes / build (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Build Dev Container Image / build (push) Has been cancelled
We were failing to actually climb up the containing block chain, causing this API to infinite loop for anything but the most trivial cases. By fixing the loop structure, we also make a bunch of the already imported WPT tests pass. :^)
This commit is contained in:
parent
8d1c860fcd
commit
b3d9e39bad
Notes:
github-actions[bot]
2025-06-30 19:39:31 +00:00
Author: https://github.com/awesomekling
Commit: b3d9e39bad
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5248
Reviewed-by: https://github.com/tcl3 ✅
6 changed files with 33 additions and 15 deletions
|
@ -98,6 +98,7 @@ enum class InvalidateLayoutTreeReason {
|
||||||
X(HTMLElementOffsetParent) \
|
X(HTMLElementOffsetParent) \
|
||||||
X(HTMLElementOffsetTop) \
|
X(HTMLElementOffsetTop) \
|
||||||
X(HTMLElementOffsetWidth) \
|
X(HTMLElementOffsetWidth) \
|
||||||
|
X(HTMLElementScrollParent) \
|
||||||
X(HTMLEventLoopRenderingUpdate) \
|
X(HTMLEventLoopRenderingUpdate) \
|
||||||
X(HTMLImageElementHeight) \
|
X(HTMLImageElementHeight) \
|
||||||
X(HTMLImageElementWidth) \
|
X(HTMLImageElementWidth) \
|
||||||
|
|
|
@ -464,6 +464,9 @@ String HTMLElement::outer_text()
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-scrollparent
|
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-scrollparent
|
||||||
GC::Ptr<DOM::Element> HTMLElement::scroll_parent() const
|
GC::Ptr<DOM::Element> HTMLElement::scroll_parent() const
|
||||||
{
|
{
|
||||||
|
// NOTE: We have to ensure that the layout is up-to-date before querying the layout tree.
|
||||||
|
const_cast<DOM::Document&>(document()).update_layout(DOM::UpdateLayoutReason::HTMLElementScrollParent);
|
||||||
|
|
||||||
// 1. If any of the following holds true, return null and terminate this algorithm:
|
// 1. If any of the following holds true, return null and terminate this algorithm:
|
||||||
// - The element does not have an associated box.
|
// - The element does not have an associated box.
|
||||||
// - The element is the root element.
|
// - The element is the root element.
|
||||||
|
@ -478,7 +481,7 @@ GC::Ptr<DOM::Element> HTMLElement::scroll_parent() const
|
||||||
|
|
||||||
// 2. Let ancestor be the containing block of the element in the flat tree and repeat these substeps:
|
// 2. Let ancestor be the containing block of the element in the flat tree and repeat these substeps:
|
||||||
auto ancestor = layout_node()->containing_block();
|
auto ancestor = layout_node()->containing_block();
|
||||||
while (true) {
|
while (ancestor) {
|
||||||
// 1. If ancestor is the initial containing block, return the scrollingElement for the element’s document if it
|
// 1. If ancestor is the initial containing block, return the scrollingElement for the element’s document if it
|
||||||
// is not closed-shadow-hidden from the element, otherwise return null.
|
// is not closed-shadow-hidden from the element, otherwise return null.
|
||||||
if (ancestor->is_viewport()) {
|
if (ancestor->is_viewport()) {
|
||||||
|
@ -490,7 +493,8 @@ GC::Ptr<DOM::Element> HTMLElement::scroll_parent() const
|
||||||
|
|
||||||
// 2. If ancestor is not closed-shadow-hidden from the element, and is a scroll container, terminate this
|
// 2. If ancestor is not closed-shadow-hidden from the element, and is a scroll container, terminate this
|
||||||
// algorithm and return ancestor.
|
// algorithm and return ancestor.
|
||||||
if (!ancestor->dom_node()->is_closed_shadow_hidden_from(*this) && ancestor->is_scroll_container()) {
|
if ((ancestor->dom_node() && !ancestor->dom_node()->is_closed_shadow_hidden_from(*this))
|
||||||
|
&& ancestor->is_scroll_container()) {
|
||||||
return const_cast<Element*>(static_cast<DOM::Element const*>(ancestor->dom_node()));
|
return const_cast<Element*>(static_cast<DOM::Element const*>(ancestor->dom_node()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,8 +502,10 @@ GC::Ptr<DOM::Element> HTMLElement::scroll_parent() const
|
||||||
// position containing block, terminate this algorithm and return null.
|
// position containing block, terminate this algorithm and return null.
|
||||||
|
|
||||||
// 4. Let ancestor be the containing block of ancestor in the flat tree.
|
// 4. Let ancestor be the containing block of ancestor in the flat tree.
|
||||||
ancestor = layout_node()->containing_block();
|
ancestor = ancestor->containing_block();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsetparent
|
// https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsetparent
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
PASS (didn't hang)
|
|
@ -2,8 +2,9 @@ Harness status: OK
|
||||||
|
|
||||||
Found 4 tests
|
Found 4 tests
|
||||||
|
|
||||||
4 Fail
|
3 Pass
|
||||||
Fail scrollParent skips intermediate closed shadow tree nodes
|
1 Fail
|
||||||
|
Pass scrollParent skips intermediate closed shadow tree nodes
|
||||||
Fail scrollParent skips intermediate open shadow tree nodes
|
Fail scrollParent skips intermediate open shadow tree nodes
|
||||||
Fail scrollParent from inside closed shadow tree
|
Pass scrollParent from inside closed shadow tree
|
||||||
Fail scrollParent from inside open shadow tree
|
Pass scrollParent from inside open shadow tree
|
|
@ -2,14 +2,14 @@ Harness status: OK
|
||||||
|
|
||||||
Found 9 tests
|
Found 9 tests
|
||||||
|
|
||||||
3 Pass
|
7 Pass
|
||||||
6 Fail
|
2 Fail
|
||||||
Fail scrollParent returns the nearest scroll container.
|
Pass scrollParent returns the nearest scroll container.
|
||||||
Fail hidden element is a scroll container.
|
Pass hidden element is a scroll container.
|
||||||
Pass Element with no box has null scrollParent.
|
Pass Element with no box has null scrollParent.
|
||||||
Fail scrollParent follows absolute positioned containing block chain.
|
Pass scrollParent follows absolute positioned containing block chain.
|
||||||
Fail scrollParent follows fixed positioned containing block chain.
|
Fail scrollParent follows fixed positioned containing block chain.
|
||||||
Pass scrollParent of element fixed to root is null.
|
Fail scrollParent of element fixed to root is null.
|
||||||
Fail scrollParent of child in root viewport returns document scrolling element.
|
Pass scrollParent of child in root viewport returns document scrolling element.
|
||||||
Fail scrollParent of fixed element contained within root is document scrolling element.
|
Pass scrollParent of fixed element contained within root is document scrolling element.
|
||||||
Pass scrollParent of body is null.
|
Pass scrollParent of body is null.
|
|
@ -0,0 +1,9 @@
|
||||||
|
<!doctype html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<body><div id=foo><div id=bar></div></div>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
bar.scrollParent;
|
||||||
|
println("PASS (didn't hang)");
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue