LibWeb: Take UTF-16 names in Typed OM property maps

Move StylePropertyMap, StylePropertyMapReadOnly, and the CSS.supports
property-name overload to Utf16FlyString. Request the UTF-16 binding
conversion path for their IDL property-name arguments.
This commit is contained in:
Andreas Kling 2026-06-08 20:35:13 +02:00 committed by Andreas Kling
parent d641bfd7e2
commit 96521f7df0
10 changed files with 26 additions and 25 deletions

View file

@ -29,7 +29,7 @@ WebIDL::ExceptionOr<String> escape(JS::VM&, StringView identifier)
}
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
bool supports(JS::VM&, FlyString const& property_name, StringView value)
bool supports(JS::VM&, Utf16FlyString const& property_name, StringView value)
{
// 1. If property is an ASCII case-insensitive match for any defined CSS property that the UA supports, or is a
// custom property name string, and value successfully parses according to that propertys grammar, return true.

View file

@ -9,6 +9,7 @@
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Utf16FlyString.h>
#include <LibJS/Forward.h>
#include <LibWeb/CSS/GeneratedCSSNumericFactoryMethods.h>
#include <LibWeb/Export.h>
@ -20,7 +21,7 @@ namespace Web::CSS {
WEB_API WebIDL::ExceptionOr<String> escape(JS::VM&, StringView identifier);
WEB_API bool supports(JS::VM&, FlyString const& property, StringView value);
WEB_API bool supports(JS::VM&, Utf16FlyString const& property, StringView value);
WEB_API WebIDL::ExceptionOr<bool> supports(JS::VM&, StringView condition_text);
WEB_API WebIDL::ExceptionOr<void> register_property(JS::VM&, Bindings::PropertyDefinition const&);

View file

@ -116,7 +116,7 @@ static WebIDL::ExceptionOr<NonnullRefPtr<StyleValue const>> normalize_overflow_c
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-set
WebIDL::ExceptionOr<void> StylePropertyMap::set(FlyString property_name, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values)
WebIDL::ExceptionOr<void> StylePropertyMap::set(Utf16FlyString property_name, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values)
{
// The set(property, ...values) method, when called on a StylePropertyMap this, must perform the following steps:
@ -221,7 +221,7 @@ WebIDL::ExceptionOr<void> StylePropertyMap::set(FlyString property_name, Readonl
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-append
WebIDL::ExceptionOr<void> StylePropertyMap::append(FlyString property_name, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values)
WebIDL::ExceptionOr<void> StylePropertyMap::append(Utf16FlyString property_name, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values)
{
// The append(property, ...values) method, when called on a StylePropertyMap this, must perform the following steps:
@ -289,7 +289,7 @@ WebIDL::ExceptionOr<void> StylePropertyMap::append(FlyString property_name, Read
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-delete
WebIDL::ExceptionOr<void> StylePropertyMap::delete_(FlyString property)
WebIDL::ExceptionOr<void> StylePropertyMap::delete_(Utf16FlyString property)
{
// The delete(property) method, when called on a StylePropertyMap this, must perform the following steps:
@ -302,7 +302,7 @@ WebIDL::ExceptionOr<void> StylePropertyMap::delete_(FlyString property)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("'{}' is not a valid CSS property", property)) };
// 3. If thiss [[declarations]] internal slot contains property, remove it.
TRY(declarations().remove_property(Utf16FlyString::from_utf8(property)));
TRY(declarations().remove_property(property));
return {};
}

View file

@ -20,9 +20,9 @@ public:
virtual ~StylePropertyMap() override;
WebIDL::ExceptionOr<void> set(FlyString property, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values);
WebIDL::ExceptionOr<void> append(FlyString property, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values);
WebIDL::ExceptionOr<void> delete_(FlyString property);
WebIDL::ExceptionOr<void> set(Utf16FlyString property, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values);
WebIDL::ExceptionOr<void> append(Utf16FlyString property, ReadonlySpan<Variant<GC::Ref<CSSStyleValue>, String>> values);
WebIDL::ExceptionOr<void> delete_(Utf16FlyString property);
WebIDL::ExceptionOr<void> clear();
private:

View file

@ -1,9 +1,9 @@
// https://drafts.css-houdini.org/css-typed-om-1/#stylepropertymap
[Exposed=Window]
interface StylePropertyMap : StylePropertyMapReadOnly {
undefined set(USVString property, (CSSStyleValue or USVString)... values);
undefined append(USVString property, (CSSStyleValue or USVString)... values);
undefined delete(USVString property);
undefined set(Utf16USVString property, (CSSStyleValue or USVString)... values);
undefined append(Utf16USVString property, (CSSStyleValue or USVString)... values);
undefined delete(Utf16USVString property);
undefined clear();
};

View file

@ -48,7 +48,7 @@ void StylePropertyMapReadOnly::visit_edges(Cell::Visitor& visitor)
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-get
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapReadOnly::get(String property_name)
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapReadOnly::get(Utf16FlyString property_name)
{
// The get(property) method, when called on a StylePropertyMapReadOnly this, must perform the following steps:
@ -72,7 +72,7 @@ WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapRead
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-getall
WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> StylePropertyMapReadOnly::get_all(String property_name)
WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> StylePropertyMapReadOnly::get_all(Utf16FlyString property_name)
{
// The getAll(property) method, when called on a StylePropertyMap this, must perform the following steps:
@ -100,7 +100,7 @@ WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> StylePropertyMapRead
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-has
WebIDL::ExceptionOr<bool> StylePropertyMapReadOnly::has(String property_name)
WebIDL::ExceptionOr<bool> StylePropertyMapReadOnly::has(Utf16FlyString property_name)
{
// The has(property) method, when called on a StylePropertyMapReadOnly this, must perform the following steps:

View file

@ -23,9 +23,9 @@ public:
virtual ~StylePropertyMapReadOnly() override;
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> get(String property);
WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> get_all(String property);
WebIDL::ExceptionOr<bool> has(String property);
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> get(Utf16FlyString property);
WebIDL::ExceptionOr<GC::RootVector<GC::Ref<CSSStyleValue>>> get_all(Utf16FlyString property);
WebIDL::ExceptionOr<bool> has(Utf16FlyString property);
WebIDL::UnsignedLong size() const;
protected:

View file

@ -2,9 +2,9 @@
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
interface StylePropertyMapReadOnly {
// FIXME: iterable<USVString, sequence<CSSStyleValue>>;
(undefined or CSSStyleValue) get(USVString property);
sequence<CSSStyleValue> getAll(USVString property);
boolean has(USVString property);
(undefined or CSSStyleValue) get(Utf16USVString property);
sequence<CSSStyleValue> getAll(Utf16USVString property);
boolean has(Utf16USVString property);
readonly attribute unsigned long size;
};

View file

@ -27,12 +27,12 @@ GC::Ref<CSSStyleValue> IntegerStyleValue::reify(JS::Realm& realm, Utf16FlyString
// 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
// slot set to 0, and its unit internal slot set to "px".
if (m_value == 0) {
if (m_value == 0 && associated_property.is_ascii()) {
// NB: Determine whether the associated property expects 0 to be a <length>.
// FIXME: Do this for registered custom properties.
auto associated_property_string = associated_property.to_utf16_string();
if (auto property_id = property_id_from_string(associated_property_string.ascii_view()); property_id.has_value()
&& property_id != PropertyID::Custom
&& *property_id != PropertyID::Custom
&& property_accepts_type(*property_id, ValueType::Length)) {
return CSSUnitValue::create(realm, 0, "px"_fly_string);
}

View file

@ -32,12 +32,12 @@ GC::Ref<CSSStyleValue> NumberStyleValue::reify(JS::Realm& realm, Utf16FlyString
// 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
// slot set to 0, and its unit internal slot set to "px".
if (m_value == 0) {
if (m_value == 0 && associated_property.is_ascii()) {
// NB: Determine whether the associated property expects 0 to be a <length>.
// FIXME: Do this for registered custom properties.
auto associated_property_string = associated_property.to_utf16_string();
if (auto property_id = property_id_from_string(associated_property_string.ascii_view()); property_id.has_value()
&& property_id != PropertyID::Custom
&& *property_id != PropertyID::Custom
&& property_accepts_type(*property_id, ValueType::Length)) {
return CSSUnitValue::create(realm, 0, "px"_fly_string);
}