LibWeb: Include own shadow root in for_each_shadow_including_descendant

Fixes a crash in wpt.live/css/cssom/CSSStyleSheet-constructable.html
This commit is contained in:
Callum Law 2025-07-12 00:41:57 +12:00 committed by Andreas Kling
commit d980321a77
Notes: github-actions[bot] 2025-07-11 14:22:20 +00:00
3 changed files with 848 additions and 10 deletions

View file

@ -126,6 +126,15 @@ inline TraversalDecision Node::for_each_shadow_including_inclusive_descendant(Ca
if (callback(*this) == TraversalDecision::Break)
return TraversalDecision::Break;
if (this->for_each_shadow_including_descendant(callback) == TraversalDecision::Break)
return TraversalDecision::Break;
return TraversalDecision::Continue;
}
template<typename Callback>
inline TraversalDecision Node::for_each_shadow_including_descendant(Callback callback)
{
if (is_element()) {
if (auto shadow_root = static_cast<Element*>(this)->shadow_root()) {
if (shadow_root->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break)
@ -141,14 +150,4 @@ inline TraversalDecision Node::for_each_shadow_including_inclusive_descendant(Ca
return TraversalDecision::Continue;
}
template<typename Callback>
inline TraversalDecision Node::for_each_shadow_including_descendant(Callback callback)
{
for (auto* child = first_child(); child; child = child->next_sibling()) {
if (child->for_each_shadow_including_inclusive_descendant(callback) == TraversalDecision::Break)
return TraversalDecision::Break;
}
return TraversalDecision::Continue;
}
}