mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 05:39:11 +00:00
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:
parent
ee9db99961
commit
bc77f84359
Notes:
github-actions[bot]
2024-12-05 19:00:42 +00:00
Author: https://github.com/AtkinsSJ
Commit: bc77f84359
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2783
11 changed files with 20 additions and 46 deletions
|
@ -22,14 +22,12 @@ WebIDL::ExceptionOr<String> escape(JS::VM&, StringView identifier)
|
|||
}
|
||||
|
||||
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
|
||||
bool supports(JS::VM& vm, StringView property, StringView value)
|
||||
bool supports(JS::VM&, StringView property, StringView value)
|
||||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 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 property’s grammar, return true.
|
||||
if (auto property_id = property_id_from_string(property); property_id.has_value()) {
|
||||
if (parse_css_value(Parser::ParsingContext { realm }, value, property_id.value()))
|
||||
if (parse_css_value(Parser::ParsingContext {}, value, property_id.value()))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ WebIDL::ExceptionOr<void> PropertyOwningCSSStyleDeclaration::set_property(String
|
|||
// 5. Let component value list be the result of parsing value for property property.
|
||||
auto component_value_list = is<ElementInlineCSSStyleDeclaration>(this)
|
||||
? parse_css_value(CSS::Parser::ParsingContext { static_cast<ElementInlineCSSStyleDeclaration&>(*this).element()->document() }, value, property_id)
|
||||
: parse_css_value(CSS::Parser::ParsingContext { realm() }, value, property_id);
|
||||
: parse_css_value(CSS::Parser::ParsingContext {}, value, property_id);
|
||||
|
||||
// 6. If component value list is null, then return.
|
||||
if (!component_value_list)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -174,8 +174,7 @@ WebIDL::CallbackType* FontFaceSet::onloadingerror()
|
|||
static WebIDL::ExceptionOr<GC::Ref<JS::Set>> find_matching_font_faces(JS::Realm& realm, FontFaceSet& font_face_set, String const& font, String const&)
|
||||
{
|
||||
// 1. Parse font using the CSS value syntax of the font property. If a syntax error occurs, return a syntax error.
|
||||
auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), font);
|
||||
auto property = parser.parse_as_css_value(PropertyID::Font);
|
||||
auto property = parse_css_value(CSS::Parser::ParsingContext(), font, PropertyID::Font);
|
||||
if (!property)
|
||||
return WebIDL::SyntaxError::create(realm, "Unable to parse font"_string);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue