Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(cssom): append computed custom properties
ldm010a78042fe8b
diff --git a/moli-renderer-v8/src/native_bridge/element/styles/computed_names.rs b/moli-renderer-v8/src/native_bridge/element/styles/computed_names.rsindex 1d2566872..36f8c22b2 100644--- a/moli-renderer-v8/src/native_bridge/element/styles/computed_names.rs+++ b/moli-renderer-v8/src/native_bridge/element/styles/computed_names.rs@@ -1,9 +1,7 @@use crate::{document_runtime::DomHandle,native_bridge::JsContextHost,- style_engine::{- computed_longhand_count, computed_longhand_first_vendor_index, computed_longhand_name_at,- },+ style_engine::{computed_longhand_count, computed_longhand_name_at},};use super::declaration::{ComputedStyleRead, StyleComputationContext, computed_style_applies};@@ -33,22 +31,15 @@ pub(super) fn computed_property_name_at(return None;}- let first_vendor = computed_longhand_first_vendor_index();- if index < first_vendor {+ let longhand_count = computed_longhand_count();+ if index < longhand_count {return computed_longhand_name_at(index).map(str::to_owned);}- // Custom properties sort between ordinary and vendor-prefixed longhands.- // Standard indices therefore stay O(1); only this short tail needs the- // element's resolved custom-property set.let custom_names = sorted_custom_property_names(&ComputedStyleRead::new_with_context(runtime, handle, context,));- let custom_index = index - first_vendor;- if let Some(name) = custom_names.get(custom_index) {- return Some(name.clone());- }- computed_longhand_name_at(index - custom_names.len()).map(str::to_owned)+ custom_names.get(index - longhand_count).cloned()}pub(super) fn computed_property_names(@@ -64,19 +55,13 @@ pub(super) fn computed_property_names(}pub(super) fn computed_property_names_for_read(read: &ComputedStyleRead<'_>) -> Vec<String> {- let first_vendor = computed_longhand_first_vendor_index();let mut names = Vec::with_capacity(computed_longhand_count());names.extend(- (0..first_vendor)+ (0..computed_longhand_count()).filter_map(computed_longhand_name_at).map(str::to_owned),);names.extend(sorted_custom_property_names(read));- names.extend(- (first_vendor..computed_longhand_count())- .filter_map(computed_longhand_name_at)- .map(str::to_owned),- );names}diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rsindex 39e604da4..3294d20f3 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs@@ -7592,7 +7592,7 @@ fn computed_absolute_logical_inline_insets_resolve_physical_sides() {assert_eq!(result, "0px|140px|140px|0px");}#[test]-fn computed_style_property_names_are_sorted() {+fn computed_style_property_names_follow_cssom_order() {let mut vm = new_storage_test_vm("https://computed-style-order.test/");let result = vm@@ -7619,7 +7619,7 @@ fn computed_style_property_names_are_sorted() {const style = getComputedStyle(target);const properties = Array.from(style);const sorted = properties.slice().sort((left, right) => {- const segment = name => name.startsWith('--') ? 1 : name.startsWith('-') ? 2 : 0;+ const segment = name => name.startsWith('--') ? 2 : name.startsWith('-') ? 1 : 0;if (segment(left) !== segment(right)) {return segment(left) - segment(right);}@@ -8296,6 +8296,47 @@ fn computed_style_enumerates_registered_custom_properties() {r#"{"innerRegistered":true,"innerInherited":true,"innerOwn":true,"innerNoInitial":false,"siblingInherited":true,"siblingOwnNoInitial":true,"siblingInnerAbsent":false}"#);}++#[test]+fn computed_style_property_names_place_custom_properties_after_longhands() {+ let mut vm = new_storage_test_vm("https://computed-style-custom-property-order.test/");++ let result = vm+ .eval(+ r#"+(() => {+ const root = document.body || document.documentElement ||+ document.appendChild(document.createElement('html'));+ const target = document.createElement('div');+ const plain = document.createElement('div');+ target.style.cssText = '--z-token: z; --a-token: a;';+ root.append(target, plain);++ const computed = getComputedStyle(target);+ const names = Array.from(+ { length: computed.length },+ (_, index) => computed.item(index)+ );+ const customStart = names.indexOf('--a-token');+ const lastVendor = names.findLastIndex(+ name => name.startsWith('-') && !name.startsWith('--')+ );+ return [+ computed.getPropertyValue('--a-token'),+ computed.length - getComputedStyle(plain).length,+ names.slice(-2).join(','),+ computed.item(computed.length - 1),+ computed[computed.length - 1],+ customStart > lastVendor+ ].join('|');+})()+"#,+ )+ .expect("computed custom property order should evaluate");++ assert_eq!(result, "a|2|--a-token,--z-token|--z-token|--z-token|true");+}+#[test]fn css_register_property_validates_and_updates_computed_style() {let mut vm = new_storage_test_vm("https://css-register-property.test/");diff --git a/moli-renderer-v8/src/style_engine/mod.rs b/moli-renderer-v8/src/style_engine/mod.rsindex f4d0d1a97..53c580777 100644--- a/moli-renderer-v8/src/style_engine/mod.rs+++ b/moli-renderer-v8/src/style_engine/mod.rs@@ -111,8 +111,7 @@ pub(crate) use mutation_effect::{StyleAttributeImpact, StyleMutationEffect, normalized_style_attribute_name,};pub(crate) use property_metadata::{- computed_longhand_count, computed_longhand_first_vendor_index, computed_longhand_name_at,- computed_property_is_queryable,+ computed_longhand_count, computed_longhand_name_at, computed_property_is_queryable,};pub(crate) use registered_properties::{CssCustomPropertyRegistration, CssCustomPropertyRegistrationError,diff --git a/moli-renderer-v8/src/style_engine/property_metadata.rs b/moli-renderer-v8/src/style_engine/property_metadata.rsindex bd3e77bb0..99afad90f 100644--- a/moli-renderer-v8/src/style_engine/property_metadata.rs+++ b/moli-renderer-v8/src/style_engine/property_metadata.rs@@ -65,10 +65,6 @@ pub(crate) fn computed_longhand_count() -> usize {COMPUTED_LONGHAND_METADATA.longhands.len()}-pub(crate) fn computed_longhand_first_vendor_index() -> usize {- COMPUTED_LONGHAND_METADATA.first_vendor_index-}-pub(crate) fn computed_longhand_name_at(index: usize) -> Option<&'static str> {COMPUTED_LONGHAND_METADATA.longhands@@ -98,8 +94,7 @@ mod tests {use style::properties::PropertyId;use super::{- computed_longhand_count, computed_longhand_first_vendor_index, computed_longhand_name_at,- computed_property_is_queryable,+ computed_longhand_count, computed_longhand_name_at, computed_property_is_queryable,};#[test]@@ -144,7 +139,10 @@ mod tests {"every enumerated computed longhand must be queryable");- let first_vendor = computed_longhand_first_vendor_index();+ let first_vendor = names+ .iter()+ .position(|name| name.starts_with('-'))+ .unwrap_or(names.len());assert!(first_vendor > 250,"ordinary longhands must precede the vendor tail: {first_vendor}"