Files
sousa-gecko/testing/web-platform/tests/css/cssom/CSSStyleSheet-constructable-replace-thenable.html
T
Emilio Cobos Álvarez 06979f0bbc Bug 2016237 - Take CSSStyleSheet's replace() promise before resolving. r=firefox-style-system-reviewers,dshin
If CSSStyleSheet becomes a thenable due to prototype mutations, then we
might null out the wrong promise.

Differential Revision: https://phabricator.services.mozilla.com/D284391
2026-02-23 19:24:10 +00:00

44 lines
1.3 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8">
<title>CSSStyleSheet.replace/replaceSync() when stylesheet is a thenable</title>
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<link rel="author" href="https://mozilla.org" title="Mozilla">
<link rel="help" href="https://drafts.csswg.org/cssom/#extensions-to-the-document-or-shadow-root-interface">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=2016237">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async function() {
const sheet = new CSSStyleSheet();
document.adoptedStyleSheets = [sheet];
let p2 = null;
let once = false;
Object.defineProperty(CSSStyleSheet.prototype, "then", {
configurable: true,
get() {
if (!once) {
once = true;
p2 = sheet.replace("b { color: blue; }");
}
return undefined;
},
});
await sheet.replace("a { color: red; }");
delete CSSStyleSheet.prototype.then;
assert_true(once, "Then getter was called");
await p2;
assert_true(true, "replace() from then() should settle");
// Check if sheet is still modifiable
sheet.replaceSync("c {}");
assert_equals(sheet.cssRules[0].selectorText, "c", "Sheet should still be modifiable");
});
</script>