mirror of
https://github.com/lexmount/moli.git
synced 2026-11-21 08:02:59 +00:00
fix(cssom): serialize computed background layers
Serialize computed background from the shared retained style read, using the image list to coordinate layers, repeating or truncating other component lists, and emitting color only in the final layer. Include computed initial components instead of using specified-value shorthand elision. When Stylo cannot serialize a computed shorthand, reify the shared CSSOM result as one property-associated opaque CSSStyleValue. Preserve native realm allocation, snapshot immutability and longhand Typed OM types. Cover multiple layers, currentcolor, list coordination, private native writes and cross-realm reads.
This commit is contained in:
@@ -396,6 +396,12 @@ pub(crate) fn computed_typed_style_value_from_object<'s>(
|
||||
computed
|
||||
.computed_or_resolved_property_value(id.clone(), None, &mut css_text)
|
||||
.ok()?;
|
||||
if css_text.is_empty() && id.as_shorthand().is_ok() {
|
||||
// Stylo cannot serialize every computed shorthand. Use this read's
|
||||
// shared CSSOM serializer, retaining one property-associated opaque
|
||||
// value rather than splitting a shorthand into keywords or layers.
|
||||
css_text = read.property(property);
|
||||
}
|
||||
if css_text.is_empty() && !property.starts_with("--") {
|
||||
return None;
|
||||
}
|
||||
|
||||
+15
-3
@@ -16,18 +16,30 @@
|
||||
element.style.cssText = text;
|
||||
document.body.append(element);
|
||||
const style = getComputedStyle(element);
|
||||
const map = element.computedStyleMap();
|
||||
const value = map.get('background');
|
||||
check(style.background === expected, text + ': ' + style.background);
|
||||
check(String(value) === expected, text + ': Typed OM ' + value);
|
||||
check(Object.getPrototypeOf(value) === CSSStyleValue.prototype, 'opaque shorthand');
|
||||
const all = map.getAll('background');
|
||||
check(all.length === 1 && String(all[0]) === expected, 'whole shorthand is one value');
|
||||
element.remove();
|
||||
}
|
||||
const element = document.createElement('div');
|
||||
element.style.background = 'blue'; document.body.append(element);
|
||||
const computed = getComputedStyle(element);
|
||||
const previous = computed.background;
|
||||
const previousComputed = computed.background;
|
||||
const map = element.computedStyleMap();
|
||||
const previous = Object.freeze(map.get('background'));
|
||||
element.style.backgroundColor = 'red';
|
||||
check(String(previous).startsWith('rgb(0, 0, 255) '), 'retained value is immutable');
|
||||
check(String(previousComputed).startsWith('rgb(0, 0, 255) '), 'retained computed string is immutable');
|
||||
check(computed.background.startsWith('rgb(255, 0, 0) '), 'retained declaration observes mutations');
|
||||
check(String(previous).startsWith('rgb(0, 0, 255) '), 'retained typed value is immutable');
|
||||
check(String(map.get('background')).startsWith('rgb(255, 0, 0) '), 'retained map observes mutations');
|
||||
check(computed.backgroundImage === 'none', 'longhand value preserved');
|
||||
check(map.get('background-image') instanceof CSSKeywordValue, 'longhand type preserved');
|
||||
element.remove();
|
||||
check(computed.background === '', 'inactive owner is empty');
|
||||
check(computed.background === '', 'inactive declaration owner is empty');
|
||||
check(map.get('background') === undefined && map.getAll('background').length === 0, 'inactive map owner is empty');
|
||||
return true;
|
||||
})()
|
||||
|
||||
+12
@@ -8,3 +8,15 @@ fn css_computed_background_preserves_coordinated_layers() {
|
||||
"true"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn css_computed_shorthands_retain_property_identity_and_native_realms() {
|
||||
let mut vm = new_parsed_test_vm(
|
||||
"https://computed-shorthand-values.test/",
|
||||
"<!doctype html><body><iframe></iframe>",
|
||||
);
|
||||
assert_eq!(
|
||||
vm.eval(include_str!("css_computed_shorthands.js")).unwrap(),
|
||||
"true"
|
||||
);
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
(() => {
|
||||
const check = (ok, message) => {if (!ok) throw new Error(message);};
|
||||
const element = document.createElement('div');
|
||||
element.style.cssText = 'background:blue;mask:none;flex-flow:column wrap;transition:opacity 1s linear;';
|
||||
document.body.append(element);
|
||||
const map = element.computedStyleMap();
|
||||
for (const property of ['background', 'mask', 'flex-flow', 'transition']) {
|
||||
const value = map.get(property);
|
||||
check(Object.getPrototypeOf(value) === CSSStyleValue.prototype, property + ': opaque type');
|
||||
check(map.getAll(property).length === 1, property + ': one value');
|
||||
let rejected = false;
|
||||
try {element.attributeStyleMap.set('margin', value);} catch(e) {rejected = e instanceof TypeError;}
|
||||
check(rejected, property + ': property association');
|
||||
const expected = String(value);
|
||||
value.toString = () => {throw new Error('author stringifier');};
|
||||
element.attributeStyleMap.set(property, value);
|
||||
check(String(map.get(property)) === expected, property + ': native write');
|
||||
}
|
||||
const other = document.querySelector('iframe').contentWindow;
|
||||
const childElement = other.document.createElement('div');
|
||||
childElement.style.background = 'blue'; other.document.body.append(childElement);
|
||||
const childMap = childElement.computedStyleMap();
|
||||
const read = StylePropertyMapReadOnly.prototype.get;
|
||||
const value = read.call(childMap, 'background');
|
||||
check(value instanceof other.CSSStyleValue && !(value instanceof CSSStyleValue), 'map owner realm');
|
||||
const native = other.CSSStyleValue;
|
||||
other.CSSStyleValue = () => {throw new Error('author constructor');};
|
||||
check(read.call(childMap, 'background') instanceof native, 'intrinsic allocation');
|
||||
other.CSSStyleValue = native;
|
||||
childElement.remove(); element.remove();
|
||||
return true;
|
||||
})()
|
||||
Reference in New Issue
Block a user