LibWeb: Stop passing Realm unnecessarily to parse CSS properties

Also use the parse_css_value() helper in cases where we previously
constructed a Parser manually.
This commit is contained in:
Sam Atkins 2024-12-05 11:52:43 +00:00 committed by Alexander Kalenik
commit bc77f84359
Notes: github-actions[bot] 2024-12-05 19:00:42 +00:00
11 changed files with 20 additions and 46 deletions

View file

@ -57,13 +57,6 @@ static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> load_vector_fo
GC_DEFINE_ALLOCATOR(FontFace);
template<CSS::PropertyID PropertyID>
RefPtr<CSSStyleValue const> parse_property_string(JS::Realm& realm, StringView value)
{
auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), value);
return parser.parse_as_css_value(PropertyID);
}
// https://drafts.csswg.org/css-font-loading/#font-face-constructor
GC::Ref<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, FontFaceSource source, FontFaceDescriptors const& descriptors)
{
@ -213,7 +206,7 @@ GC::Ref<WebIDL::Promise> FontFace::loaded() const
// https://drafts.csswg.org/css-font-loading/#dom-fontface-family
WebIDL::ExceptionOr<void> FontFace::set_family(String const& string)
{
auto property = parse_property_string<CSS::PropertyID::FontFamily>(realm(), string);
auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontFamily);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.family setter: Invalid font descriptor"_string);
@ -229,7 +222,7 @@ WebIDL::ExceptionOr<void> FontFace::set_family(String const& string)
// https://drafts.csswg.org/css-font-loading/#dom-fontface-style
WebIDL::ExceptionOr<void> FontFace::set_style(String const& string)
{
auto property = parse_property_string<CSS::PropertyID::FontStyle>(realm(), string);
auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontStyle);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.style setter: Invalid font descriptor"_string);
@ -245,7 +238,7 @@ WebIDL::ExceptionOr<void> FontFace::set_style(String const& string)
// https://drafts.csswg.org/css-font-loading/#dom-fontface-weight
WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string)
{
auto property = parse_property_string<CSS::PropertyID::FontWeight>(realm(), string);
auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontWeight);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.weight setter: Invalid font descriptor"_string);
@ -262,7 +255,7 @@ WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string)
WebIDL::ExceptionOr<void> FontFace::set_stretch(String const& string)
{
// NOTE: font-stretch is now an alias for font-width
auto property = parse_property_string<CSS::PropertyID::FontWidth>(realm(), string);
auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontWidth);
if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_string);