Truly independent web browser
<!doctype html>
<style id="registrations">
@property --from-rule {
syntax: "<length>";
inherits: false;
initial-value: 2px;
}
@property --without-initial {
syntax: "*";
inherits: false;
}
</style>
<div id="target"></div>
<script src="../include.js"></script>
<script>
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()}`);
println(`rule value: ${map.get("--from-rule")}`);
println(`size matches iteration: ${map.size === Array.from(map).length}`);
document.getElementById("registrations").remove();
println(`removed rules: ${customNames()}`);
target.style.setProperty("--unicode-\uE000", "first");
target.style.setProperty("--unicode-\u{10000}", "second");
const unicodeOrder = Array.from(map.keys())
.filter(name => name.startsWith("--unicode-"))
.map(name => Array.from(name).at(-1).codePointAt(0).toString(16));
println(`unicode order: ${unicodeOrder.join(", ")}`);
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>