LibWeb/CSS: Connect up StylePropertyMaps to their source

After looking into this more, the `[[declarations]]` slot does not seem
to need to be a literal map of property names and values. Instead, it
can just point at the source (an element or style declaration), and
then direct all read or write operations to that.

This means the `has()` and `delete()` methods actually work now.

A few remaining failures in these tests are because of:
- StylePropertyMap[ReadOnly]s not being iterable yet
- We're not populating an element's custom properties map, which get
  fixed whenever someone gets around to producing proper computed
  values of them.
This commit is contained in:
Sam Atkins 2025-08-13 13:52:59 +01:00
parent 37ea9a4ce3
commit b80930ae34
Notes: github-actions[bot] 2025-08-18 09:14:23 +00:00
13 changed files with 103 additions and 67 deletions

View file

@ -7,6 +7,7 @@
#include "StylePropertyMap.h"
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/StylePropertyMapPrototype.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/PropertyName.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -26,6 +27,12 @@ StylePropertyMap::StylePropertyMap(JS::Realm& realm, GC::Ref<CSSStyleDeclaration
StylePropertyMap::~StylePropertyMap() = default;
CSSStyleDeclaration& StylePropertyMap::declarations()
{
// Writable StylePropertyMaps must be backed by a CSSStyleDeclaration, not an AbstractElement.
return m_declarations.get<GC::Ref<CSSStyleDeclaration>>();
}
void StylePropertyMap::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(StylePropertyMap);
@ -56,10 +63,10 @@ WebIDL::ExceptionOr<void> StylePropertyMap::set(String property, Vector<Variant<
// are actually going to show up). This steps restriction preserves the same semantics in the Typed OM.
// 6. Let props be the value of thiss [[declarations]] internal slot.
auto& props = m_declarations;
auto& props = declarations();
// 7. If props[property] exists, remove it.
props.remove(property);
TRY(props.remove_property(property));
// FIXME: 8. Let values to set be an empty list.
@ -95,7 +102,7 @@ WebIDL::ExceptionOr<void> StylePropertyMap::append(String property, Vector<Varia
// NOTE: When a property is set via string-based APIs, the presence of var() in a property prevents the entire thing from being interpreted. In other words, everything besides the var() is a plain component value, not a meaningful type. This steps restriction preserves the same semantics in the Typed OM.
// 6. Let props be the value of thiss [[declarations]] internal slot.
auto& props = m_declarations;
auto& props = declarations();
// FIXME: 7. If props[property] does not exist, set props[property] to an empty list.
(void)props;
@ -126,17 +133,17 @@ WebIDL::ExceptionOr<void> StylePropertyMap::delete_(String 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.
m_declarations.remove(property);
TRY(declarations().remove_property(property));
return {};
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymap-clear
void StylePropertyMap::clear()
WebIDL::ExceptionOr<void> StylePropertyMap::clear()
{
// The clear() method, when called on a StylePropertyMap this, must perform the following steps:
// 1. Remove all of the declarations in thiss [[declarations]] internal slot.
m_declarations.clear();
return declarations().set_css_text(""sv);
}
}