LibWeb: Make CSSStyleDeclaration a legacy platform object with indices

CSSStyleDeclaration has an indexed property getter, which returns
properties associated with the object in the order they were specified
in.
This commit is contained in:
Luke Wilde 2024-11-14 17:05:56 +00:00 committed by Andreas Kling
commit a94282e0e8
Notes: github-actions[bot] 2024-11-14 18:51:15 +00:00
3 changed files with 247 additions and 0 deletions

View file

@ -24,6 +24,9 @@ JS_DEFINE_ALLOCATOR(ElementInlineCSSStyleDeclaration);
CSSStyleDeclaration::CSSStyleDeclaration(JS::Realm& realm)
: PlatformObject(realm)
{
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
.supports_indexed_properties = true,
};
}
void CSSStyleDeclaration::initialize(JS::Realm& realm)
@ -328,6 +331,15 @@ WebIDL::ExceptionOr<void> CSSStyleDeclaration::set_css_float(StringView value)
return set_property("float"sv, value, ""sv);
}
Optional<JS::Value> CSSStyleDeclaration::item_value(size_t index) const
{
auto value = item(index);
if (value.is_empty())
return {};
return JS::PrimitiveString::create(vm(), value);
}
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration
static String serialize_a_css_declaration(CSS::PropertyID property, StringView value, Important important)
{