Truly independent web browser
LibWeb: Implement StylePropertyMap iteration
Andreas Klingeffbd98b4a43
diff --git a/Libraries/LibWeb/Bindings/StylePropertyMapReadOnlyIterator.cpp b/Libraries/LibWeb/Bindings/StylePropertyMapReadOnlyIterator.cppnew file mode 100644index 00000000000..92ea034aad9--- /dev/null+++ b/Libraries/LibWeb/Bindings/StylePropertyMapReadOnlyIterator.cpp@@ -0,0 +1,79 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <LibGC/RootVector.h>+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/Array.h>+#include <LibJS/Runtime/Iterator.h>+#include <LibJS/Runtime/PrimitiveString.h>+#include <LibWeb/Bindings/CSSStyleValue.h>+#include <LibWeb/Bindings/Intrinsics.h>+#include <LibWeb/Bindings/StylePropertyMapReadOnly.h>+#include <LibWeb/Bindings/StylePropertyMapReadOnlyIterator.h>+#include <LibWeb/Bindings/WrapperWorld.h>+#include <LibWeb/CSS/CSSStyleValue.h>++namespace Web::CSS {++GC_DEFINE_ALLOCATOR(StylePropertyMapReadOnlyIterator);++static constexpr JSHostClass style_property_map_iterator_host_class = JS::make_host_class(JS_HOST_CLASS_OBJECT, "StylePropertyMapReadOnlyIterator"sv, nullptr, nullptr, nullptr, 0);++StylePropertyMapReadOnlyIterator::StylePropertyMapReadOnlyIterator(JS::Object::PropertyKind kind, Vector<StylePropertyMapReadOnly::IterationEntry> entries, ReadonlySpan<GC::Ref<CSSStyleValue>> values)+ : m_kind(kind)+ , m_entries(move(entries))+{+ m_values.ensure_capacity(values.size());+ for (auto value : values)+ m_values.unchecked_append(value);+}++GC::Ref<JS::HostObject> StylePropertyMapReadOnlyIterator::create(JS::Realm& realm, StylePropertyMapReadOnly& map, JS::Object::PropertyKind kind)+{+ // INTEROP: Snapshot the entry list when iteration starts, matching Chrome and Safari.+ Vector<StylePropertyMapReadOnly::IterationEntry> entries;+ GC::RootVector<GC::Ref<CSSStyleValue>> values;+ if (kind == JS::Object::PropertyKind::Key) {+ for (auto const& name : map.property_names())+ entries.append({ name, 0, 0 });+ } else {+ map.collect_iteration_entries(entries, values);+ }+ auto iterator = realm.create<StylePropertyMapReadOnlyIterator>(kind, move(entries), values.span());+ auto& prototype = Bindings::ensure_web_prototype<Bindings::StylePropertyMapReadOnlyIteratorPrototype>(realm, "StylePropertyMapReadOnlyIterator"_utf16_fly_string);+ return JS::HostObject::create(realm, style_property_map_iterator_host_class, prototype, {}, iterator);+}++void StylePropertyMapReadOnlyIterator::visit_edges(GC::Cell::Visitor& visitor)+{+ Base::visit_edges(visitor);+ for (auto value : m_values)+ visitor.visit(value);+}++// https://drafts.css-houdini.org/css-typed-om-1/#stylepropertymapreadonly+GC::Ref<JS::Object> StylePropertyMapReadOnlyIterator::next(JS::Realm& realm)+{+ if (m_index >= m_entries.size())+ return JS::create_iterator_result_object(realm, JS::js_undefined(), true);++ auto const& entry = m_entries[m_index++];+ auto name = JS::PrimitiveString::create(vm(), entry.name.to_utf16_string());+ if (m_kind == JS::Object::PropertyKind::Key)+ return JS::create_iterator_result_object(realm, name, false);++ GC::RootVector<JS::Value> wrapped_values;+ wrapped_values.ensure_capacity(entry.value_count);+ for (auto value : m_values.span().slice(entry.value_offset, entry.value_count))+ wrapped_values.unchecked_append(Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, value));+ auto array = JS::Array::create_from(realm, wrapped_values.span());+ if (m_kind == JS::Object::PropertyKind::Value)+ return JS::create_iterator_result_object(realm, array, false);++ return JS::create_iterator_result_object(realm, JS::Array::create_from(realm, { name, array }), false);+}++}diff --git a/Libraries/LibWeb/Bindings/StylePropertyMapReadOnlyIterator.h b/Libraries/LibWeb/Bindings/StylePropertyMapReadOnlyIterator.hnew file mode 100644index 00000000000..55b7f59c72e--- /dev/null+++ b/Libraries/LibWeb/Bindings/StylePropertyMapReadOnlyIterator.h@@ -0,0 +1,36 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <LibJS/Heap/Cell.h>+#include <LibJS/Runtime/HostObject.h>+#include <LibJS/Runtime/Object.h>+#include <LibWeb/CSS/StylePropertyMapReadOnly.h>++namespace Web::CSS {++class StylePropertyMapReadOnlyIterator final : public JS::Cell {+ GC_CELL(StylePropertyMapReadOnlyIterator, JS::Cell);+ GC_DECLARE_ALLOCATOR(StylePropertyMapReadOnlyIterator);++public:+ using JSValueConversionIsForbidden = void;++ static GC::Ref<JS::HostObject> create(JS::Realm&, StylePropertyMapReadOnly&, JS::Object::PropertyKind);+ GC::Ref<JS::Object> next(JS::Realm&);++private:+ StylePropertyMapReadOnlyIterator(JS::Object::PropertyKind, Vector<StylePropertyMapReadOnly::IterationEntry>, ReadonlySpan<GC::Ref<CSSStyleValue>>);+ virtual void visit_edges(GC::Cell::Visitor&) override;++ JS::Object::PropertyKind m_kind;+ Vector<StylePropertyMapReadOnly::IterationEntry> m_entries;+ Vector<GC::Ref<CSSStyleValue>> m_values;+ size_t m_index { 0 };+};++}diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex a564ee7a19d..19d18495a60 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -29,6 +29,7 @@ set(SOURCESBindings/OptionConstructor.cppBindings/PlatformObject.cppBindings/RustBindingsServices.cpp+ Bindings/StylePropertyMapReadOnlyIterator.cppBindings/PrincipalHostDefined.cppBindings/Wrappable.cppBindings/WrapperWorld.cppdiff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cppindex 15aa5b6ff13..4e13e2bf0b2 100644--- a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp+++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp@@ -5,8 +5,10 @@*/#include "StylePropertyMapReadOnly.h"+#include <AK/QuickSort.h>#include <LibGC/Heap.h>#include <LibWeb/CSS/CSSStyleDeclaration.h>+#include <LibWeb/CSS/CSSStyleProperties.h>#include <LibWeb/CSS/CSSStyleValue.h>#include <LibWeb/CSS/ComputedValues.h>#include <LibWeb/CSS/CustomPropertyData.h>@@ -37,6 +39,7 @@ StylePropertyMapReadOnly::~StylePropertyMapReadOnly() = default;void StylePropertyMapReadOnly::visit_edges(GC::Cell::Visitor& visitor){Base::visit_edges(visitor);+ visitor.visit(m_cached_document);m_declarations.visit([&visitor](DOM::AbstractElement& element) { element.visit(visitor); },@@ -149,31 +152,122 @@ WebIDL::UnsignedLong StylePropertyMapReadOnly::size() const// The size attribute, on getting from a StylePropertyMapReadOnly this, must perform the following steps:// 1. Return the size of the value of this’s [[declarations]] internal slot.- return m_declarations.visit(- [](DOM::AbstractElement const& element) {- if (!has_computed_style(element))- return size_t { 0 };- // From https://drafts.css-houdini.org/css-typed-om-1/#dom-element-computedstylemap we need to include:- // "the name and computed value of every longhand CSS property supported by the User Agent, every- // registered custom property, and every non-registered custom property which is not set to its initial- // value on this"- // Ensure style is computed on the element before we try to read it.+ return property_names().size();+}++// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-declarations-slot+ReadonlySpan<Utf16FlyString> StylePropertyMapReadOnly::property_names() const+{+ if (auto* element = m_declarations.get_pointer<DOM::AbstractElement>(); element && !has_computed_style(*element))+ return {};++ auto needs_update = m_declarations.visit(+ [&](DOM::AbstractElement const& element) {element.document().update_style_for_element(element);+ auto custom_property_data = element.custom_property_data();+ auto& document = element.document();+ if (m_cached_document.ptr() == &document+ && m_cached_custom_property_data == custom_property_data+ && m_cached_registration_generation == document.custom_property_registration_generation()) {+ return false;+ }++ m_cached_document = document;+ m_cached_custom_property_data = move(custom_property_data);+ m_cached_registration_generation = document.custom_property_registration_generation();+ m_cached_property_names.clear_with_capacity();+ for (auto id = to_underlying(first_longhand_property_id); id <= to_underlying(last_longhand_property_id); ++id)+ m_cached_property_names.append(string_from_property_id(static_cast<PropertyID>(id)));- // Some custom properties set on the element might also be in the registered custom properties set, so we- // want the size of the union of the two sets.HashTable<Utf16FlyString> custom_properties;- if (auto data = element.custom_property_data()) {- data->for_each_property([&](Utf16FlyString const& name, CSS::StyleProperty const&) {- custom_properties.set(name);+ if (m_cached_custom_property_data) {+ m_cached_custom_property_data->for_each_property([&](auto const& name, auto const& property) {+ if (!property.value->is_guaranteed_invalid())+ custom_properties.set(name);});}- for (auto const& [key, _] : element.document().registered_property_set())- custom_properties.set(key);-- return number_of_longhand_properties + custom_properties.size();+ document.for_each_registered_custom_property([&](CustomPropertyRegistration const& registration) {+ custom_properties.set(registration.property_name);+ });+ for (auto const& name : custom_properties)+ m_cached_property_names.append(name);+ return true;},- [](GC::Ref<CSSStyleDeclaration> const& declaration) { return declaration->length(); });+ [&](GC::Ref<CSSStyleDeclaration> const& declaration) {+ // NB: Inline and declared maps are both backed by CSSStyleProperties.+ auto const& properties = as<CSSStyleProperties>(*declaration);+ if (m_cached_declaration_revision == properties.revision())+ return false;+ m_cached_declaration_revision = properties.revision();+ m_cached_property_names.clear_with_capacity();+ for (size_t i = 0; i < declaration->length(); ++i)+ m_cached_property_names.append(Utf16FlyString { declaration->item(i) });+ return true;+ });++ // INTEROP: Inline and declared maps preserve declaration order.+ if (needs_update && m_declarations.has<DOM::AbstractElement>()) {+ // Unless otherwise stated, the initial ordering of the [[declarations]] internal slot is based on the key of each entry:+ // 1. Standardized properties (not custom properties or vendor-prefixed properties), ASCII lowercased+ // and then sorted in increasing code-point order.+ // 2. Vendor-prefixed/experimental properties (those whose name starts with a single dash), ASCII lowercased+ // and then sorted in increasing code-point order.+ // 3. Custom properties, sorted in increasing code-point order. (These are never lower-cased; they are+ // preserved exactly as written.)+ quick_sort(m_cached_property_names, [](auto const& left, auto const& right) {+ auto category = [](auto const& name) {+ if (name.starts_with("--"sv))+ return 2;+ return name.starts_with("-"sv) ? 1 : 0;+ };+ if (category(left) != category(right))+ return category(left) < category(right);+ auto left_view = left.view();+ auto right_view = right.view();+ auto left_iterator = left_view.begin();+ auto right_iterator = right_view.begin();+ for (; left_iterator != left_view.end() && right_iterator != right_view.end(); ++left_iterator, ++right_iterator) {+ if (*left_iterator != *right_iterator)+ return *left_iterator < *right_iterator;+ }+ return left_iterator == left_view.end() && right_iterator != right_view.end();+ });+ }+ return m_cached_property_names;+}++// https://drafts.css-houdini.org/css-typed-om-1/#stylepropertymapreadonly+void StylePropertyMapReadOnly::collect_iteration_entries(Vector<IterationEntry>& entries, GC::RootVector<GC::Ref<CSSStyleValue>>& values)+{+ // The value pairs to iterate over for a StylePropertyMapReadOnly object this are obtained as follows:+ // 1. Let declarations be this’s [[declarations]] slot.+ // 2. Let value pairs be an empty list.+ // 3. For each prop → value in declarations:+ // NB: Copy the names, since reifying values may refresh the cached names.+ Vector<Utf16FlyString> names { property_names() };+ for (auto const& name : names) {+ // 1. Let iterations be the result of dividing into iterations value.+ // 2. Reify each item of iterations, and let objects be the result.+ auto objects = MUST(get_all(name.to_utf16_string()));+ // 3. Append prop/objects to value pairs.+ entries.append({ name, values.size(), objects.size() });+ for (auto object : objects)+ values.append(object);+ }+ // 4. Return value pairs.+}++// https://webidl.spec.whatwg.org/#es-iterable+void StylePropertyMapReadOnly::for_each(ForEachCallback callback)+{+ // INTEROP: Snapshot style-map entries before invoking callbacks, matching Chrome and Safari.+ Vector<IterationEntry> entries;+ GC::RootVector<GC::Ref<CSSStyleValue>> values;+ collect_iteration_entries(entries, values);+ for (auto const& entry : entries) {+ if (callback(entry.name.to_utf16_string(), values.span().slice(entry.value_offset, entry.value_count)) == IterationDecision::Break)+ break;+ }}RefPtr<StyleValue const> StylePropertyMapReadOnly::get_style_value(Source& source, PropertyNameAndID const& property)diff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.h b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.hindex ad2c54d16a9..e7aff57b89d 100644--- a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.h+++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.h@@ -6,6 +6,8 @@#pragma once+#include <AK/Function.h>+#include <AK/IterationDecision.h>#include <LibWeb/Bindings/Wrappable.h>#include <LibWeb/CSS/StyleValues/StyleValue.h>#include <LibWeb/DOM/AbstractElement.h>@@ -28,6 +30,16 @@ public:WebIDL::ExceptionOr<bool> has(Utf16String property);WebIDL::UnsignedLong size() const;+ ReadonlySpan<Utf16FlyString> property_names() const;+ struct IterationEntry {+ Utf16FlyString name;+ size_t value_offset;+ size_t value_count;+ };+ void collect_iteration_entries(Vector<IterationEntry>&, GC::RootVector<GC::Ref<CSSStyleValue>>&);+ using ForEachCallback = Function<IterationDecision(Utf16String const&, ReadonlySpan<GC::Ref<CSSStyleValue>>)>;+ void for_each(ForEachCallback);+protected:using Source = Variant<DOM::AbstractElement, GC::Ref<CSSStyleDeclaration>>;explicit StylePropertyMapReadOnly(Source);@@ -41,6 +53,13 @@ protected:// declaration block’s declarations.// NB: We just directly refer to our source, at least for now.Source m_declarations;++private:+ mutable Vector<Utf16FlyString> m_cached_property_names;+ mutable Optional<u64> m_cached_declaration_revision;+ mutable GC::Ptr<DOM::Document> m_cached_document;+ mutable RefPtr<CustomPropertyData const> m_cached_custom_property_data;+ mutable size_t m_cached_registration_generation { 0 };};}diff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idlindex 158d5e5ec16..847b2daa73f 100644--- a/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl+++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl@@ -1,7 +1,7 @@// https://drafts.css-houdini.org/css-typed-om-1/#stylepropertymapreadonly[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]interface StylePropertyMapReadOnly {- // FIXME: iterable<USVString, sequence<CSSStyleValue>>;+ iterable<USVString, sequence<CSSStyleValue>>;(undefined or CSSStyleValue) get(USVString property);sequence<CSSStyleValue> getAll(USVString property);boolean has(USVString property);diff --git a/Libraries/LibWeb/CSS/StylePropertyMapReadOnlyIterator.h b/Libraries/LibWeb/CSS/StylePropertyMapReadOnlyIterator.hnew file mode 100644index 00000000000..39c34cf0594--- /dev/null+++ b/Libraries/LibWeb/CSS/StylePropertyMapReadOnlyIterator.h@@ -0,0 +1,10 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++// The iterable generator finds this header beside the interface. The JS iterator belongs to the bindings layer.+#include <LibWeb/Bindings/StylePropertyMapReadOnlyIterator.h>diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 87ebbda2b2d..801568c3c9e 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -11844,6 +11844,16 @@ Optional<CSS::CustomPropertyRegistration const&> Document::get_registered_customreturn {};}+void Document::for_each_registered_custom_property(Function<void(CSS::CustomPropertyRegistration const&)> const& callback) const+{+ for (auto const& [name, registration] : m_registered_property_set)+ callback(registration);+ for (auto const& [name, registration] : m_cached_registered_properties_from_css_property_rules) {+ if (!m_registered_property_set.contains(name))+ callback(registration);+ }+}+void Document::did_change_custom_property_registrations(Optional<Utf16FlyString> registered_property_set_change){++m_custom_property_registration_generation;diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.hindex 682edd07e18..ebe69bcf842 100644--- a/Libraries/LibWeb/DOM/Document.h+++ b/Libraries/LibWeb/DOM/Document.h@@ -1708,6 +1708,7 @@ public:// https://www.w3.org/TR/css-properties-values-api-1/#dom-window-registeredpropertyset-slotHashMap<Utf16FlyString, CSS::CustomPropertyRegistration>& registered_property_set();Optional<CSS::CustomPropertyRegistration const&> get_registered_custom_property(Utf16FlyString const& name) const;+ void for_each_registered_custom_property(Function<void(CSS::CustomPropertyRegistration const&)> const&) const;size_t custom_property_registration_generation() const { return m_custom_property_registration_generation; }void const* rust_custom_property_registry() const { return m_rust_custom_property_registry; }void did_change_custom_property_registrations(Optional<Utf16FlyString> registered_property_set_change = {});diff --git a/Tests/LibWeb/Text/expected/css/style-map-registration-iteration.txt b/Tests/LibWeb/Text/expected/css/style-map-registration-iteration.txtindex fd7eaa5fc96..200f5762950 100644--- a/Tests/LibWeb/Text/expected/css/style-map-registration-iteration.txt+++ b/Tests/LibWeb/Text/expected/css/style-map-registration-iteration.txt@@ -1 +1,10 @@-Uncaught Error In Test: TypeError: undefined is not a function (evaluated from 'map.keys')+initial: --from-api, --from-rule, --without-initial+rule value: 2px+size matches iteration: true+removed rules: --from-api+unicode order: e000, 10000+disconnected keys: 0+disconnected size: 0+snapshot keys: width, height+snapshot values: width: 1px; height: 2px+callback snapshot: width: 1px; height: 2pxdiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txtindex 84ea339d5b4..c1bb6a32925 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-properties-values-api/typedom.txt@@ -2,8 +2,8 @@ Harness status: OKFound 325 tests-244 Pass-81 Fail+292 Pass+33 FailPass Computed * is reified as CSSUnparsedValuePass Computed <angle> is reified as CSSUnitValuePass Computed <color> is reified as CSSStyleValue@@ -280,52 +280,52 @@ Pass CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length>+Pass CSSStyleValue.parse[All] returns CSSUnparsedValue for syntax <length>#Pass Direct CSSStyleValue may not be set [attributeStyleMap]Pass Direct CSSStyleValue may not be set [styleMap]-Fail Specified * is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified * is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified foo is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified foo is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <angle> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <angle> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <color> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <color> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <custom-ident> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <custom-ident> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <image> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <image> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <integer> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <integer> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <length-percentage> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <length-percentage> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <length> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <length> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <number> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <number> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <percentage> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <percentage> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <resolution> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <resolution> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <time> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <time> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <transform-function> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <transform-function> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <transform-list> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <transform-list> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <url> is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <url> is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <length>+ is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <length>+ is reified CSSUnparsedValue by iterator [styleMap]-Fail Specified <length># is reified CSSUnparsedValue by iterator [attributeStyleMap]-Fail Specified <length># is reified CSSUnparsedValue by iterator [styleMap]-Fail Registered property with initial value show up on iteration of computedStyleMap-Fail Computed * is reified as CSSUnparsedValue by iterator-Fail Computed <angle> is reified as CSSUnitValue by iterator-Fail Computed <custom-ident> is reified as CSSKeywordValue by iterator+Pass Specified * is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified * is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified foo is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified foo is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <angle> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <angle> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <color> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <color> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <custom-ident> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <custom-ident> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <image> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <image> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <integer> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <integer> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <length-percentage> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <length-percentage> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <length> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <length> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <number> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <number> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <percentage> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <percentage> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <resolution> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <resolution> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <time> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <time> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <transform-function> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <transform-function> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <transform-list> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <transform-list> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <url> is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <url> is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <length>+ is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <length>+ is reified CSSUnparsedValue by iterator [styleMap]+Pass Specified <length># is reified CSSUnparsedValue by iterator [attributeStyleMap]+Pass Specified <length># is reified CSSUnparsedValue by iterator [styleMap]+Pass Registered property with initial value show up on iteration of computedStyleMap+Pass Computed * is reified as CSSUnparsedValue by iterator+Pass Computed <angle> is reified as CSSUnitValue by iterator+Pass Computed <custom-ident> is reified as CSSKeywordValue by iteratorFail Computed <image> is reified as CSSImageValue by iterator-Fail Computed <integer> is reified as CSSUnitValue by iterator-Fail Computed <length> is reified as CSSUnitValue by iterator-Fail Computed <number> is reified as CSSUnitValue by iterator-Fail Computed <percentage> is reified as CSSUnitValue by iterator-Fail Computed <resolution> is reified as CSSUnitValue by iterator-Fail Computed <time> is reified as CSSUnitValue by iterator-Fail Computed none | thing | THING is reified as CSSKeywordValue by iterator-Fail Computed <angle> | <length> is reified as CSSUnitValue by iterator\ No newline at end of file+Pass Computed <integer> is reified as CSSUnitValue by iterator+Pass Computed <length> is reified as CSSUnitValue by iterator+Pass Computed <number> is reified as CSSUnitValue by iterator+Pass Computed <percentage> is reified as CSSUnitValue by iterator+Pass Computed <resolution> is reified as CSSUnitValue by iterator+Pass Computed <time> is reified as CSSUnitValue by iterator+Pass Computed none | thing | THING is reified as CSSKeywordValue by iterator+Pass Computed <angle> | <length> is reified as CSSUnitValue by iterator\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/idlharness.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/idlharness.txtindex 9b10f4a12ef..02c103a01ce 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/idlharness.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/idlharness.txt@@ -2,8 +2,8 @@ Harness status: OKFound 545 tests-445 Pass-100 Fail+446 Pass+99 FailPass idl_test setupPass idl_test validationPass Partial interface Element: original interface defined@@ -45,7 +45,7 @@ Pass StylePropertyMapReadOnly interface object namePass StylePropertyMapReadOnly interface: existence and properties of interface prototype objectPass StylePropertyMapReadOnly interface: existence and properties of interface prototype object's "constructor" propertyPass StylePropertyMapReadOnly interface: existence and properties of interface prototype object's @@unscopables property-Fail StylePropertyMapReadOnly interface: iterable<USVString, [object Object]>+Pass StylePropertyMapReadOnly interface: iterable<USVString, [object Object]>Pass StylePropertyMapReadOnly interface: operation get(USVString)Pass StylePropertyMapReadOnly interface: operation getAll(USVString)Pass StylePropertyMapReadOnly interface: operation has(USVString)diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/iterable.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/iterable.tentative.txtindex 349c1b99ee6..91c6811c9c5 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/iterable.tentative.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/computed/iterable.tentative.txt@@ -2,9 +2,10 @@ Harness status: OKFound 5 tests-5 Fail-Fail StylePropertyMap iterates properties in correct order-Fail StylePropertyMap iterator returns CSS properties with the correct CSSStyleValue-Fail StylePropertyMap iterator returns list-valued properties with the correct CSSStyleValue-Fail StylePropertyMap iterator returns custom properties with the correct CSSStyleValue+4 Pass+1 Fail+Pass StylePropertyMap iterates properties in correct order+Pass StylePropertyMap iterator returns CSS properties with the correct CSSStyleValue+Pass StylePropertyMap iterator returns list-valued properties with the correct CSSStyleValue+Pass StylePropertyMap iterator returns custom properties with the correct CSSStyleValueFail Computed StylePropertyMap sorts custom properties in increasing code-point order\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/clear.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/clear.txtindex da020a79b43..3465f182e72 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/clear.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/clear.txt@@ -2,8 +2,7 @@ Harness status: OKFound 3 tests-1 Pass-2 Fail-Fail Clearing an empty CSS rule is a no-op-Fail Can clear a CSS rule containing properties+3 Pass+Pass Clearing an empty CSS rule is a no-op+Pass Can clear a CSS rule containing propertiesPass Declared StylePropertyMap.clear updates the CSS rule\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/iterable.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/iterable.tentative.txtindex 66f34921509..bb75a066134 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/iterable.tentative.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/declared/iterable.tentative.txt@@ -2,9 +2,10 @@ Harness status: OKFound 5 tests-5 Fail-Fail Iterating over an empty StylePropertyMap gives a zero-length array+4 Pass+1 Fail+Pass Iterating over an empty StylePropertyMap gives a zero-length arrayFail StylePropertyMap iterates properties in correct order-Fail StylePropertyMap iterator returns CSS properties with the correct CSSStyleValue-Fail StylePropertyMap iterator returns list-valued properties with the correct CSSStyleValue-Fail StylePropertyMap iterator returns custom properties with the correct CSSStyleValue\ No newline at end of file+Pass StylePropertyMap iterator returns CSS properties with the correct CSSStyleValue+Pass StylePropertyMap iterator returns list-valued properties with the correct CSSStyleValue+Pass StylePropertyMap iterator returns custom properties with the correct CSSStyleValue\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/clear.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/clear.txtindex de7e06c0f71..8e62dfa4fd2 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/clear.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/clear.txt@@ -2,8 +2,7 @@ Harness status: OKFound 3 tests-1 Pass-2 Fail-Fail Clearing an empty inline style is a no-op-Fail Can clear an inline style containing properties+3 Pass+Pass Clearing an empty inline style is a no-op+Pass Can clear an inline style containing propertiesPass Inline StylePropertyMap.clear updates the element inline style\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/iterable.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/iterable.tentative.txtindex 44d51338bfe..f5d6b657d69 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/iterable.tentative.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-typed-om/the-stylepropertymap/inline/iterable.tentative.txt@@ -2,9 +2,10 @@ Harness status: OKFound 5 tests-5 Fail-Fail Iterating over an empty StylePropertyMap gives a zero-length array+4 Pass+1 Fail+Pass Iterating over an empty StylePropertyMap gives a zero-length arrayFail StylePropertyMap iterates properties in inline style order-Fail StylePropertyMap iterator returns CSS properties with the correct CSSStyleValue-Fail StylePropertyMap iterator returns list-valued properties with the correct CSSStyleValue-Fail StylePropertyMap iterator returns custom properties with the correct CSSStyleValue\ No newline at end of file+Pass StylePropertyMap iterator returns CSS properties with the correct CSSStyleValue+Pass StylePropertyMap iterator returns list-valued properties with the correct CSSStyleValue+Pass StylePropertyMap iterator returns custom properties with the correct CSSStyleValue\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/css/style-map-registration-iteration.html b/Tests/LibWeb/Text/input/css/style-map-registration-iteration.htmlindex 49327f3d965..2c7a99df27b 100644--- a/Tests/LibWeb/Text/input/css/style-map-registration-iteration.html+++ b/Tests/LibWeb/Text/input/css/style-map-registration-iteration.html@@ -16,6 +16,7 @@test(() => {CSS.registerProperty({ name: "--from-api", syntax: "<length>", inherits: false, initialValue: "3px" });const target = document.getElementById("target");+ target.style.setProperty("--invalid", "var(--missing)");const map = target.computedStyleMap();const customNames = () => Array.from(map.keys()).filter(name => name.startsWith("--")).sort().join(", ");println(`initial: ${customNames()}`);@@ -32,5 +33,24 @@target.remove();println(`disconnected keys: ${Array.from(map.keys()).length}`);println(`disconnected size: ${map.size}`);+ target.style.cssText = "width: 1px; height: 2px";+ const inlineMap = target.attributeStyleMap;+ const keys = inlineMap.keys();+ const entries = inlineMap.entries();+ inlineMap.set("height", CSS.px(4));+ inlineMap.set("left", CSS.px(3));+ internals.gc();+ println(`snapshot keys: ${Array.from(keys).join(", ")}`);+ println(`snapshot values: ${Array.from(entries, ([name, values]) => `${name}: ${values.join(", ")}`).join("; ")}`);+ target.style.cssText = "width: 1px; height: 2px";+ const visited = [];+ inlineMap.forEach((values, name) => {+ visited.push(`${name}: ${values.join(", ")}`);+ if (name === "width") {+ inlineMap.set("height", CSS.px(4));+ inlineMap.set("left", CSS.px(3));+ }+ });+ println(`callback snapshot: ${visited.join("; ")}`);});</script>