mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-19 15:32:31 +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
|
@ -464,6 +464,9 @@ String HTMLElement::outer_text()
|
|||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-scrollparent
|
||||
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:
|
||||
// - The element does not have an associated box.
|
||||
// - 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:
|
||||
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
|
||||
// is not closed-shadow-hidden from the element, otherwise return null.
|
||||
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
|
||||
// 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()));
|
||||
}
|
||||
|
||||
|
@ -498,8 +502,10 @@ GC::Ptr<DOM::Element> HTMLElement::scroll_parent() const
|
|||
// position containing block, terminate this algorithm and return null.
|
||||
|
||||
// 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue