LibWeb/CSS: Use FlyString for CSSStyleValue property name

This commit is contained in:
Sam Atkins 2025-09-25 13:00:43 +01:00
parent a8312bf571
commit a30afafcc9
22 changed files with 32 additions and 31 deletions

View File

@ -15,7 +15,7 @@ namespace Web::CSS {
GC_DEFINE_ALLOCATOR(CSSStyleValue); GC_DEFINE_ALLOCATOR(CSSStyleValue);
GC::Ref<CSSStyleValue> CSSStyleValue::create(JS::Realm& realm, String associated_property, String constructed_from_string) GC::Ref<CSSStyleValue> CSSStyleValue::create(JS::Realm& realm, FlyString associated_property, String constructed_from_string)
{ {
return realm.create<CSSStyleValue>(realm, move(associated_property), move(constructed_from_string)); return realm.create<CSSStyleValue>(realm, move(associated_property), move(constructed_from_string));
} }
@ -25,7 +25,7 @@ CSSStyleValue::CSSStyleValue(JS::Realm& realm)
{ {
} }
CSSStyleValue::CSSStyleValue(JS::Realm& realm, String associated_property, String constructed_from_string) CSSStyleValue::CSSStyleValue(JS::Realm& realm, FlyString associated_property, String constructed_from_string)
: PlatformObject(realm) : PlatformObject(realm)
, m_associated_property(move(associated_property)) , m_associated_property(move(associated_property))
, m_constructed_from_string(move(constructed_from_string)) , m_constructed_from_string(move(constructed_from_string))
@ -39,7 +39,7 @@ void CSSStyleValue::initialize(JS::Realm& realm)
} }
// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylevalue-parse // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylevalue-parse
WebIDL::ExceptionOr<GC::Ref<CSSStyleValue>> CSSStyleValue::parse(JS::VM& vm, String property, String css_text) WebIDL::ExceptionOr<GC::Ref<CSSStyleValue>> CSSStyleValue::parse(JS::VM& vm, FlyString const& property, String css_text)
{ {
// The parse(property, cssText) method, when invoked, must parse a CSSStyleValue with property property, cssText // The parse(property, cssText) method, when invoked, must parse a CSSStyleValue with property property, cssText
// cssText, and parseMultiple set to false, and return the result. // cssText, and parseMultiple set to false, and return the result.
@ -50,7 +50,7 @@ WebIDL::ExceptionOr<GC::Ref<CSSStyleValue>> CSSStyleValue::parse(JS::VM& vm, Str
} }
// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylevalue-parseall // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylevalue-parseall
WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> CSSStyleValue::parse_all(JS::VM& vm, String property, String css_text) WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> CSSStyleValue::parse_all(JS::VM& vm, FlyString const& property, String css_text)
{ {
// The parseAll(property, cssText) method, when invoked, must parse a CSSStyleValue with property property, cssText // The parseAll(property, cssText) method, when invoked, must parse a CSSStyleValue with property property, cssText
// cssText, and parseMultiple set to true, and return the result. // cssText, and parseMultiple set to true, and return the result.
@ -61,7 +61,7 @@ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> CSSStyleValue::parse
} }
// https://drafts.css-houdini.org/css-typed-om-1/#parse-a-cssstylevalue // https://drafts.css-houdini.org/css-typed-om-1/#parse-a-cssstylevalue
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, GC::RootVector<GC::Ref<CSSStyleValue>>>> CSSStyleValue::parse_a_css_style_value(JS::VM& vm, String property, String css_text, ParseMultiple parse_multiple) WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, GC::RootVector<GC::Ref<CSSStyleValue>>>> CSSStyleValue::parse_a_css_style_value(JS::VM& vm, FlyString property, String css_text, ParseMultiple parse_multiple)
{ {
// 1. If property is not a custom property name string, set property to property ASCII lowercased. // 1. If property is not a custom property name string, set property to property ASCII lowercased.
if (!is_a_custom_property_name_string(property)) if (!is_a_custom_property_name_string(property))

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/FlyString.h>
#include <LibWeb/Bindings/PlatformObject.h> #include <LibWeb/Bindings/PlatformObject.h>
namespace Web::CSS { namespace Web::CSS {
@ -16,14 +17,14 @@ class CSSStyleValue : public Bindings::PlatformObject {
GC_DECLARE_ALLOCATOR(CSSStyleValue); GC_DECLARE_ALLOCATOR(CSSStyleValue);
public: public:
[[nodiscard]] static GC::Ref<CSSStyleValue> create(JS::Realm&, String associated_property, String constructed_from_string); [[nodiscard]] static GC::Ref<CSSStyleValue> create(JS::Realm&, FlyString associated_property, String constructed_from_string);
virtual ~CSSStyleValue() override = default; virtual ~CSSStyleValue() override = default;
virtual void initialize(JS::Realm&) override; virtual void initialize(JS::Realm&) override;
static WebIDL::ExceptionOr<GC::Ref<CSSStyleValue>> parse(JS::VM&, String property, String css_text); static WebIDL::ExceptionOr<GC::Ref<CSSStyleValue>> parse(JS::VM&, FlyString const& property, String css_text);
static WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> parse_all(JS::VM&, String property, String css_text); static WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> parse_all(JS::VM&, FlyString const& property, String css_text);
virtual WebIDL::ExceptionOr<String> to_string() const; virtual WebIDL::ExceptionOr<String> to_string() const;
@ -31,16 +32,16 @@ protected:
explicit CSSStyleValue(JS::Realm&); explicit CSSStyleValue(JS::Realm&);
private: private:
explicit CSSStyleValue(JS::Realm&, String associated_property, String constructed_from_string); explicit CSSStyleValue(JS::Realm&, FlyString associated_property, String constructed_from_string);
enum class ParseMultiple : u8 { enum class ParseMultiple : u8 {
No, No,
Yes, Yes,
}; };
static WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, GC::RootVector<GC::Ref<CSSStyleValue>>>> parse_a_css_style_value(JS::VM&, String property, String css_text, ParseMultiple); static WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, GC::RootVector<GC::Ref<CSSStyleValue>>>> parse_a_css_style_value(JS::VM&, FlyString property, String css_text, ParseMultiple);
// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylevalue-associatedproperty-slot // https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylevalue-associatedproperty-slot
Optional<String> m_associated_property; Optional<FlyString> m_associated_property;
Optional<String> m_constructed_from_string; Optional<String> m_constructed_from_string;
}; };

View File

@ -10,7 +10,7 @@
namespace Web::CSS { namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#reify-stylevalue // https://drafts.css-houdini.org/css-typed-om-1/#reify-stylevalue
GC::Ref<CSSStyleValue> AbstractImageStyleValue::reify(JS::Realm& realm, String const&) const GC::Ref<CSSStyleValue> AbstractImageStyleValue::reify(JS::Realm& realm, FlyString const&) const
{ {
// AD-HOC: There's no spec description of how to reify as a CSSImageValue. // AD-HOC: There's no spec description of how to reify as a CSSImageValue.
return CSSImageValue::create(realm, to_string(SerializationMode::Normal)); return CSSImageValue::create(realm, to_string(SerializationMode::Normal));

View File

@ -41,7 +41,7 @@ public:
virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const { return {}; } virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const { return {}; }
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
}; };
// And now, some gradient related things. Maybe these should live somewhere else. // And now, some gradient related things. Maybe these should live somewhere else.

View File

@ -2772,7 +2772,7 @@ String CalculatedStyleValue::dump() const
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-a-math-expression // https://drafts.css-houdini.org/css-typed-om-1/#reify-a-math-expression
GC::Ref<CSSStyleValue> CalculatedStyleValue::reify(JS::Realm& realm, String const& associated_property) const GC::Ref<CSSStyleValue> CalculatedStyleValue::reify(JS::Realm& realm, FlyString const& associated_property) const
{ {
// NB: This spec algorithm isn't really implementable here - it's incomplete, and assumes we don't already have a // NB: This spec algorithm isn't really implementable here - it's incomplete, and assumes we don't already have a
// calculation tree. So we have a per-node method instead. // calculation tree. So we have a per-node method instead.

View File

@ -110,7 +110,7 @@ public:
String dump() const; String dump() const;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
private: private:
explicit CalculatedStyleValue(NonnullRefPtr<CalculationNode const> calculation, NumericType resolved_type, CalculationContext context) explicit CalculatedStyleValue(NonnullRefPtr<CalculationNode const> calculation, NumericType resolved_type, CalculationContext context)

View File

@ -16,7 +16,7 @@ Vector<Parser::ComponentValue> CustomIdentStyleValue::tokenize() const
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-ident // https://drafts.css-houdini.org/css-typed-om-1/#reify-ident
GC::Ref<CSSStyleValue> CustomIdentStyleValue::reify(JS::Realm& realm, String const&) const GC::Ref<CSSStyleValue> CustomIdentStyleValue::reify(JS::Realm& realm, FlyString const&) const
{ {
// 1. Return a new CSSKeywordValue with its value internal slot set to the serialization of ident. // 1. Return a new CSSKeywordValue with its value internal slot set to the serialization of ident.
return CSSKeywordValue::create(realm, m_custom_ident); return CSSKeywordValue::create(realm, m_custom_ident);

View File

@ -25,7 +25,7 @@ public:
virtual String to_string(SerializationMode) const override { return serialize_an_identifier(m_custom_ident.to_string()); } virtual String to_string(SerializationMode) const override { return serialize_an_identifier(m_custom_ident.to_string()); }
virtual Vector<Parser::ComponentValue> tokenize() const override; virtual Vector<Parser::ComponentValue> tokenize() const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm& realm, String const&) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm& realm, FlyString const&) const override;
bool properties_equal(CustomIdentStyleValue const& other) const { return m_custom_ident == other.m_custom_ident; } bool properties_equal(CustomIdentStyleValue const& other) const { return m_custom_ident == other.m_custom_ident; }

View File

@ -15,7 +15,7 @@ Vector<Parser::ComponentValue> DimensionStyleValue::tokenize() const
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-a-numeric-value // https://drafts.css-houdini.org/css-typed-om-1/#reify-a-numeric-value
GC::Ref<CSSStyleValue> DimensionStyleValue::reify(JS::Realm& realm, String const&) const GC::Ref<CSSStyleValue> DimensionStyleValue::reify(JS::Realm& realm, FlyString const&) const
{ {
// NB: Steps 1 and 2 don't apply here. // NB: Steps 1 and 2 don't apply here.
// 3. Return a new CSSUnitValue with its value internal slot set to the numeric value of num, and its unit internal // 3. Return a new CSSUnitValue with its value internal slot set to the numeric value of num, and its unit internal

View File

@ -20,7 +20,7 @@ public:
virtual double raw_value() const = 0; virtual double raw_value() const = 0;
virtual FlyString unit_name() const = 0; virtual FlyString unit_name() const = 0;
virtual Vector<Parser::ComponentValue> tokenize() const override; virtual Vector<Parser::ComponentValue> tokenize() const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
protected: protected:
explicit DimensionStyleValue(Type type) explicit DimensionStyleValue(Type type)

View File

@ -21,7 +21,7 @@ Vector<Parser::ComponentValue> IntegerStyleValue::tokenize() const
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-a-numeric-value // https://drafts.css-houdini.org/css-typed-om-1/#reify-a-numeric-value
GC::Ref<CSSStyleValue> IntegerStyleValue::reify(JS::Realm& realm, String const& associated_property) const GC::Ref<CSSStyleValue> IntegerStyleValue::reify(JS::Realm& realm, FlyString const& associated_property) const
{ {
// NB: Step 1 doesn't apply here. // NB: Step 1 doesn't apply here.
// 2. If num is the unitless value 0 and num is a <dimension>, return a new CSSUnitValue with its value internal // 2. If num is the unitless value 0 and num is a <dimension>, return a new CSSUnitValue with its value internal

View File

@ -21,7 +21,7 @@ public:
virtual String to_string(SerializationMode) const override; virtual String to_string(SerializationMode) const override;
virtual Vector<Parser::ComponentValue> tokenize() const override; virtual Vector<Parser::ComponentValue> tokenize() const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
bool equals(StyleValue const& other) const override bool equals(StyleValue const& other) const override
{ {

View File

@ -349,7 +349,7 @@ Vector<Parser::ComponentValue> KeywordStyleValue::tokenize() const
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-ident // https://drafts.css-houdini.org/css-typed-om-1/#reify-ident
GC::Ref<CSSStyleValue> KeywordStyleValue::reify(JS::Realm& realm, String const&) const GC::Ref<CSSStyleValue> KeywordStyleValue::reify(JS::Realm& realm, FlyString const&) const
{ {
// 1. Return a new CSSKeywordValue with its value internal slot set to the serialization of ident. // 1. Return a new CSSKeywordValue with its value internal slot set to the serialization of ident.
return CSSKeywordValue::create(realm, FlyString::from_utf8_without_validation(string_from_keyword(m_keyword).bytes())); return CSSKeywordValue::create(realm, FlyString::from_utf8_without_validation(string_from_keyword(m_keyword).bytes()));

View File

@ -52,7 +52,7 @@ public:
virtual Optional<Color> to_color(ColorResolutionContext) const override; virtual Optional<Color> to_color(ColorResolutionContext) const override;
virtual String to_string(SerializationMode) const override; virtual String to_string(SerializationMode) const override;
virtual Vector<Parser::ComponentValue> tokenize() const override; virtual Vector<Parser::ComponentValue> tokenize() const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
bool properties_equal(KeywordStyleValue const& other) const { return m_keyword == other.m_keyword; } bool properties_equal(KeywordStyleValue const& other) const { return m_keyword == other.m_keyword; }

View File

@ -25,7 +25,7 @@ Vector<Parser::ComponentValue> NumberStyleValue::tokenize() const
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-a-numeric-value // https://drafts.css-houdini.org/css-typed-om-1/#reify-a-numeric-value
GC::Ref<CSSStyleValue> NumberStyleValue::reify(JS::Realm& realm, String const& associated_property) const GC::Ref<CSSStyleValue> NumberStyleValue::reify(JS::Realm& realm, FlyString const& associated_property) const
{ {
// NB: Step 1 doesn't apply here. // NB: Step 1 doesn't apply here.
// 2. If num is the unitless value 0 and num is a <dimension>, return a new CSSUnitValue with its value internal // 2. If num is the unitless value 0 and num is a <dimension>, return a new CSSUnitValue with its value internal

View File

@ -24,7 +24,7 @@ public:
virtual String to_string(SerializationMode) const override; virtual String to_string(SerializationMode) const override;
virtual Vector<Parser::ComponentValue> tokenize() const override; virtual Vector<Parser::ComponentValue> tokenize() const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
bool equals(StyleValue const& other) const override bool equals(StyleValue const& other) const override
{ {

View File

@ -145,7 +145,7 @@ Vector<Parser::ComponentValue> StyleValue::tokenize() const
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-as-a-cssstylevalue // https://drafts.css-houdini.org/css-typed-om-1/#reify-as-a-cssstylevalue
GC::Ref<CSSStyleValue> StyleValue::reify(JS::Realm& realm, String const& associated_property) const GC::Ref<CSSStyleValue> StyleValue::reify(JS::Realm& realm, FlyString const& associated_property) const
{ {
// 1. Return a new CSSStyleValue object representing value whose [[associatedProperty]] internal slot is set to property. // 1. Return a new CSSStyleValue object representing value whose [[associatedProperty]] internal slot is set to property.
return CSSStyleValue::create(realm, associated_property, to_string(SerializationMode::Normal)); return CSSStyleValue::create(realm, associated_property, to_string(SerializationMode::Normal));

View File

@ -209,7 +209,7 @@ public:
virtual String to_string(SerializationMode) const = 0; virtual String to_string(SerializationMode) const = 0;
virtual Vector<Parser::ComponentValue> tokenize() const; virtual Vector<Parser::ComponentValue> tokenize() const;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const;
virtual void set_style_sheet(GC::Ptr<CSSStyleSheet>) { } virtual void set_style_sheet(GC::Ptr<CSSStyleSheet>) { }
virtual void visit_edges(JS::Cell::Visitor&) const { } virtual void visit_edges(JS::Cell::Visitor&) const { }

View File

@ -98,7 +98,7 @@ static GC::Ref<CSSStyleValue> reify_a_transform_list(JS::Realm& realm, StyleValu
return CSSTransformValue::create(realm, static_cast<Vector<GC::Ref<CSSTransformComponent>>>(move(transform_components))); return CSSTransformValue::create(realm, static_cast<Vector<GC::Ref<CSSTransformComponent>>>(move(transform_components)));
} }
GC::Ref<CSSStyleValue> StyleValueList::reify(JS::Realm& realm, String const& associated_property) const GC::Ref<CSSStyleValue> StyleValueList::reify(JS::Realm& realm, FlyString const& associated_property) const
{ {
// NB: <transform-list> is a StyleValueList that contains TransformStyleValues. If that's what we are, follow the // NB: <transform-list> is a StyleValueList that contains TransformStyleValues. If that's what we are, follow the
// steps for reifying that. // steps for reifying that.

View File

@ -35,7 +35,7 @@ public:
virtual String to_string(SerializationMode) const override; virtual String to_string(SerializationMode) const override;
virtual Vector<Parser::ComponentValue> tokenize() const override; virtual Vector<Parser::ComponentValue> tokenize() const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override; virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const override;

View File

@ -166,7 +166,7 @@ static GC::Ref<CSSUnparsedValue> reify_a_list_of_component_values(JS::Realm& rea
} }
// https://drafts.css-houdini.org/css-typed-om-1/#reify-a-list-of-component-values // https://drafts.css-houdini.org/css-typed-om-1/#reify-a-list-of-component-values
GC::Ref<CSSStyleValue> UnresolvedStyleValue::reify(JS::Realm& realm, String const&) const GC::Ref<CSSStyleValue> UnresolvedStyleValue::reify(JS::Realm& realm, FlyString const&) const
{ {
return reify_a_list_of_component_values(realm, m_values); return reify_a_list_of_component_values(realm, m_values);
} }

View File

@ -30,7 +30,7 @@ public:
virtual bool equals(StyleValue const& other) const override; virtual bool equals(StyleValue const& other) const override;
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, String const& associated_property) const override; virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
private: private:
UnresolvedStyleValue(Vector<Parser::ComponentValue>&& values, Parser::SubstitutionFunctionsPresence, Optional<String> original_source_text); UnresolvedStyleValue(Vector<Parser::ComponentValue>&& values, Parser::SubstitutionFunctionsPresence, Optional<String> original_source_text);