From c953103d2fb7ecf838e853387c4b466381037f72 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 1 Oct 2021 19:56:23 +0200 Subject: [PATCH] LibWeb: Make CSSStyleDeclaration support both dashed-name and camelCase Turns out we need to support *both* of these styles since there's content that uses one or both of these. --- .../CSSStyleDeclarationWrapperCustom.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp index 7c63c0dc23..ccdb1ab932 100644 --- a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp @@ -10,19 +10,29 @@ namespace Web::Bindings { +static CSS::PropertyID property_id_from_name(StringView name) +{ + if (auto property_id = CSS::property_id_from_camel_case_string(name); property_id != CSS::PropertyID::Invalid) + return property_id; + + if (auto property_id = CSS::property_id_from_string(name); property_id != CSS::PropertyID::Invalid) + return property_id; + + return CSS::PropertyID::Invalid; +} + JS::ThrowCompletionOr CSSStyleDeclarationWrapper::internal_has_property(JS::PropertyName const& name) const { if (!name.is_string()) return Base::internal_has_property(name); - auto property_id = CSS::property_id_from_camel_case_string(name.to_string()); - return property_id != CSS::PropertyID::Invalid; + return property_id_from_name(name.to_string()) != CSS::PropertyID::Invalid; } JS::ThrowCompletionOr CSSStyleDeclarationWrapper::internal_get(JS::PropertyName const& name, JS::Value receiver) const { if (!name.is_string()) return Base::internal_get(name, receiver); - auto property_id = CSS::property_id_from_camel_case_string(name.to_string()); + auto property_id = property_id_from_name(name.to_string()); if (property_id == CSS::PropertyID::Invalid) return Base::internal_get(name, receiver); if (auto maybe_property = impl().property(property_id); maybe_property.has_value()) @@ -34,7 +44,7 @@ JS::ThrowCompletionOr CSSStyleDeclarationWrapper::internal_set(JS::Propert { if (!name.is_string()) return Base::internal_set(name, value, receiver); - auto property_id = CSS::property_id_from_camel_case_string(name.to_string()); + auto property_id = property_id_from_name(name.to_string()); if (property_id == CSS::PropertyID::Invalid) return Base::internal_set(name, value, receiver);