LibWeb/CSS: Parse media-feature values forgivingly

Instead of rejecting invalid media-feature values at parse time, we are
expected to parse them, and then treat them as Unknown when evaluating
their media query. To implement this, we first try to parse a valid
value as before. If that fails, or we have any trailing tokens that
could be part of a value, we then scoop up all the possible
ComponentValues and treat that as an "unknown"-type MediaFeatureValue.

This gets us 66 WPT passes.
This commit is contained in:
Sam Atkins 2025-05-22 11:56:04 +01:00
parent 72f50217b0
commit 9b8dc6b8d0
Notes: github-actions[bot] 2025-05-23 09:19:18 +00:00
15 changed files with 228 additions and 146 deletions

View file

@ -36,6 +36,9 @@ String MediaFeatureValue::to_string() const
if (integer.is_calculated())
return integer.calculated()->to_string(SerializationMode::Normal);
return String::number(integer.value());
},
[&](Vector<Parser::ComponentValue> const& values) {
return serialize_a_series_of_component_values(values);
});
}
@ -46,7 +49,8 @@ bool MediaFeatureValue::is_same_type(MediaFeatureValue const& other) const
[&](LengthOrCalculated const&) { return other.is_length(); },
[&](Ratio const&) { return other.is_ratio(); },
[&](ResolutionOrCalculated const&) { return other.is_resolution(); },
[&](IntegerOrCalculated const&) { return other.is_integer(); });
[&](IntegerOrCalculated const&) { return other.is_integer(); },
[&](Vector<Parser::ComponentValue> const&) { return other.is_unknown(); });
}
String MediaFeature::to_string() const
@ -149,6 +153,9 @@ MatchResult MediaFeature::evaluate(HTML::Window const* window) const
MatchResult MediaFeature::compare(HTML::Window const& window, MediaFeatureValue const& left, Comparison comparison, MediaFeatureValue const& right)
{
if (left.is_unknown() || right.is_unknown())
return MatchResult::Unknown;
if (!left.is_same_type(right))
return MatchResult::False;