Bug 1374181 Part 1: Don't attempt EnsureUniqueInner on incomplete sheets in a StyleSet. draft
authorBrad Werth <bwerth@mozilla.com>
Tue, 03 Oct 2017 11:15:26 -0700
changeset 675113 ec5ea291b9e563af847a39b8dfa12dd4e369c673
parent 674765 294f332a35538940469b1a2576615ff5ffe1e016
child 734514 b1d25f717e69976e9f1a7ee10c113ae558fece7d
push id83037
push userbwerth@mozilla.com
push dateWed, 04 Oct 2017 20:45:36 +0000
bugs1374181, 1404538
milestone58.0a1
Bug 1374181 Part 1: Don't attempt EnsureUniqueInner on incomplete sheets in a StyleSet. One remaining issue is that requesters of CSSRules might also want to know if those rules are complete, and to listen for completion if the rules are incomplete. Bug 1404538 will fix this up at least for devtools. MozReview-Commit-ID: COnkS40Ooe2
layout/style/ServoStyleSet.cpp
layout/style/nsStyleSet.cpp
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1274,17 +1274,25 @@ ServoStyleSet::EnsureUniqueInnerOnCSSShe
   // Bug 1290276 will replicate the nsStyleSet work of checking
   // a nsBindingManager
 
   while (!queue.IsEmpty()) {
     uint32_t idx = queue.Length() - 1;
     StyleSheet* sheet = queue[idx];
     queue.RemoveElementAt(idx);
 
-    sheet->EnsureUniqueInner();
+    // Only call EnsureUniqueInner for complete sheets. If we do call it on
+    // incomplete sheets, we'll cause problems when the sheet is actually
+    // loaded. We don't care about incomplete sheets here anyway, because this
+    // method is only invoked by nsPresContext::EnsureSafeToHandOutCSSRules.
+    // The CSSRule objects we are handing out won't contain any rules derived
+    // from incomplete sheets (because they aren't yet applied in styling).
+    if (sheet->IsComplete()) {
+      sheet->EnsureUniqueInner();
+    }
 
     // Enqueue all the sheet's children.
     sheet->AppendAllChildSheets(queue);
   }
 
   if (mNeedsRestyleAfterEnsureUniqueInner) {
     // TODO(emilio): We could make this faster if needed tracking the specific
     // origins and all that, but the only caller of this doesn't seem to really
--- a/layout/style/nsStyleSet.cpp
+++ b/layout/style/nsStyleSet.cpp
@@ -2724,17 +2724,25 @@ nsStyleSet::EnsureUniqueInnerOnCSSSheets
     }
   }
 
   while (!queue.IsEmpty()) {
     uint32_t idx = queue.Length() - 1;
     StyleSheet* sheet = queue[idx];
     queue.RemoveElementAt(idx);
 
-    sheet->EnsureUniqueInner();
+    // Only call EnsureUniqueInner for complete sheets. If we do call it on
+    // incomplete sheets, we'll cause problems when the sheet is actually
+    // loaded. We don't care about incomplete sheets here anyway, because this
+    // method is only invoked by nsPresContext::EnsureSafeToHandOutCSSRules.
+    // The CSSRule objects we are handing out won't contain any rules derived
+    // from incomplete sheets (because they aren't yet applied in styling).
+    if (sheet->IsComplete()) {
+      sheet->EnsureUniqueInner();
+    }
 
     // Enqueue all the sheet's children.
     sheet->AppendAllChildSheets(queue);
   }
 
   bool res = mNeedsRestyleAfterEnsureUniqueInner;
   mNeedsRestyleAfterEnsureUniqueInner = false;
   return res;