mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-16 13:09:41 +00:00
LibWeb/CSS: Use PropertyNameAndID in CSSSV::parse_a_css_style_value()
This commit is contained in:
parent
2906176500
commit
d014c6818a
Notes:
github-actions[bot]
2025-10-02 12:47:31 +00:00
Author: https://github.com/AtkinsSJ
Commit: d014c6818a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6310
1 changed files with 8 additions and 11 deletions
|
@ -8,7 +8,7 @@
|
|||
#include <LibWeb/Bindings/CSSStyleValuePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/PropertyName.h>
|
||||
#include <LibWeb/CSS/PropertyNameAndID.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
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
|
||||
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.
|
||||
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.
|
||||
if (!is_a_valid_css_property(property))
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("'{}' is not a valid CSS property", property)) };
|
||||
auto property = PropertyNameAndID::from_name(property_name);
|
||||
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 property’s grammar.
|
||||
// If this fails, throw a TypeError.
|
||||
// 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)
|
||||
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.
|
||||
|
||||
// 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() };
|
||||
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.
|
||||
if (parse_multiple == ParseMultiple::No)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue