Skip to content

Truly independent web browser

LibWeb+Meta: Implement CSSStyleProperties bindings in Rust

Andreas Klingc0967a4c8e44
diff --git a/Documentation/CSSGeneratedFiles.md b/Documentation/CSSGeneratedFiles.md
index 81a40e50de7..7ae93cd5bbf 100644
--- a/Documentation/CSSGeneratedFiles.md
+++ b/Documentation/CSSGeneratedFiles.md
@@ -11,7 +11,7 @@ They are run automatically as part of the build, and most of the time you can ig
## Properties.json
Each CSS property has an entry here, which describes what values it accepts, whether it's inherited, and similar data.
-This generates `PropertyID.h`, `PropertyID.cpp`, `GeneratedCSSStyleProperties.h`, `GeneratedCSSStyleProperties.cpp` and `GeneratedCSSStyleProperties.idl`.
+This generates `PropertyID.h`, `PropertyID.cpp`, `GeneratedCSSStyleProperties.cpp` and `GeneratedCSSStyleProperties.idl`.
Most of this data is found in the information box for that property in the relevant CSS spec.
The file is organized as a single JSON object, with keys being property names, and the values being the data for that property.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/mod.rs
index c870dbafa57..c06a903a22b 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/mod.rs
@@ -41,7 +41,35 @@ use core::ptr::NonNull;
use ak::Utf16String;
use libjs_rust::api::{ErrorKind, Gc, Object, Realm, Throw, ThrowCompletionOr, Value, Vm};
-use crate::bindings::services::web_bindings_create_dom_exception;
+use crate::bindings::services::{
+ web_bindings_create_dom_exception, web_bindings_pop_element_queue_and_invoke_reactions,
+ web_bindings_push_element_queue,
+};
+
+/// Runs the steps of a [CEReactions] construct, https://html.spec.whatwg.org/multipage/custom-elements.html#cereactions
+/// An exception of the steps is in the result, which the caller rethrows after the reactions ran.
+#[cfg_attr(
+ not(web_idl_bindings),
+ allow(dead_code, reason = "only the generated bindings use the function")
+)]
+pub(crate) fn with_custom_element_reactions<R>(original_steps: impl FnOnce() -> R) -> R {
+ // 1. Push a new element queue onto this object's relevant agent's custom element reactions stack.
+ // SAFETY: The bindings run on the main thread.
+ unsafe { web_bindings_push_element_queue() };
+
+ // 2. Run the originally-specified steps for this construct, catching any exceptions. If the steps return a value,
+ // let value be the returned value. If they throw an exception, let exception be the thrown exception.
+ let value_or_exception = original_steps();
+
+ // 3. Let queue be the result of popping from this object's relevant agent's custom element reactions stack.
+ // 4. Invoke custom element reactions in queue.
+ // SAFETY: The bindings run on the main thread, and the queue is the one this function pushed.
+ unsafe { web_bindings_pop_element_queue_and_invoke_reactions() };
+
+ // 5. If an exception exception was thrown by the original steps, rethrow exception.
+ // 6. If a value value was returned from the original steps, return value.
+ value_or_exception
+}
/// What the bindings pass the implementation of an interface: the VM, and the realm that the implementation creates
/// its results in. For an attribute or an operation, that is the realm of the object it runs on; for a constructor,
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs
index a6d83ed8a31..5b240158952 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs
@@ -32,6 +32,12 @@ unsafe extern "C" {
/// Makes `wrapper` the wrapper that the world of its realm, which is not a main world, holds for the cell.
pub(crate) fn web_bindings_set_rust_wrapper(realm: *mut c_void, cell: *mut c_void, wrapper: *mut c_void);
+ /// Pushes a new element queue onto the custom element reactions stack of the agent of the main thread.
+ pub(crate) fn web_bindings_push_element_queue();
+
+ /// Pops the element queue from that stack and invokes the custom element reactions in it.
+ pub(crate) fn web_bindings_pop_element_queue_and_invoke_reactions();
+
/// Whether the global object of the realm is a Window.
pub(crate) fn web_bindings_realm_is_window(realm: *mut c_void) -> bool;
pub(crate) fn web_bindings_realm_is_secure_context(realm: *mut c_void) -> bool;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_descriptors.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_descriptors.rs
index 519a7eae346..14ada8baf1c 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_descriptors.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_descriptors.rs
@@ -4,8 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! What the interfaces of the descriptors of an at-rule share. Each is a CSSStyleDeclaration, which LibWeb implements
-//! in C++, with an attribute for each descriptor.
+//! What the interfaces that inherit from CSSStyleDeclaration, which LibWeb implements in C++, share: each owns a
+//! C++ declaration block and has an attribute for each of its properties or descriptors.
use core::ffi::c_void;
use core::ptr::NonNull;
@@ -20,7 +20,13 @@ use crate::bindings::{Exception, WebIdlResult};
unsafe extern "C" {
fn web_css_descriptors_set_owner(descriptors: *mut c_void, interface_name: u16, owner: *mut c_void);
fn web_css_descriptors_get(descriptors: *mut c_void, name: *const u8, name_length: usize) -> usize;
- fn web_css_descriptors_set(descriptors: *mut c_void, name: *const u8, name_length: usize, value: usize) -> bool;
+ fn web_css_descriptors_set(
+ descriptors: *mut c_void,
+ name: *const u8,
+ name_length: usize,
+ value: usize,
+ error_message: *mut usize,
+ ) -> bool;
}
/// The Web::CSS::RustCSSDescriptors that an object of a descriptors interface owns.
@@ -48,14 +54,22 @@ impl CppDescriptors {
}
pub(crate) fn set(&self, name: &str, value: Utf16String) -> WebIdlResult<()> {
+ let mut error_message = 0;
// SAFETY: The cell is live, the name is lent for the call, and the value is handed over.
- if unsafe { web_css_descriptors_set(self.0.as_ptr(), name.as_ptr(), name.len(), value.into_raw()) } {
+ if unsafe {
+ web_css_descriptors_set(
+ self.0.as_ptr(),
+ name.as_ptr(),
+ name.len(),
+ value.into_raw(),
+ &raw mut error_message,
+ )
+ } {
return Ok(());
}
- Err(Exception::Dom(
- "NoModificationAllowedError",
- Utf16String::from_utf8("Cannot modify properties of readonly CSSStyleDeclaration"),
- ))
+ // SAFETY: LibWeb hands over the message of the exception.
+ let message = unsafe { Utf16String::from_raw_owned(error_message) };
+ Err(Exception::Dom("NoModificationAllowedError", message))
}
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_keyframe_rule.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_keyframe_rule.rs
index 9a668bcc632..246c07e24f7 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_keyframe_rule.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_keyframe_rule.rs
@@ -9,7 +9,7 @@
use super::css_rule::CSSRule;
use super::css_rule::RuleText;
use super::css_rule::impl_rule_wrappable;
-use crate::bindings::conversions::CppInterface;
+use super::css_style_properties::CSSStyleProperties;
use crate::bindings::interface::{Inherits, Ref, allocate};
use crate::bindings::{CallContext, WebIdlResult};
use ak::Utf16String;
@@ -67,8 +67,8 @@ impl CSSKeyframeRule {
}
// https://drafts.csswg.org/css-animations/#dom-csskeyframerule-style
- pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
- Ok(self.rule.style_attribute(cx))
+ pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSStyleProperties>> {
+ Ok(self.rule.declarations_object(cx))
}
pub(crate) fn serialized(&self, vm: &Vm) -> Utf16String {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_margin_rule.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_margin_rule.rs
index d50b6b944c0..4148a01d5af 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_margin_rule.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_margin_rule.rs
@@ -9,7 +9,7 @@
use super::css_rule::CSSRule;
use super::css_rule::RuleText;
use super::css_rule::impl_rule_wrappable;
-use crate::bindings::conversions::CppInterface;
+use super::css_style_properties::CSSStyleProperties;
use crate::bindings::interface::{Inherits, Ref, allocate};
use crate::bindings::{CallContext, WebIdlResult};
use ak::Utf16String;
@@ -48,8 +48,8 @@ impl CSSMarginRule {
}
// https://drafts.csswg.org/cssom/#dom-cssmarginrule-style
- pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
- Ok(self.rule.style_attribute(cx))
+ pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSStyleProperties>> {
+ Ok(self.rule.declarations_object(cx))
}
pub(crate) fn serialized(&self, vm: &Vm) -> Utf16String {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_nested_declarations.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_nested_declarations.rs
index 3c17529bd5f..300daab289e 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_nested_declarations.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_nested_declarations.rs
@@ -8,7 +8,7 @@
use super::css_rule::CSSRule;
use super::css_rule::impl_rule_wrappable;
-use crate::bindings::conversions::CppInterface;
+use super::css_style_properties::CSSStyleProperties;
use crate::bindings::interface::{Inherits, Ref, allocate};
use crate::bindings::{CallContext, WebIdlResult};
use ak::Utf16String;
@@ -42,8 +42,8 @@ impl CSSNestedDeclarations {
}
// https://drafts.csswg.org/css-nesting-1/#dom-cssnesteddeclarations-style
- pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
- Ok(self.rule.style_attribute(cx))
+ pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSStyleProperties>> {
+ Ok(self.rule.declarations_object(cx))
}
pub(crate) fn serialized(&self, vm: &Vm) -> Utf16String {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_position_try_descriptors.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_position_try_descriptors.rs
new file mode 100644
index 00000000000..c5e41846b1c
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_position_try_descriptors.rs
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! CSSPositionTryDescriptors, https://drafts.csswg.org/css-anchor-position-1/#om-position-try
+
+use super::css_descriptors::descriptors_interface;
+
+descriptors_interface!(
+ CSSPositionTryDescriptors,
+ web_css_position_try_descriptors_create,
+ (margin, set_margin, "margin"),
+ (margin_top, set_margin_top, "margin-top"),
+ (margin_right, set_margin_right, "margin-right"),
+ (margin_bottom, set_margin_bottom, "margin-bottom"),
+ (margin_left, set_margin_left, "margin-left"),
+ (margin_block, set_margin_block, "margin-block"),
+ (margin_block_start, set_margin_block_start, "margin-block-start"),
+ (margin_block_end, set_margin_block_end, "margin-block-end"),
+ (margin_inline, set_margin_inline, "margin-inline"),
+ (margin_inline_start, set_margin_inline_start, "margin-inline-start"),
+ (margin_inline_end, set_margin_inline_end, "margin-inline-end"),
+ (inset, set_inset, "inset"),
+ (inset_block, set_inset_block, "inset-block"),
+ (inset_block_start, set_inset_block_start, "inset-block-start"),
+ (inset_block_end, set_inset_block_end, "inset-block-end"),
+ (inset_inline, set_inset_inline, "inset-inline"),
+ (inset_inline_start, set_inset_inline_start, "inset-inline-start"),
+ (inset_inline_end, set_inset_inline_end, "inset-inline-end"),
+ (top, set_top, "top"),
+ (left, set_left, "left"),
+ (right, set_right, "right"),
+ (bottom, set_bottom, "bottom"),
+ (width, set_width, "width"),
+ (min_width, set_min_width, "min-width"),
+ (max_width, set_max_width, "max-width"),
+ (height, set_height, "height"),
+ (min_height, set_min_height, "min-height"),
+ (max_height, set_max_height, "max-height"),
+ (block_size, set_block_size, "block-size"),
+ (min_block_size, set_min_block_size, "min-block-size"),
+ (max_block_size, set_max_block_size, "max-block-size"),
+ (inline_size, set_inline_size, "inline-size"),
+ (min_inline_size, set_min_inline_size, "min-inline-size"),
+ (max_inline_size, set_max_inline_size, "max-inline-size"),
+ (place_self, set_place_self, "place-self"),
+ (align_self, set_align_self, "align-self"),
+ (justify_self, set_justify_self, "justify-self"),
+ (position_anchor, set_position_anchor, "position-anchor"),
+ (position_area, set_position_area, "position-area"),
+);
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_position_try_rule.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_position_try_rule.rs
index bdf5cd228f3..16ee690e730 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_position_try_rule.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_position_try_rule.rs
@@ -6,10 +6,10 @@
//! CSSPositionTryRule, https://drafts.csswg.org/css-anchor-position-1/#the-csspositiontryrule-interface
+use super::css_position_try_descriptors::CSSPositionTryDescriptors;
use super::css_rule::CSSRule;
use super::css_rule::RuleText;
use super::css_rule::impl_rule_wrappable;
-use crate::bindings::conversions::CppInterface;
use crate::bindings::interface::{Inherits, Ref, allocate};
use crate::bindings::{CallContext, WebIdlResult};
use ak::Utf16String;
@@ -55,7 +55,7 @@ impl CSSPositionTryRule {
}
// https://drafts.csswg.org/css-anchor-position-1/#dom-csspositiontryrule-style
- pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
+ pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSPositionTryDescriptors>> {
// On getting, it must return a CSSPositionTryDescriptors object for the @position-try at-rule, with the
// following properties:
// computed flag: Unset
@@ -63,7 +63,7 @@ impl CSSPositionTryRule {
// declarations: The declared descriptors in the rule, in specified order.
// parent CSS rule: The context object
// owner node: Null
- Ok(self.rule.style_attribute(cx))
+ Ok(self.rule.declarations_object(cx))
}
pub(crate) fn serialized(&self, vm: &Vm) -> Utf16String {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_rule.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_rule.rs
index e9e3669ab68..30a4ec8b378 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_rule.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_rule.rs
@@ -42,13 +42,14 @@ use super::css_style_sheet::CSSStyleSheet;
use super::css_supports_rule::CSSSupportsRule;
use crate::bindings::conversions::{CppInterface, ToJs};
use crate::bindings::cpp_cell::CppCell;
-use crate::bindings::interface::{Ref, Wrappable, cell_from_abi, cell_into_abi, wrap};
+use crate::bindings::interface::{Interface, Ref, Wrappable, cell_from_abi, cell_into_abi, wrap};
use crate::bindings::{CallContext, WebIdlResult};
unsafe extern "C" {
fn web_css_wrap_object(realm: *mut c_void, cell: *mut c_void) -> *mut c_void;
fn web_css_rule_create_declarations(rule: *mut c_void) -> *mut c_void;
fn web_css_declarations_serialized(declarations: *mut c_void) -> usize;
+ fn web_css_declaration_owner(declaration: *mut c_void) -> *mut c_void;
fn web_css_style_sheet_native_rules(sheet: *mut c_void) -> *const c_void;
fn web_css_selector_list_text(selectors: *const c_void, sheet: *mut c_void) -> usize;
}
@@ -174,6 +175,14 @@ impl CSSRule {
unsafe { Utf16String::from_raw_owned(text) }
}
+ /// The object of an interface implemented in Rust that owns the CSSStyleDeclaration of the rule, which the `style`
+ /// attribute of the rule returns.
+ pub(crate) fn declarations_object<T: Interface>(&self, cx: &CallContext) -> Ref<T> {
+ let declarations = self.declarations(cx.vm());
+ // SAFETY: The cell is that of a live CSSStyleDeclaration, whose owner is an object of the interface of the rule.
+ unsafe { cell_from_abi(web_css_declaration_owner(declarations.as_ptr())) }
+ }
+
/// The object that the `style` attribute of the rule returns.
pub(crate) fn style_attribute(&self, cx: &CallContext) -> CppInterface {
wrap_cpp_cell(cx, &self.declarations(cx.vm()))
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_style_properties.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_style_properties.rs
new file mode 100644
index 00000000000..16237330512
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_style_properties.rs
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! CSSStyleProperties, https://drafts.csswg.org/cssom/#cssstyleproperties
+
+use core::ffi::c_void;
+use core::ptr::NonNull;
+
+use ak::Utf16String;
+use libjs_rust::api::{
+ Attribute, Gc, NativeFunction, Object, PropertyAttributes, PropertyKey, Realm, ThrowCompletionOr, Trace, Value, Vm,
+};
+use libweb_rust::css_property_names;
+
+use super::css_descriptors::CppDescriptors;
+use crate::bindings::cpp_cell::CppCell;
+use crate::bindings::interface::{Wrappable, allocate};
+use crate::bindings::{CallContext, WebIdlResult};
+
+/// What an accessor of a CSS property captures. NB: The name is static, so the collector has nothing to see in it.
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct CSSPropertyAccessor {
+ #[gc(untraced)]
+ property_name: &'static str,
+}
+
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct CSSStyleProperties {
+ declaration: CppDescriptors,
+}
+
+impl Wrappable for CSSStyleProperties {
+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {
+ self.declaration.as_cpp_parent()
+ }
+}
+
+/// https://drafts.csswg.org/cssom/#css-property-to-idl-attribute
+fn css_property_to_idl_attribute(property: &str, lowercase_first: bool) -> String {
+ // 1. Let output be the empty string.
+ let mut output = String::new();
+
+ // 2. Let uppercase next be unset.
+ let mut uppercase_next = false;
+
+ // 3. If the lowercase first flag is set, remove the first character from property.
+ let property = if lowercase_first { &property[1..] } else { property };
+
+ // 4. For each character c in property:
+ for c in property.chars() {
+ // 1. If c is "-", set uppercase next.
+ if c == '-' {
+ uppercase_next = true;
+ }
+ // 2. Otherwise, if uppercase next is set, unset uppercase next and append c converted to ASCII uppercase to
+ // output.
+ else if uppercase_next {
+ uppercase_next = false;
+ output.push(c.to_ascii_uppercase());
+ }
+ // 3. Otherwise, append c to output.
+ else {
+ output.push(c);
+ }
+ }
+
+ // 5. Return output.
+ output
+}
+
+impl CSSStyleProperties {
+ // https://drafts.csswg.org/cssom/#dom-cssstyleproperties-cssfloat
+ pub(crate) fn css_float(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ // The cssFloat attribute, on getting, must return the result of invoking getPropertyValue() with float as
+ // argument.
+ Ok(self.declaration.get("float"))
+ }
+
+ pub(crate) fn set_css_float(&self, _: &mut CallContext, value: Utf16String) -> WebIdlResult<()> {
+ // On setting, the attribute must invoke setProperty() with float as first argument, as second argument the
+ // given value, and no third argument. Any exceptions thrown must be re-thrown.
+ self.declaration.set("float", value)
+ }
+
+ pub(crate) fn property_value(
+ &self,
+ _: &mut CallContext,
+ property: &CSSPropertyAccessor,
+ ) -> WebIdlResult<Utf16String> {
+ Ok(self.declaration.get(property.property_name))
+ }
+
+ pub(crate) fn set_property_value(
+ &self,
+ _: &mut CallContext,
+ property: &CSSPropertyAccessor,
+ value: Utf16String,
+ ) -> WebIdlResult<()> {
+ self.declaration.set(property.property_name, value)
+ }
+
+ /// Defines the accessors of the CSS properties on the interface prototype object. They are not enumerable, so that
+ /// enumerating the object only finds its indexed properties.
+ pub(crate) fn define_property_accessors<Getter, Setter>(
+ vm: &Vm,
+ realm: Gc<Realm>,
+ prototype: Gc<Object>,
+ getter: Getter,
+ setter: Setter,
+ ) where
+ Getter: Fn(&Vm, &CSSPropertyAccessor) -> ThrowCompletionOr<Value> + Copy + 'static,
+ Setter: Fn(&Vm, &CSSPropertyAccessor) -> ThrowCompletionOr<Value> + Copy + 'static,
+ {
+ let attributes = PropertyAttributes::new(Attribute::CONFIGURABLE | Attribute::WRITABLE);
+ let define = |attribute: &str, property_name: &'static str| {
+ let key = PropertyKey::from_utf8(attribute);
+ let capture = || CSSPropertyAccessor { property_name };
+ let get = NativeFunction::create(vm, capture(), getter, 0, &key, Some(realm), Some("get"), None);
+ let set = NativeFunction::create(vm, capture(), setter, 1, &key, Some(realm), Some("set"), None);
+ prototype.define_direct_accessor(vm, &key, Some(get.upcast()), Some(set.upcast()), attributes);
+ };
+ for property in css_property_names() {
+ // https://drafts.csswg.org/cssom/#dom-cssstyleproperties-camel_cased_attribute
+ define(&css_property_to_idl_attribute(property, false), property);
+ // https://drafts.csswg.org/cssom/#dom-cssstyleproperties-webkit_cased_attribute
+ if property.starts_with("-webkit-") {
+ define(&css_property_to_idl_attribute(property, true), property);
+ }
+ // https://drafts.csswg.org/cssom/#dom-cssstyleproperties-dashed_attribute
+ if property.contains('-') {
+ define(property, property);
+ }
+ }
+ }
+}
+
+/// A new object that owns the declaration block, which LibWeb created.
+///
+/// # Safety
+///
+/// `vm` must be the live VM, and `declaration` the live cell of a Web::CSS::CSSStyleProperties.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_css_style_properties_create(vm: *mut c_void, declaration: *mut c_void) {
+ assert!(!vm.is_null(), "C++ passes the VM");
+ // SAFETY: The caller passes the live VM and a live cell.
+ let (vm, declaration) = unsafe { (&*vm.cast::<Vm>(), CppCell::from_raw(declaration)) };
+ let object = allocate(vm, |_| CSSStyleProperties {
+ declaration: CppDescriptors::new(declaration),
+ });
+ object.declaration.set_owner(object);
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_style_rule.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_style_rule.rs
index daca1471fae..98e26641100 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_style_rule.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_style_rule.rs
@@ -9,8 +9,8 @@
use super::css_grouping_rule::CSSGroupingRule;
use super::css_rule::impl_rule_wrappable;
use super::css_rule::{CSSRule, RuleText, native_rules_of_sheet, selector_list_text};
+use super::css_style_properties::CSSStyleProperties;
use super::style_property_map::StylePropertyMap;
-use crate::bindings::conversions::CppInterface;
use crate::bindings::interface::{Inherits, Ref, allocate};
use crate::bindings::{CallContext, WebIdlResult};
use ak::Utf16String;
@@ -94,8 +94,8 @@ impl CSSStyleRule {
}
// https://drafts.csswg.org/cssom-1/#dom-cssstylerule-style
- pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<CppInterface> {
- Ok(self.rule().style_attribute(cx))
+ pub(crate) fn style(&self, cx: &mut CallContext) -> WebIdlResult<Ref<CSSStyleProperties>> {
+ Ok(self.rule().declarations_object(cx))
}
// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssstylerule-stylemap
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
index 5af4a78976f..91b2b3f9f32 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
@@ -44,6 +44,7 @@ pub(crate) mod css_numeric_value;
pub(crate) mod css_page_descriptors;
pub(crate) mod css_page_rule;
pub(crate) mod css_perspective;
+pub(crate) mod css_position_try_descriptors;
pub(crate) mod css_position_try_rule;
pub(crate) mod css_property_rule;
pub(crate) mod css_rotate;
@@ -54,6 +55,7 @@ pub(crate) mod css_scope_rule;
pub(crate) mod css_skew;
pub(crate) mod css_skew_x;
pub(crate) mod css_skew_y;
+pub(crate) mod css_style_properties;
pub(crate) mod css_style_rule;
pub(crate) mod css_style_sheet;
pub(crate) mod css_style_value;
diff --git a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp b/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
index 5b145a8b507..42fb78b83d3 100644
--- a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
+++ b/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
@@ -17,9 +17,11 @@
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Bindings/WrapperWorld.h>
#include <LibWeb/DOM/Document.h>
+#include <LibWeb/HTML/CustomElements/CustomElementReactions.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/Scripting/Agent.h>
#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/HTML/Window.h>
@@ -107,6 +109,8 @@ u64 web_bindings_currently_running_task(void* realm);
void* web_bindings_create_callback_function(JSObject* callable, bool returns_promise);
JSCompletion web_bindings_invoke_callback_function(void* callback, bool has_this_value, JSValue this_value, ReadonlySpan<JSValue> arguments);
void* web_bindings_invoke_promise_callback_function(void* callback, bool has_this_value, JSValue this_value, ReadonlySpan<JSValue> arguments);
+void web_bindings_push_element_queue();
+void web_bindings_pop_element_queue_and_invoke_reactions();
bool web_bindings_realm_is_window(void* realm);
bool web_bindings_realm_is_secure_context(void* realm);
HTML::Window* web_bindings_window_from_global_object(JSObject* global_object);
@@ -179,6 +183,17 @@ bool web_bindings_realm_is_secure_context(void* realm)
return HTML::is_secure_context(principal_host_defined_environment_settings_object(*static_cast<JS::Realm*>(realm)));
}
+void web_bindings_push_element_queue()
+{
+ main_thread_similar_origin_window_agent().custom_element_reactions_stack.element_queue_stack.append({});
+}
+
+void web_bindings_pop_element_queue_and_invoke_reactions()
+{
+ auto queue = main_thread_similar_origin_window_agent().custom_element_reactions_stack.element_queue_stack.take_last();
+ HTML::invoke_custom_element_reactions(queue);
+}
+
bool web_bindings_realm_is_window(void* realm)
{
return HTML::window_from_global_object(static_cast<JS::Realm*>(realm)->global_object());
diff --git a/Libraries/LibWeb/Bindings/RustCSSDescriptors.cpp b/Libraries/LibWeb/Bindings/RustCSSDescriptors.cpp
index 0a621020c32..832a11957a8 100644
--- a/Libraries/LibWeb/Bindings/RustCSSDescriptors.cpp
+++ b/Libraries/LibWeb/Bindings/RustCSSDescriptors.cpp
@@ -25,13 +25,6 @@ RustCSSDescriptors::RustCSSDescriptors(AtRuleID at_rule, RustDescriptorBlock des
{
}
-void RustCSSDescriptors::set_owner(Bindings::InterfaceName interface_name, Bindings::RustInterfaceCell& owner)
-{
- VERIFY(!m_owner);
- m_owner_interface_name = interface_name;
- m_owner = owner;
-}
-
WebIDL::ExceptionOr<void> RustCSSDescriptors::set_property(Utf16FlyString const& property, Utf16View value, Utf16View priority)
{
TRY(Base::set_property(property, value, priority));
@@ -44,52 +37,4 @@ WebIDL::ExceptionOr<void> RustCSSDescriptors::set_property(Utf16FlyString const&
return {};
}
-extern "C" JSObject* web_rust_bindings_wrap(JSVM*, void* realm, u16 interface_name, void* cell);
-
-GC::Ref<JS::HostObject> RustCSSDescriptors::create_wrapper(JS::Realm& realm)
-{
- VERIFY(m_owner);
- auto* wrapper = web_rust_bindings_wrap(JS::HostABI::vm_to_abi(realm.vm()), &realm, to_underlying(m_owner_interface_name), m_owner.ptr());
- return as<JS::HostObject>(*JS::HostABI::object_from_abi(wrapper));
-}
-
-void RustCSSDescriptors::visit_edges(GC::Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_owner);
-}
-
-// Declared on the Rust side in Libraries/LibWeb/Bindings/Rust/src/css/css_descriptors.rs.
-extern "C" {
-void web_css_descriptors_set_owner(void* descriptors, u16 interface_name, void* owner);
-FlatPtr web_css_descriptors_get(void* descriptors, u8 const* name, size_t name_length);
-bool web_css_descriptors_set(void* descriptors, u8 const* name, size_t name_length, FlatPtr value);
-}
-
-static RustCSSDescriptors& descriptors_from_cell(void* cell)
-{
- return *static_cast<RustCSSDescriptors*>(static_cast<GC::Cell*>(cell));
-}
-
-static Utf16FlyString descriptor_name(u8 const* name, size_t name_length)
-{
- return Utf16FlyString::from_utf8_without_validation(StringView { name, name_length });
-}
-
-void web_css_descriptors_set_owner(void* descriptors, u16 interface_name, void* owner)
-{
- descriptors_from_cell(descriptors).set_owner(static_cast<Bindings::InterfaceName>(interface_name), *static_cast<Bindings::RustInterfaceCell*>(owner));
-}
-
-FlatPtr web_css_descriptors_get(void* descriptors, u8 const* name, size_t name_length)
-{
- return descriptors_from_cell(descriptors).get_property_value(descriptor_name(name, name_length)).into_raw();
-}
-
-bool web_css_descriptors_set(void* descriptors, u8 const* name, size_t name_length, FlatPtr value)
-{
- auto text = Utf16String::from_raw(value);
- return !descriptors_from_cell(descriptors).set_property(descriptor_name(name, name_length), text.utf16_view(), u""sv).is_error();
-}
-
}
diff --git a/Libraries/LibWeb/Bindings/RustCSSDescriptors.h b/Libraries/LibWeb/Bindings/RustCSSDescriptors.h
index 8f84e876b55..28948965948 100644
--- a/Libraries/LibWeb/Bindings/RustCSSDescriptors.h
+++ b/Libraries/LibWeb/Bindings/RustCSSDescriptors.h
@@ -20,20 +20,12 @@ class RustCSSDescriptors final : public CSSDescriptors {
public:
[[nodiscard]] static GC::Ref<RustCSSDescriptors> create(AtRuleID, RustDescriptorBlock);
- void set_owner(Bindings::InterfaceName, Bindings::RustInterfaceCell&);
-
virtual WebIDL::ExceptionOr<void> set_property(Utf16FlyString const& property, Utf16View value, Utf16View priority) override;
private:
RustCSSDescriptors(AtRuleID, RustDescriptorBlock);
- virtual bool is_owned_by_rust_interface_object() const override { return true; }
- virtual GC::Ref<JS::HostObject> create_wrapper(JS::Realm&) override;
- virtual void visit_edges(GC::Cell::Visitor&) override;
-
AtRuleID m_at_rule;
- Bindings::InterfaceName m_owner_interface_name { Bindings::InterfaceName::Unknown };
- GC::Ptr<Bindings::RustInterfaceCell> m_owner;
};
}
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 22e896394e0..1df85797137 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -1075,8 +1075,6 @@ set(GENERATED_SOURCES
CSS/Enums.cpp
CSS/GeneratedCSSNumericFactoryMethods.cpp
CSS/GeneratedCSSNumericFactoryMethods.idl
- CSS/GeneratedCSSStyleProperties.cpp
- CSS/GeneratedCSSStyleProperties.idl
CSS/Keyword.cpp
CSS/MediaFeatureID.h
CSS/PropertyID.cpp
diff --git a/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.cpp b/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.cpp
index 06b5db751d8..36ce9fef3b7 100644
--- a/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.cpp
+++ b/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.cpp
@@ -5,6 +5,7 @@
*/
#include <LibGC/Heap.h>
+#include <LibJS/HostClassBuilder.h>
#include <LibWeb/CSS/CSSPositionTryDescriptors.h>
#include <LibWeb/CSS/PropertyNameAndID.h>
@@ -22,6 +23,13 @@ CSSPositionTryDescriptors::CSSPositionTryDescriptors(RustDeclarationBlock declar
{
}
+extern "C" void web_css_position_try_descriptors_create(void* vm, void* declaration);
+
+void CSSPositionTryDescriptors::create_owner()
+{
+ web_css_position_try_descriptors_create(JS::HostABI::vm_to_abi(JS::VM::the()), static_cast<GC::Cell*>(this));
+}
+
// https://drafts.csswg.org/css-anchor-position-1/#accepted-position-try-properties
static bool is_accepted_position_try_property(PropertyID property_id)
{
@@ -46,16 +54,4 @@ WebIDL::ExceptionOr<void> CSSPositionTryDescriptors::set_property(Utf16FlyString
return Base::set_property(property_name, css_text, priority);
}
-#define __ENUMERATE(name, property_name, property_id) \
- WebIDL::ExceptionOr<void> CSSPositionTryDescriptors::set_##name(Utf16View css_text) \
- { \
- return set_property(property_name##_utf16_fly_string, css_text, u""sv); \
- } \
- Utf16String CSSPositionTryDescriptors::name() const \
- { \
- return get_property_value(property_name##_utf16_fly_string); \
- }
-ENUMERATE_CSS_POSITION_TRY_DESCRIPTORS(__ENUMERATE)
-#undef __ENUMERATE
-
}
diff --git a/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.h b/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.h
index 8c5ef8e371f..ddf78d2e32d 100644
--- a/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.h
+++ b/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.h
@@ -52,7 +52,7 @@ namespace Web::CSS {
X(position_area, "position-area", PositionArea)
// https://drafts.csswg.org/css-anchor-position-1/#om-position-try
class CSSPositionTryDescriptors final : public CSSStyleProperties {
- WEB_WRAPPABLE(CSSPositionTryDescriptors, CSSStyleProperties);
+ WEB_NON_IDL_WRAPPABLE(CSSPositionTryDescriptors, CSSStyleProperties);
GC_DECLARE_ALLOCATOR(CSSPositionTryDescriptors);
public:
@@ -62,14 +62,10 @@ public:
virtual WebIDL::ExceptionOr<void> set_property(Utf16FlyString const& property_name, Utf16View css_text, Utf16View priority) override;
-#define __ENUMERATE(name, property_name, property_id) \
- WebIDL::ExceptionOr<void> set_##name(Utf16View css_text); \
- Utf16String name() const;
- ENUMERATE_CSS_POSITION_TRY_DESCRIPTORS(__ENUMERATE)
-#undef __ENUMERATE
-
private:
explicit CSSPositionTryDescriptors(RustDeclarationBlock);
+
+ virtual void create_owner() override;
};
}
diff --git a/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.idl b/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.idl
index 00b0b2ba0b7..0ceb2172ef0 100644
--- a/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.idl
+++ b/Libraries/LibWeb/CSS/CSSPositionTryDescriptors.idl
@@ -1,5 +1,5 @@
// https://drafts.csswg.org/css-anchor-position-1/#om-position-try
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface CSSPositionTryDescriptors : CSSStyleDeclaration {
attribute CSSOMString margin;
[AttributeCallbackName=margin_top_regular, ImplementedAs=margin_top] attribute CSSOMString marginTop;
diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp
index 137405ce7d5..758f59902a6 100644
--- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp
+++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibJS/HostClassBuilder.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleEngineInput.h>
@@ -14,7 +15,7 @@
namespace Web::CSS {
#if ARCH(X86_64) && !defined(AK_OS_WINDOWS)
-static_assert(sizeof(CSSStyleDeclaration) == 40);
+static_assert(sizeof(CSSStyleDeclaration) == 48);
#endif
GC_DEFINE_ALLOCATOR(CSSStyleDeclaration);
@@ -25,6 +26,29 @@ CSSStyleDeclaration::CSSStyleDeclaration(Computed computed, Readonly readonly)
{
}
+void CSSStyleDeclaration::set_owner(Bindings::InterfaceName interface_name, Bindings::RustInterfaceCell& owner)
+{
+ VERIFY(!m_rust_owner);
+ m_rust_owner_interface_name = interface_name;
+ m_rust_owner = owner;
+}
+
+Bindings::RustInterfaceCell& CSSStyleDeclaration::ensure_owner()
+{
+ if (!m_rust_owner)
+ create_owner();
+ return *m_rust_owner;
+}
+
+extern "C" JSObject* web_rust_bindings_wrap(JSVM*, void* realm, u16 interface_name, void* cell);
+
+GC::Ref<JS::HostObject> CSSStyleDeclaration::create_wrapper(JS::Realm& realm)
+{
+ auto& owner = ensure_owner();
+ auto* wrapper = web_rust_bindings_wrap(JS::HostABI::vm_to_abi(realm.vm()), &realm, to_underlying(m_rust_owner_interface_name), &owner);
+ return as<JS::HostObject>(*JS::HostABI::object_from_abi(wrapper));
+}
+
void CSSStyleDeclaration::prepare_to_update_style_attribute()
{
VERIFY(!is_computed());
@@ -86,6 +110,7 @@ void CSSStyleDeclaration::visit_edges(GC::Cell::Visitor& visitor)
Base::visit_edges(visitor);
visitor.visit(m_parent_rule);
visitor.visit(m_owner_element);
+ visitor.visit(m_rust_owner);
}
void CSSStyleDeclaration::set_owner_node(Optional<DOM::AbstractElement> owner_node)
@@ -99,4 +124,49 @@ void CSSStyleDeclaration::set_owner_node(Optional<DOM::AbstractElement> owner_no
m_owner_pseudo_element = owner_node->pseudo_element();
}
+// Declared on the Rust side in Libraries/LibWeb/Bindings/Rust/src/css/css_descriptors.rs.
+extern "C" {
+void web_css_descriptors_set_owner(void* declaration, u16 interface_name, void* owner);
+void* web_css_declaration_owner(void* declaration);
+FlatPtr web_css_descriptors_get(void* declaration, u8 const* name, size_t name_length);
+bool web_css_descriptors_set(void* declaration, u8 const* name, size_t name_length, FlatPtr value, FlatPtr* error_message);
+}
+
+static CSSStyleDeclaration& declaration_from_cell(void* cell)
+{
+ return *static_cast<CSSStyleDeclaration*>(static_cast<GC::Cell*>(cell));
+}
+
+static Utf16FlyString property_name(u8 const* name, size_t name_length)
+{
+ return Utf16FlyString::from_utf8_without_validation(StringView { name, name_length });
+}
+
+void web_css_descriptors_set_owner(void* declaration, u16 interface_name, void* owner)
+{
+ declaration_from_cell(declaration).set_owner(static_cast<Bindings::InterfaceName>(interface_name), *static_cast<Bindings::RustInterfaceCell*>(owner));
+}
+
+void* web_css_declaration_owner(void* declaration)
+{
+ return &declaration_from_cell(declaration).ensure_owner();
+}
+
+FlatPtr web_css_descriptors_get(void* declaration, u8 const* name, size_t name_length)
+{
+ return declaration_from_cell(declaration).get_property_value(property_name(name, name_length)).into_raw();
+}
+
+bool web_css_descriptors_set(void* declaration, u8 const* name, size_t name_length, FlatPtr value, FlatPtr* error_message)
+{
+ auto text = Utf16String::from_raw(value);
+ auto result = declaration_from_cell(declaration).set_property(property_name(name, name_length), text.utf16_view(), u""sv);
+ if (!result.is_error())
+ return true;
+ auto exception = result.release_error();
+ auto message = exception.get<GC::Ref<WebIDL::DOMException>>()->message();
+ *error_message = Utf16String(message).into_raw();
+ return false;
+}
+
}
diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Libraries/LibWeb/CSS/CSSStyleDeclaration.h
index 1b036ee2842..19bbc1da6d7 100644
--- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.h
+++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.h
@@ -11,6 +11,7 @@
#include <AK/Utf16String.h>
#include <AK/Utf16View.h>
#include <LibWeb/Bindings/PlatformObject.h>
+#include <LibWeb/Bindings/RustInterface.h>
#include <LibWeb/CSS/CSSRule.h>
#include <LibWeb/CSS/StyleProperty.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
@@ -69,6 +70,10 @@ public:
virtual RefPtr<StyleValue const> get_property_style_value(PropertyNameAndID const&) const { VERIFY_NOT_REACHED(); }
virtual WebIDL::ExceptionOr<void> set_property_style_value(PropertyNameAndID const&, NonnullRefPtr<StyleValue const>) { VERIFY_NOT_REACHED(); }
+ // The object of an interface implemented in Rust that owns this declaration block, whose wrappers are this block's.
+ void set_owner(Bindings::InterfaceName, Bindings::RustInterfaceCell&);
+ Bindings::RustInterfaceCell& ensure_owner();
+
protected:
enum class Computed : u8 {
No,
@@ -82,10 +87,16 @@ protected:
virtual void visit_edges(GC::Cell::Visitor&) override;
+ // Creates the object that owns this block, for a block whose owner is created on first use.
+ virtual void create_owner() { VERIFY_NOT_REACHED(); }
+
void prepare_to_update_style_attribute();
void update_style_attribute();
private:
+ virtual bool is_owned_by_rust_interface_object() const override { return true; }
+ virtual GC::Ref<JS::HostObject> create_wrapper(JS::Realm&) override;
+
// NB: The flags come first, so that they fill the padding at the end of the wrappable's fields.
// https://drafts.csswg.org/cssom/#cssstyledeclaration-computed-flag
@@ -105,6 +116,9 @@ private:
// element compressed.
GC::Member<DOM::Element> m_owner_element;
Optional<PseudoElement> m_owner_pseudo_element;
+
+ Bindings::InterfaceName m_rust_owner_interface_name { Bindings::InterfaceName::Unknown };
+ GC::Member<Bindings::RustInterfaceCell> m_rust_owner;
};
}
diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
index aba09f7dbcf..638c479ccd1 100644
--- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
+++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp
@@ -7,6 +7,7 @@
#include <AK/QuickSort.h>
#include <AK/Utf16StringBuilder.h>
+#include <LibJS/HostClassBuilder.h>
#include <LibJS/Runtime/ExternalMemory.h>
#include <LibWeb/CSS/CSSRule.h>
#include <LibWeb/CSS/CSSStyleProperties.h>
@@ -103,6 +104,13 @@ CSSStyleProperties::CSSStyleProperties(Computed computed, Readonly readonly, Rus
CSSStyleProperties::~CSSStyleProperties() = default;
+extern "C" void web_css_style_properties_create(void* vm, void* declaration);
+
+void CSSStyleProperties::create_owner()
+{
+ web_css_style_properties_create(JS::HostABI::vm_to_abi(JS::VM::the()), static_cast<GC::Cell*>(this));
+}
+
size_t CSSStyleProperties::external_memory_size() const
{
auto size = JS::saturating_add_external_memory_size(Base::external_memory_size(), m_declarations.external_memory_size());
@@ -1077,19 +1085,6 @@ WebIDL::ExceptionOr<Utf16String> CSSStyleProperties::remove_property(PropertyID
}
// https://drafts.csswg.org/cssom/#dom-cssstyleproperties-cssfloat
-Utf16String CSSStyleProperties::css_float() const
-{
- // The cssFloat attribute, on getting, must return the result of invoking getPropertyValue() with float as argument.
- return get_property_value("float"_utf16_fly_string);
-}
-
-WebIDL::ExceptionOr<void> CSSStyleProperties::set_css_float(Utf16View value)
-{
- // On setting, the attribute must invoke setProperty() with float as first argument, as second argument the given value,
- // and no third argument. Any exceptions thrown must be re-thrown.
- return set_property(PropertyID::Float, value, u""sv);
-}
-
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration-block
Utf16String CSSStyleProperties::serialized() const
{
diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.h b/Libraries/LibWeb/CSS/CSSStyleProperties.h
index 1e2e464fdfe..af846e7a082 100644
--- a/Libraries/LibWeb/CSS/CSSStyleProperties.h
+++ b/Libraries/LibWeb/CSS/CSSStyleProperties.h
@@ -12,7 +12,6 @@
#include <AK/Utf16View.h>
#include <LibGC/Weak.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
-#include <LibWeb/CSS/GeneratedCSSStyleProperties.h>
#include <LibWeb/CSS/RustDeclarationBlock.h>
#include <LibWeb/Export.h>
@@ -21,7 +20,7 @@ namespace Web::CSS {
// https://drafts.csswg.org/cssom/#cssstyleproperties
class WEB_API CSSStyleProperties
: public CSSStyleDeclaration {
- WEB_WRAPPABLE(CSSStyleProperties, CSSStyleDeclaration);
+ WEB_NON_IDL_WRAPPABLE(CSSStyleProperties, CSSStyleDeclaration);
GC_DECLARE_ALLOCATOR(CSSStyleProperties);
public:
@@ -64,9 +63,6 @@ public:
RefPtr<StyleValue const> get_property_style_value(PropertyID) const;
virtual WebIDL::ExceptionOr<void> set_property_style_value(PropertyNameAndID const&, NonnullRefPtr<StyleValue const>) override;
- Utf16String css_float() const;
- WebIDL::ExceptionOr<void> set_css_float(Utf16View);
-
virtual Utf16String serialized() const final override;
virtual WebIDL::ExceptionOr<void> set_css_text(Utf16View) override;
@@ -77,6 +73,8 @@ public:
protected:
CSSStyleProperties(Computed, Readonly, RustDeclarationBlock, Optional<DOM::AbstractElement>);
+ virtual void create_owner() override;
+
private:
virtual size_t external_memory_size() const override;
@@ -99,6 +97,4 @@ private:
mutable u64 m_cached_custom_property_registration_generation { 0 };
};
-#undef ENUMERATE_GENERATED_CSS_STYLE_PROPERTIES
-
}
diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.idl b/Libraries/LibWeb/CSS/CSSStyleProperties.idl
index de6bfe8a237..5018688d378 100644
--- a/Libraries/LibWeb/CSS/CSSStyleProperties.idl
+++ b/Libraries/LibWeb/CSS/CSSStyleProperties.idl
@@ -1,8 +1,6 @@
// https://drafts.csswg.org/cssom/#cssstyleproperties
-// Generated property accessors live on the shared prototype.
-[Exposed=Window]
+// The bindings define an accessor on the prototype for each CSS property.
+[Exposed=Window, ImplementedIn=Rust]
interface CSSStyleProperties : CSSStyleDeclaration {
[CEReactions, LegacyNullToEmptyString] attribute CSSOMString cssFloat;
};
-
-CSSStyleProperties includes GeneratedCSSStyleProperties;
diff --git a/Libraries/LibWeb/Rust/src/lib.rs b/Libraries/LibWeb/Rust/src/lib.rs
index 1ccf9368a41..14b03d8cc55 100644
--- a/Libraries/LibWeb/Rust/src/lib.rs
+++ b/Libraries/LibWeb/Rust/src/lib.rs
@@ -38,6 +38,13 @@ pub use css::media_list::{MediaList as NativeMediaList, MediaListDeleteResult};
pub use css::rule::cssom;
pub use css::rule::{NativeRule, NativeRuleList, NativeRuleType, RuleInsertionResult, RuleRemovalResult};
pub use css::style_sheet::NativeStyleSheetFlag;
+
+/// The names of the CSS properties and of their legacy aliases, which have an accessor on CSSStyleProperties.
+pub fn css_property_names() -> impl Iterator<Item = &'static str> {
+ css::property_metadata::PROPERTY_NAME_LOOKUP
+ .iter()
+ .map(|(name, _)| *name)
+}
pub use css::typed_om;
pub use svg::gfx_path_from_path_data;
diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake
index 28d13f27440..664aed601c8 100644
--- a/Libraries/LibWeb/idl_files.cmake
+++ b/Libraries/LibWeb/idl_files.cmake
@@ -94,7 +94,6 @@ libweb_js_bindings(CSS/FontFace)
libweb_js_bindings(CSS/FontFaceSet)
libweb_js_bindings(CSS/FontFaceSetLoadEvent)
libweb_js_bindings(CSS/GeneratedCSSNumericFactoryMethods)
-libweb_js_bindings(CSS/GeneratedCSSStyleProperties)
libweb_js_bindings(CSS/Highlight)
libweb_js_bindings(CSS/HighlightRegistry)
libweb_js_bindings(CSS/LinkStyle)
diff --git a/Meta/CMake/libweb_generators.cmake b/Meta/CMake/libweb_generators.cmake
index 60c50ccb4ba..6b76c2b023b 100644
--- a/Meta/CMake/libweb_generators.cmake
+++ b/Meta/CMake/libweb_generators.cmake
@@ -96,17 +96,6 @@ function (generate_css_implementation)
arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/Units.json"
)
- invoke_py_idl_generator(
- "GeneratedCSSStyleProperties.cpp"
- "GeneratedCSSStyleProperties.idl"
- "generate_libweb_css_style_properties.py"
- "${LIBWEB_INPUT_FOLDER}/CSS/Properties.json"
- "CSS/GeneratedCSSStyleProperties.h"
- "CSS/GeneratedCSSStyleProperties.cpp"
- "CSS/GeneratedCSSStyleProperties.idl"
- arguments -j "${LIBWEB_INPUT_FOLDER}/CSS/Properties.json"
- )
-
embed_as_string(
"DefaultStyleSheetSource.cpp"
"${LIBWEB_INPUT_FOLDER}/CSS/Default.css"
@@ -141,7 +130,6 @@ function (generate_css_implementation)
set(CSS_GENERATED_HEADERS
"CSS/Enums.h"
- "CSS/GeneratedCSSStyleProperties.h"
"CSS/GeneratedCSSNumericFactoryMethods.h"
"CSS/Keyword.h"
"CSS/MediaFeatureID.h"
@@ -158,7 +146,6 @@ function (generate_css_implementation)
set(LIBWEB_ALL_GENERATED_HEADERS ${LIBWEB_ALL_GENERATED_HEADERS} PARENT_SCOPE)
set(CSS_GENERATED_IDL
- "GeneratedCSSStyleProperties.idl"
"GeneratedCSSNumericFactoryMethods.idl"
)
list(APPEND LIBWEB_ALL_GENERATED_IDL ${CSS_GENERATED_IDL})
diff --git a/Meta/Generators/generate_libweb_css_style_properties.py b/Meta/Generators/generate_libweb_css_style_properties.py
deleted file mode 100644
index 7f248f00ef9..00000000000
--- a/Meta/Generators/generate_libweb_css_style_properties.py
+++ /dev/null
@@ -1,237 +0,0 @@
-# Copyright (c) 2024, Luke Wilde <[email protected]>
-# Copyright (c) 2026-present, the Ladybird developers.
-#
-# SPDX-License-Identifier: BSD-2-Clause
-
-import argparse
-import json
-import sys
-
-from pathlib import Path
-from typing import TextIO
-
-sys.path.append(str(Path(__file__).resolve().parent.parent))
-
-
-def css_property_to_idl_attribute(property_name: str, lowercase_first: bool = False) -> str:
- # https://drafts.csswg.org/cssom/#css-property-to-idl-attribute
- actual_property_name = property_name[1:] if lowercase_first else property_name
- output = []
- uppercase_next = False
- for c in actual_property_name:
- if c == "-":
- uppercase_next = True
- elif uppercase_next:
- uppercase_next = False
- output.append(c.upper())
- else:
- output.append(c)
- return "".join(output)
-
-
-def write_header_file(out: TextIO, properties: dict) -> None:
- out.write("""
-#pragma once
-
-#include <LibWeb/Forward.h>
-
-namespace Web::Bindings {
-
-class GeneratedCSSStyleProperties {
-public:
- static void initialize(JS::Realm&, JS::Object&);
-}; // class GeneratedCSSStyleProperties
-
-} // namespace Web::Bindings
-""")
-
-
-def write_implementation_file(out: TextIO, properties: dict) -> None:
- out.write("""
-#include <AK/Array.h>
-#include <LibJS/Runtime/NativeFunction.h>
-#include <LibJS/Runtime/Object.h>
-#include <LibJS/Runtime/PrimitiveString.h>
-#include <LibJS/Runtime/ValueInlines.h>
-#include <AK/Utf16String.h>
-#include <LibWeb/Bindings/Wrappable.h>
-#include <LibWeb/CSS/GeneratedCSSStyleProperties.h>
-#include <LibWeb/CSS/CSSStyleProperties.h>
-#include <LibWeb/HTML/CustomElements/CustomElementReactions.h>
-#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
-#include <LibWeb/WebIDL/AbstractOperations.h>
-#include <LibWeb/WebIDL/ExceptionOrUtils.h>
-
-namespace Web::Bindings {
-
-namespace {
-
-JS::ThrowCompletionOr<CSS::CSSStyleProperties*> impl_from(JS::VM& vm, JS::Value value)
-{
- if (auto object = value.as_if<JS::Object>()) {
- if (auto* wrappable = wrappable_impl_from(object.ptr())) {
- if (auto* impl = as_if<CSS::CSSStyleProperties>(wrappable))
- return impl;
- }
- }
- return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "CSSStyleProperties");
-}
-
-JS::ThrowCompletionOr<CSS::CSSStyleProperties*> impl_from(JS::VM& vm)
-{
- auto this_value = vm.this_value();
- if (this_value.is_nullish())
- this_value = &vm.current_realm()->global_object();
- return impl_from(vm, this_value);
-}
-
-struct Property {
- StringView attribute_name;
- StringView property_name;
-};
-
-static constexpr auto properties = Array {
-""")
-
- for name in properties:
- out.write(f' Property {{ "{css_property_to_idl_attribute(name)}"sv, "{name}"sv }},\n')
- if name.startswith("-webkit-"):
- out.write(
- f' Property {{ "{css_property_to_idl_attribute(name, lowercase_first=True)}"sv, "{name}"sv }},\n'
- )
- if "-" in name:
- out.write(f' Property {{ "{name}"sv, "{name}"sv }},\n')
-
- out.write("""};
-
-// NB: The accessors capture the index of their property, not its name. The garbage collector scans captures
-// conservatively, and a name's pointer can look like a pointer to any cell.
-Utf16FlyString const& property_name_at(size_t index)
-{
- static auto const& property_names = *[] {
- auto* property_names = new Vector<Utf16FlyString>;
- property_names->ensure_capacity(properties.size());
- for (auto const& property : properties)
- property_names->unchecked_append(Utf16FlyString::from_utf8(property.property_name));
- return property_names;
- }();
- return property_names[index];
-}
-
-GC::Ref<JS::NativeFunction> create_getter(JS::Realm& realm, Utf16FlyString const& attribute_name, size_t property_index)
-{
- auto getter = [property_index](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
- auto* idl_object = TRY(impl_from(vm));
- auto& realm = *vm.current_realm();
-
- auto result = TRY(WebIDL::throw_dom_exception_if_needed(vm, realm, [&] {
- return idl_object->get_property_value(property_name_at(property_index));
- }));
- return JS::PrimitiveString::create(vm, result);
- };
-
- return JS::NativeFunction::create(realm, move(getter), 0, JS::PropertyKey { attribute_name }, &realm, "get"sv);
-}
-
-GC::Ref<JS::NativeFunction> create_setter(JS::Realm& realm, Utf16FlyString const& attribute_name, size_t property_index)
-{
- auto setter = [property_index](JS::VM& vm) -> JS::ThrowCompletionOr<JS::Value> {
- auto* idl_object = TRY(impl_from(vm));
- auto& realm = *vm.current_realm();
-
- auto value = vm.argument(0);
- Utf16String idl_value;
- if (!value.is_null())
- idl_value = TRY(WebIDL::to_utf16_string(vm, value));
-
- auto original_steps = [&]() -> JS::ThrowCompletionOr<JS::Value> {
- TRY(WebIDL::throw_dom_exception_if_needed(vm, realm, [&] {
- return idl_object->set_property(property_name_at(property_index), idl_value, ""sv);
- }));
- return JS::js_undefined();
- };
-
- // For [CEReactions]: https://html.spec.whatwg.org/multipage/custom-elements.html#cereactions
-
- // 1. Push a new element queue onto this object's relevant agent's custom element reactions stack.
- auto& reactions_stack = Bindings::main_thread_similar_origin_window_agent().custom_element_reactions_stack;
- reactions_stack.element_queue_stack.append({});
-
- // 2. Run the originally-specified steps for this construct, catching any exceptions. If the steps return a value,
- // let value be the returned value. If they throw an exception, let exception be the thrown exception.
- auto value_or_exception = original_steps();
-
- // 3. Let queue be the result of popping from this object's relevant agent's custom element reactions stack.
- auto queue = reactions_stack.element_queue_stack.take_last();
-
- // 4. Invoke custom element reactions in queue.
- HTML::invoke_custom_element_reactions(queue);
-
- // 5. If an exception exception was thrown by the original steps, rethrow exception.
- if (value_or_exception.is_error())
- return value_or_exception.release_error();
-
- // 6. If a value value was returned from the original steps, return value.
- return value_or_exception.release_value();
- };
-
- return JS::NativeFunction::create(realm, move(setter), 1, JS::PropertyKey { attribute_name }, &realm, "set"sv);
-}
-
-}
-
-void GeneratedCSSStyleProperties::initialize(JS::Realm& realm, JS::Object& object)
-{
- // CSS property accessors are exposed on the prototype-like platform object but
- // are not enumerable own properties (Object.values() must expose only indexed
- // CSS declarations).
- [[maybe_unused]] u8 default_attributes = JS::Attribute::Configurable | JS::Attribute::Writable;
-
- for (size_t property_index = 0; property_index < properties.size(); ++property_index) {
- auto attribute_name = Utf16FlyString::from_utf8(properties[property_index].attribute_name);
- auto native_getter = create_getter(realm, attribute_name, property_index);
- auto native_setter = create_setter(realm, attribute_name, property_index);
- object.define_direct_accessor(attribute_name, native_getter, native_setter, default_attributes);
- }
-}
-
-} // namespace Web::Bindings
-""")
-
-
-def write_idl_file(out: TextIO, properties: dict) -> None:
- out.write("""
-interface mixin GeneratedCSSStyleProperties {
-""")
-
- out.write("""
-};
-""")
-
-
-def main():
- parser = argparse.ArgumentParser(description="Generate CSS StyleProperties", add_help=False)
- parser.add_argument("--help", action="help", help="Show this help message and exit")
- parser.add_argument("-h", "--header", required=True, help="Path to the CSSStyleProperties header file to generate")
- parser.add_argument(
- "-c", "--implementation", required=True, help="Path to the CSSStyleProperties implementation file to generate"
- )
- parser.add_argument("-i", "--idl", required=True, help="Path to the CSSStyleProperties IDL file to generate")
- parser.add_argument("-j", "--json", required=True, help="Path to the JSON file to read from")
- args = parser.parse_args()
-
- with open(args.json, "r", encoding="utf-8") as input_file:
- properties = json.load(input_file)
-
- with open(args.header, "w", encoding="utf-8") as output_file:
- write_header_file(output_file, properties)
-
- with open(args.implementation, "w", encoding="utf-8") as output_file:
- write_implementation_file(output_file, properties)
-
- with open(args.idl, "w", encoding="utf-8") as output_file:
- write_idl_file(output_file, properties)
-
-
-if __name__ == "__main__":
- main()
diff --git a/Meta/Generators/libweb_bindings/interfaces.py b/Meta/Generators/libweb_bindings/interfaces.py
index 3fb96dceb45..f7f0a890f88 100644
--- a/Meta/Generators/libweb_bindings/interfaces.py
+++ b/Meta/Generators/libweb_bindings/interfaces.py
@@ -215,8 +215,6 @@ def write_implementation(
includes.add("LibJS/Runtime/Realm.h")
includes.add("LibWeb/Bindings/Wrappable.h")
includes.add("LibWeb/Bindings/WrapperWorld.h")
- if interface.name == "CSSStyleProperties":
- includes.add("LibWeb/CSS/GeneratedCSSStyleProperties.h")
if interface.parent_name:
parent_interface = context.interface(IDLType(interface.parent_name))
includes.add_binding(parent_interface.implemented_name if parent_interface else interface.parent_name)
@@ -348,8 +346,6 @@ JS::ThrowCompletionOr<GC::Ref<JS::Object>> {interface.constructor_class}::constr
global_mixins.write_global_mixin_implementation(out, context, includes, interface)
return
attributes.define_the_regular_attributes(out, includes, interface)
- if interface.name == "CSSStyleProperties":
- out.write(" GeneratedCSSStyleProperties::initialize(realm, object);\n")
operations.define_the_regular_operations(out, includes, interface)
operations.define_the_stringifier(out, includes, interface)
named_and_indexed_properties.define_the_indexed_property_getter(out, includes, interface)
diff --git a/Meta/Generators/libweb_bindings/rust_bindings.py b/Meta/Generators/libweb_bindings/rust_bindings.py
index 867204d8701..af6fa3799d6 100644
--- a/Meta/Generators/libweb_bindings/rust_bindings.py
+++ b/Meta/Generators/libweb_bindings/rust_bindings.py
@@ -979,7 +979,7 @@ RUST_BINDINGS_IMPORTS = """ #![allow(unused_imports)]
use crate::bindings::event_target::{event_handler_attribute, set_event_handler_attribute};
use crate::bindings::promise::WebIdlPromise;
use crate::bindings::structured_data;
- use crate::bindings::{CallContext, WebIdlResult};
+ use crate::bindings::{CallContext, WebIdlResult, with_custom_element_reactions};
"""
@@ -1121,6 +1121,9 @@ def write_rust_interface(
elif attribute.put_forwards is not None:
write_rust_put_forwards_setter(out, attribute)
+ if interface.name == "CSSStyleProperties":
+ write_css_property_accessors(out)
+
for operation_set in members.operation_sets:
if len(operation_set.overloads) == 1 and operation_set.overloads[0].is_default_to_json:
write_default_to_json(out, context, interface, operation_set.function)
@@ -1189,6 +1192,10 @@ def write_rust_interface(
definition = f'define_attribute(vm, realm, prototype, "{name}", {getter}, {setter});'
out.write(secure_context_only_definition(definition, is_secure_context_only))
defined_property_names.append(name)
+ if interface.name == "CSSStyleProperties":
+ out.write(
+ " Implementation::define_property_accessors(vm, realm, prototype, property_getter, property_setter);\n"
+ )
for operation_set in members.operation_sets:
name = operation_set.name
function = operation_set.function
@@ -1905,6 +1912,39 @@ def inherited_attribute_getter_call(context: GenerationContext, interface: Inter
)
+def write_css_property_accessors(out: TextIO) -> None:
+ """The getter and the setter of the accessors of CSSStyleProperties, one for each CSS property, which behave as a
+ [CEReactions, LegacyNullToEmptyString] attribute of type CSSOMString does:
+ https://drafts.csswg.org/cssom/#dom-cssstyleproperties-camel_cased_attribute"""
+ out.write(
+ """
+ fn property_getter(vm: &Vm, property: &crate::css::css_style_properties::CSSPropertyAccessor) -> ThrowCompletionOr<Value> {
+ let (implementation, mut cx) = this_implementation(vm)?;
+ let result = Implementation::property_value(&implementation, &mut cx, property)
+ .map_err(|exception| exception.throw(&cx))?;
+ result.to_js(&cx)
+ }
+
+ fn property_setter(vm: &Vm, property: &crate::css::css_style_properties::CSSPropertyAccessor) -> ThrowCompletionOr<Value> {
+ let value = vm.argument(0);
+ let (implementation, mut cx) = this_implementation(vm)?;
+ let type_error_realm_scope = vm.type_error_realm_scope(cx.realm());
+ let idl_value = to_dom_string_treating_null_as_empty(vm, value)?;
+ drop(type_error_realm_scope);
+ with_custom_element_reactions(|| Implementation::set_property_value(&implementation, &mut cx, property, idl_value))
+ .map_err(|exception| exception.throw(&cx))?;
+ Ok(Value::UNDEFINED)
+ }
+"""
+ )
+
+
+def with_ce_reactions(call: str) -> str:
+ """The call of the steps of a [CEReactions] construct, whose exception the caller rethrows after the reactions ran:
+ https://html.spec.whatwg.org/multipage/custom-elements.html#cereactions"""
+ return f"with_custom_element_reactions(|| {call})"
+
+
def write_rust_attribute_setter(
out: TextIO, context: GenerationContext, interface: Interface, attribute: RustAttribute
) -> None:
@@ -1929,6 +1969,9 @@ def write_rust_attribute_setter(
if "NeedsCallerRealm" in attribute.attribute.extended_attributes:
receiver = "(implementation, _)"
caller_realm_context = CALLER_REALM_CONTEXT
+ call = f"Implementation::{attribute.setter_method}(&implementation, &mut cx, idl_value)"
+ if "CEReactions" in attribute.attribute.extended_attributes:
+ call = with_ce_reactions(call)
out.write(
f"""
fn {attribute.setter_function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
@@ -1937,7 +1980,7 @@ def write_rust_attribute_setter(
{caller_realm_context} let type_error_realm_scope = vm.type_error_realm_scope(cx.realm());
{conversion}
drop(type_error_realm_scope);
- Implementation::{attribute.setter_method}(&implementation, &mut cx, idl_value)
+ {call}
.map_err(|exception| exception.throw(&cx))?;
Ok(Value::UNDEFINED)
}}
@@ -1989,6 +2032,10 @@ def write_rust_operation(
arguments = "".join(f", {rust_local_name(parameter.name)}" for parameter in operation.parameters)
returns_promise = is_promise_type(operation.return_type) and not operation.return_type.nullable
call = f"Implementation::{overload.method}(&implementation, &mut cx{arguments})"
+ if "CEReactions" in operation.extended_attributes:
+ if returns_promise:
+ raise UnsupportedByRustBindings(f"{what} returns a promise and is [CEReactions]")
+ call = with_ce_reactions(call)
if operation.return_type.name == "undefined" and not operation.return_type.nullable:
# NB: An operation that returns nothing has no result to name, and the conversion of nothing is undefined.
steps.write(
diff --git a/Meta/Generators/libweb_bindings/rust_members.py b/Meta/Generators/libweb_bindings/rust_members.py
index 1aa722d4d43..4961bbc8318 100644
--- a/Meta/Generators/libweb_bindings/rust_members.py
+++ b/Meta/Generators/libweb_bindings/rust_members.py
@@ -37,6 +37,7 @@ RUST_METHOD_NAME = re.compile(r"[a-z][a-z0-9_]*")
SUPPORTED_ATTRIBUTE_EXTENDED_ATTRIBUTES = {
"AttributeCallbackName",
"CachedAccessor",
+ "CEReactions",
"FIXME",
"ImplementedAs",
"LegacyNullToEmptyString",
@@ -47,6 +48,7 @@ SUPPORTED_ATTRIBUTE_EXTENDED_ATTRIBUTES = {
"SecureContext",
}
SUPPORTED_OPERATION_EXTENDED_ATTRIBUTES = {
+ "CEReactions",
"Default",
"Exposed",
"FIXME",
diff --git a/Meta/Linters/check_libweb_realm_mentions.py b/Meta/Linters/check_libweb_realm_mentions.py
index cfe8232ccc2..c3a5eddcd1e 100755
--- a/Meta/Linters/check_libweb_realm_mentions.py
+++ b/Meta/Linters/check_libweb_realm_mentions.py
@@ -36,7 +36,11 @@ CHECKED_SUFFIXES = {
# the same change. If it goes up, justify the architecture change here.
ALLOWED_REALM_MENTIONS = {
"Animations": (5, 14, "animation callbacks/events and CSS value materialization still pass spec-selected realms"),
- "CSS": (6, 15, "CSS Typed OM, parser-facing reification, style-value JS materialization, and setlike/maplike glue"),
+ "CSS": (
+ 8,
+ 17,
+ "CSS Typed OM, parser-facing reification, style-value JS materialization, setlike/maplike glue, and wrappers of declaration blocks owned by Rust objects",
+ ),
"Clipboard": (4, 16, "clipboard item/data callbacks still materialize JS values in caller-selected realms"),
"ContentSecurityPolicy": (4, 10, "CSP violation/report objects and callbacks still materialize JS-facing values"),
"CookieStore": (2, 19, "cookie-store async callbacks and promise/value materialization still thread realms"),
diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-accessors.txt b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-accessors.txt
new file mode 100644
index 00000000000..8072a6c9c84
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-accessors.txt
@@ -0,0 +1,13 @@
+Reaction ran before the setter returned: true, color: red;
+cssFloat: left, color: red; float: left;
+dashed: blue, color: red; float: left; background-color: blue;
+webkit: green, green
+legacy alias: center, center
+null clears: "", float: left; background-color: blue; -webkit-text-fill-color: green; align-content: center;
+enumerable: false, configurable: true
+getter: get color, 0; setter: set color, 1
+own keys on the object: 0,1,2,3
+wrong this: TypeError
+NoModificationAllowedError: Cannot modify properties in result of getComputedStyle()
+same object: true
+expando survives: 1
diff --git a/Tests/LibWeb/Text/input/css/CSSStyleProperties-accessors.html b/Tests/LibWeb/Text/input/css/CSSStyleProperties-accessors.html
new file mode 100644
index 00000000000..f53e4228ff8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/CSSStyleProperties-accessors.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ const log = [];
+ class Observed extends HTMLElement {
+ static observedAttributes = ["style"];
+ attributeChangedCallback(name, oldValue, newValue) {
+ log.push(newValue);
+ }
+ }
+ customElements.define("x-observed", Observed);
+
+ const element = document.createElement("x-observed");
+ element.style.color = "red";
+ println(`Reaction ran before the setter returned: ${log.length === 1}, ${log[0]}`);
+ element.style.cssFloat = "left";
+ println(`cssFloat: ${element.style.cssFloat}, ${log.at(-1)}`);
+ element.style["background-color"] = "blue";
+ println(`dashed: ${element.style.backgroundColor}, ${log.at(-1)}`);
+ element.style.webkitTextFillColor = "green";
+ println(`webkit: ${element.style.WebkitTextFillColor}, ${element.style["-webkit-text-fill-color"]}`);
+ element.style.webkitAlignContent = "center";
+ println(`legacy alias: ${element.style.alignContent}, ${element.style["-webkit-align-content"]}`);
+ element.style.color = null;
+ println(`null clears: "${element.style.color}", ${log.at(-1)}`);
+
+ const descriptor = Object.getOwnPropertyDescriptor(CSSStyleProperties.prototype, "color");
+ println(`enumerable: ${descriptor.enumerable}, configurable: ${descriptor.configurable}`);
+ println(`getter: ${descriptor.get.name}, ${descriptor.get.length}; setter: ${descriptor.set.name}, ${descriptor.set.length}`);
+ println(`own keys on the object: ${Object.keys(element.style).join()}`);
+
+ try {
+ descriptor.get.call({});
+ } catch (error) {
+ println(`wrong this: ${error.name}`);
+ }
+
+ document.body.append(element);
+ try {
+ getComputedStyle(element).color = "red";
+ } catch (error) {
+ println(`${error.name}: ${error.message}`);
+ }
+ println(`same object: ${element.style === element.style}`);
+ element.style.expando = 1;
+ println(`expando survives: ${element.style.expando}`);
+ });
+</script>