Bug 1464936: Avoid crashing with @import in Shadow DOM. r?smaug
Our behavior is correct, this uses the same setup that nsDocument and the
stylesets use, which I may look into fixing up / making more explicit in
bug 1465031.
MozReview-Commit-ID: 75AToXCw1pV
--- a/dom/base/ShadowRoot.cpp
+++ b/dom/base/ShadowRoot.cpp
@@ -389,20 +389,28 @@ ShadowRoot::InsertSheetIntoAuthorData(si
ApplicableRulesChanged();
}
// FIXME(emilio): This needs to notify document observers and such,
// presumably.
void
ShadowRoot::StyleSheetApplicableStateChanged(StyleSheet& aSheet, bool aApplicable)
{
- MOZ_ASSERT(mStyleSheets.Contains(&aSheet));
+ int32_t index = IndexOfSheet(aSheet);
+ if (index < 0) {
+ // NOTE(emilio): @import sheets are handled in the relevant RuleAdded
+ // notification, which only notifies after the sheet is loaded.
+ //
+ // This setup causes weirdness in other places, we may want to fix this in
+ // bug 1465031.
+ MOZ_DIAGNOSTIC_ASSERT(aSheet.GetParentSheet(),
+ "It'd better be an @import sheet");
+ return;
+ }
if (aApplicable) {
- int32_t index = IndexOfSheet(aSheet);
- MOZ_RELEASE_ASSERT(index >= 0);
InsertSheetIntoAuthorData(size_t(index), aSheet);
} else {
if (mStyleRuleMap) {
mStyleRuleMap->SheetRemoved(aSheet);
}
Servo_AuthorStyles_RemoveStyleSheet(mServoStyles.get(), &aSheet);
ApplicableRulesChanged();
}
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -128888,16 +128888,28 @@
[
"/css/css-scoping/reference/green-box.html",
"=="
]
],
{}
]
],
+ "css/css-scoping/shadow-at-import.html": [
+ [
+ "/css/css-scoping/shadow-at-import.html",
+ [
+ [
+ "/css/css-scoping/reference/green-box.html",
+ "=="
+ ]
+ ],
+ {}
+ ]
+ ],
"css/css-scoping/shadow-disabled-sheet-001.html": [
[
"/css/css-scoping/shadow-disabled-sheet-001.html",
[
[
"/css/css-scoping/reference/green-box.html",
"=="
]
@@ -256234,16 +256246,21 @@
{}
]
],
"css/css-scoping/reference/green-box.html": [
[
{}
]
],
+ "css/css-scoping/resources/host-green-box.css": [
+ [
+ {}
+ ]
+ ],
"css/css-scoping/slotted-with-pseudo-element-ref.html": [
[
{}
]
],
"css/css-scroll-anchoring/OWNERS": [
[
{}
@@ -519773,20 +519790,28 @@
"css/css-scoping/keyframes-002.html": [
"87f06cf1de80a4cf001fff6d150ce7013e78d604",
"testharness"
],
"css/css-scoping/reference/green-box.html": [
"a736f68dc602c0fccab56ec5cc6234cb3298c88d",
"support"
],
+ "css/css-scoping/resources/host-green-box.css": [
+ "2680b68f5c1720ce6d2b82d942ea21b0b1518587",
+ "support"
+ ],
"css/css-scoping/shadow-assign-dynamic-001.html": [
"c57e0fd5aa5be63e1cadf65a4e382798c5e05ec4",
"reftest"
],
+ "css/css-scoping/shadow-at-import.html": [
+ "40f2606177ad3143774d97060ac1bbfa9743801f",
+ "reftest"
+ ],
"css/css-scoping/shadow-cascade-order-001.html": [
"46913ea7e47811b11be898de5c3bd0a330ea6637",
"testharness"
],
"css/css-scoping/shadow-disabled-sheet-001.html": [
"3de2d23c1b3339b964ec2c009832a3207a3b9dc4",
"reftest"
],
@@ -546826,17 +546851,17 @@
"a8cfa83e572a766b61e4eae5946e7efb62e9eab7",
"testharness"
],
"css/geometry/DOMMatrix-002.html": [
"c38b9321ebb06ecae2a4217b36493f46b8649636",
"testharness"
],
"css/geometry/DOMMatrix-003.html": [
- "9e2d031f83fbcc4d32a3891fdf2c2d8bc2cc774c",
+ "ed9ca53d25463a9b38414ab9062cf3eb2f8991cb",
"testharness"
],
"css/geometry/DOMMatrix-a-f-alias.html": [
"6041bd4e7fd1535d9c8515f1b2f07981b2bdd366",
"testharness"
],
"css/geometry/DOMMatrix-attributes.html": [
"433984b90fc4579257db57b07a09ae36f7e5b4d3",
@@ -615666,17 +615691,17 @@
"e0918d83187c0fbdadaebb14be72c6f34f8dfc03",
"support"
],
"web-animations/resources/xhr-doc.py": [
"de68c45fc1d38a49946f9046f34031e9278a1531",
"support"
],
"web-animations/testcommon.js": [
- "039db95bc6b54f00d6e106241d001ae980566f92",
+ "57883097f4a440ae95b9e665bf8d9e36a187f7d8",
"support"
],
"web-animations/timing-model/animation-effects/active-time.html": [
"f05ff3594dde7248c84db42f8a80a6d0136b5f54",
"testharness"
],
"web-animations/timing-model/animation-effects/current-iteration.html": [
"617bfd8c533d159c4e56ea823917d580fe262bf6",
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-scoping/resources/host-green-box.css
@@ -0,0 +1,5 @@
+:host {
+ background: green;
+ width: 100px;
+ height: 100px;
+}
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/css/css-scoping/shadow-at-import.html
@@ -0,0 +1,13 @@
+<!doctype html>
+<title>CSS Test: @import in Shadow DOM</title>
+<link rel="help" href="https://drafts.csswg.org/css-cascade/#at-import">
+<link rel="match" href="reference/green-box.html"/>
+<p>Test passes if you see a single 100px by 100px green box below.</p>
+<div id="host">FAIL</div>
+<script>
+ host.attachShadow({ mode: "open" }).innerHTML = `
+ <style>
+ @import url("resources/host-green-box.css");
+ </style>
+ `;
+</script>