Files
ladybird/Tests/LibWeb/Text/input/css/custom-property-registration-document-adoption.html
Andreas Kling a94f9aa4c7 LibWeb: Filter non-inheriting registered custom properties on inherit
When inheriting custom-property data from a parent element, we were
copying the parent's full CustomPropertyData regardless of whether
each property was registered with `inherits: false`. That caused
non-inheriting registered properties to leak from the parent,
contrary to the @property spec.

Wrap the parent-side lookup so we strip any custom property whose
registration says it should not inherit, and only build a fresh
CustomPropertyData when at least one property was actually filtered.

Key the filtered view's cache on both the destination document's
identity and its custom-property registration generation. The
generation counter is local to each document, so a subtree adopted
into another document (or queried via getComputedStyle from another
window) could otherwise pick up a cached view computed under an
unrelated registration set and silently skip non-inheriting filtering
in the new document.
2026-04-22 20:59:00 +02:00

48 lines
1.6 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest(async done => {
const parent = document.createElement("div");
parent.style.setProperty("--foo", "rgb(255, 0, 0)");
const target = document.createElement("div");
target.textContent = "target";
target.style.color = "var(--foo)";
parent.appendChild(target);
document.body.appendChild(parent);
// Give the source document a different registration set but the same
// generation count as the destination document. That way the test
// catches caches that key only on generation and ignore the document.
CSS.registerProperty({
name: "--source-only",
syntax: "*",
inherits: true,
});
println(`before adopt color: ${getComputedStyle(target).color}`);
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
iframe.contentWindow.CSS.registerProperty({
name: "--foo",
syntax: "<color>",
inherits: false,
initialValue: "rgb(0, 128, 0)",
});
iframe.contentDocument.adoptNode(parent);
iframe.contentDocument.body.appendChild(parent);
println(`after adopt color: ${iframe.contentWindow.getComputedStyle(target).color}`);
iframe.contentWindow.CSS.registerProperty({
name: "--destination-only",
syntax: "*",
inherits: true,
});
println(`after destination generation change color: ${iframe.contentWindow.getComputedStyle(target).color}`);
done();
});
</script>