LibWeb: Handle special cases of PseudoElement::Type correctly

There are some special values for CSS::Selector::PseudoElement::Type
which are after `KnownPseudoElementCount` and therefore not present in
various arrays of pseudo elements, this leads to some errors, if a type
after `KnownPseudoElementCount` is used without checking first. This
adds explicit checks to all usages
This commit is contained in:
Totto16 2024-12-19 19:15:02 +01:00 committed by Sam Atkins
commit d21bfda900
Notes: github-actions[bot] 2024-12-19 19:37:02 +00:00
4 changed files with 59 additions and 7 deletions

View file

@ -1069,6 +1069,10 @@ void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector:
if (!existing_pseudo_element.has_value() && !pseudo_element_node)
return;
if (!CSS::Selector::PseudoElement::is_known_pseudo_element_type(pseudo_element)) {
return;
}
ensure_pseudo_element(pseudo_element).layout_node = move(pseudo_element_node);
}
@ -2279,6 +2283,11 @@ void Element::set_pseudo_element_computed_css_values(CSS::Selector::PseudoElemen
{
if (!m_pseudo_element_data && !style.has_value())
return;
if (!CSS::Selector::PseudoElement::is_known_pseudo_element_type(pseudo_element)) {
return;
}
ensure_pseudo_element(pseudo_element).computed_css_values = move(style);
}
@ -2294,6 +2303,11 @@ Optional<Element::PseudoElement&> Element::get_pseudo_element(CSS::Selector::Pse
{
if (!m_pseudo_element_data)
return {};
if (!CSS::Selector::PseudoElement::is_known_pseudo_element_type(type)) {
return {};
}
return m_pseudo_element_data->at(to_underlying(type));
}
@ -2301,6 +2315,9 @@ Element::PseudoElement& Element::ensure_pseudo_element(CSS::Selector::PseudoElem
{
if (!m_pseudo_element_data)
m_pseudo_element_data = make<PseudoElementData>();
VERIFY(CSS::Selector::PseudoElement::is_known_pseudo_element_type(type));
return m_pseudo_element_data->at(to_underlying(type));
}
@ -2310,6 +2327,11 @@ void Element::set_custom_properties(Optional<CSS::Selector::PseudoElement::Type>
m_custom_properties = move(custom_properties);
return;
}
if (!CSS::Selector::PseudoElement::is_known_pseudo_element_type(pseudo_element.value())) {
return;
}
ensure_pseudo_element(pseudo_element.value()).custom_properties = move(custom_properties);
}
@ -2317,6 +2339,9 @@ HashMap<FlyString, CSS::StyleProperty> const& Element::custom_properties(Optiona
{
if (!pseudo_element.has_value())
return m_custom_properties;
VERIFY(CSS::Selector::PseudoElement::is_known_pseudo_element_type(pseudo_element.value()));
return ensure_pseudo_element(pseudo_element.value()).custom_properties;
}