LibWeb/CSS: Integrate ParsingContext into the Parser

This is not really a context, but more of a set of parameters for
creating a Parser. So, treat it as such: Rename it to ParsingParams,
and store its values and methods directly in the Parser instead of
keeping the ParsingContext around.

This has a nice side-effect of not including DOM/Document.h everywhere
that needs a Parser.
This commit is contained in:
Sam Atkins 2025-02-05 12:08:27 +00:00
parent 30ba7e334e
commit 6a4d80b9b6
Notes: github-actions[bot] 2025-02-06 16:48:31 +00:00
49 changed files with 207 additions and 255 deletions

View file

@ -27,7 +27,7 @@ bool supports(JS::VM&, StringView property, StringView value)
// 1. If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
// and value successfully parses according to that propertys grammar, return true.
if (auto property_id = property_id_from_string(property); property_id.has_value()) {
if (parse_css_value(Parser::ParsingContext {}, value, property_id.value()))
if (parse_css_value(Parser::ParsingParams {}, value, property_id.value()))
return true;
}
@ -46,13 +46,13 @@ WebIDL::ExceptionOr<bool> supports(JS::VM& vm, StringView condition_text)
auto& realm = *vm.current_realm();
// 1. If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
if (auto supports = parse_css_supports(Parser::ParsingContext { realm }, condition_text); supports && supports->matches())
if (auto supports = parse_css_supports(Parser::ParsingParams { realm }, condition_text); supports && supports->matches())
return true;
// 2. Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.
auto wrapped_condition_text = TRY_OR_THROW_OOM(vm, String::formatted("({})", condition_text));
if (auto supports = parse_css_supports(Parser::ParsingContext { realm }, wrapped_condition_text); supports && supports->matches())
if (auto supports = parse_css_supports(Parser::ParsingParams { realm }, wrapped_condition_text); supports && supports->matches())
return true;
// 3. Otherwise, return false.