1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 05:48:12 +00:00

LibWeb: Remove CSS::Parser::ParsingContext's default constructor

This relied on pulling the current realm from the main thread VM, which
requires an execution context to be on the VM's stack. This heavily
relied on the dummy execution context that is always on the stack, for
example, when parsing the UA style sheets where no JavaScript is
running.
This commit is contained in:
Luke Wilde 2023-02-28 16:54:25 +00:00 committed by Linus Groh
parent 54a1ec2f10
commit f7ff1fd985
12 changed files with 73 additions and 72 deletions

View file

@ -41,6 +41,8 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::escape)
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
{
auto& realm = *vm.current_realm();
if (!vm.argument_count())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountAtLeastOne, "CSS.supports");
@ -53,7 +55,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
auto property = CSS::property_id_from_string(property_name);
if (property != CSS::PropertyID::Invalid) {
auto value_string = TRY(vm.argument(1).to_deprecated_string(vm));
if (parse_css_value({}, value_string, property))
if (parse_css_value(CSS::Parser::ParsingContext { realm }, value_string, property))
return JS::Value(true);
}
// Otherwise, if property is a custom property name string, return true.
@ -69,11 +71,11 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
auto supports_text = TRY(vm.argument(0).to_deprecated_string(vm));
// If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
if (auto supports = parse_css_supports({}, supports_text); supports && supports->matches())
if (auto supports = parse_css_supports(CSS::Parser::ParsingContext { realm }, supports_text); supports && supports->matches())
return JS::Value(true);
// Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.
if (auto supports = parse_css_supports({}, DeprecatedString::formatted("({})", supports_text)); supports && supports->matches())
if (auto supports = parse_css_supports(CSS::Parser::ParsingContext { realm }, DeprecatedString::formatted("({})", supports_text)); supports && supports->matches())
return JS::Value(true);
// Otherwise, return false.