LibWeb/CSS: Use PropertyNameAndID in CSSSV::parse_a_css_style_value()

This commit is contained in:
Sam Atkins 2025-09-26 12:44:56 +01:00
parent 2906176500
commit d014c6818a

View File

@ -8,7 +8,7 @@
#include <LibWeb/Bindings/CSSStyleValuePrototype.h> #include <LibWeb/Bindings/CSSStyleValuePrototype.h>
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyName.h> #include <LibWeb/CSS/PropertyNameAndID.h>
#include <LibWeb/WebIDL/ExceptionOr.h> #include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::CSS { namespace Web::CSS {
@ -61,29 +61,26 @@ 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, FlyString 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_name, 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))
property = property.to_ascii_lowercase();
// 2. If property is not a valid CSS property, throw a TypeError. // 2. If property is not a valid CSS property, throw a TypeError.
if (!is_a_valid_css_property(property)) auto property = PropertyNameAndID::from_name(property_name);
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("'{}' is not a valid CSS property", property)) }; if (!property.has_value())
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("'{}' is not a valid CSS property", property_name)) };
// 3. Attempt to parse cssText according to propertys grammar. // 3. Attempt to parse cssText according to propertys grammar.
// If this fails, throw a TypeError. // If this fails, throw a TypeError.
// Otherwise, let whole value be the parsed result. // Otherwise, let whole value be the parsed result.
auto property_id = property_id_from_string(property).release_value(); auto whole_value = parse_css_value(Parser::ParsingParams {}, css_text, property->id());
auto whole_value = parse_css_value(Parser::ParsingParams {}, css_text, property_id);
if (!whole_value) if (!whole_value)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Failed to parse '{}' as a value for '{}' property", css_text, property)) }; return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Failed to parse '{}' as a value for '{}' property", css_text, property->name())) };
// FIXME: 4. Subdivide into iterations whole value, according to property, and let values be the result. // FIXME: 4. Subdivide into iterations whole value, according to property, and let values be the result.
// 5. For each value in values, replace it with the result of reifying value for property. // 5. For each value in values, replace it with the result of reifying value for property.
GC::RootVector<GC::Ref<CSSStyleValue>> reified_values { vm.heap() }; GC::RootVector<GC::Ref<CSSStyleValue>> reified_values { vm.heap() };
reified_values.append(whole_value->reify(*vm.current_realm(), property)); reified_values.append(whole_value->reify(*vm.current_realm(), property->name()));
// 6. If parseMultiple is false, return values[0]. Otherwise, return values. // 6. If parseMultiple is false, return values[0]. Otherwise, return values.
if (parse_multiple == ParseMultiple::No) if (parse_multiple == ParseMultiple::No)