Bug 1374181 Part 1: Don't attempt EnsureUniqueInner on incomplete sheets in a StyleSet. r=xidorn
authorBrad Werth <bwerth@mozilla.com>
Tue, 03 Oct 2017 11:15:26 -0700
changeset 427201 eaddde278c9f0968585a5dc9286118548c1aea5b
parent 427200 e5c54805bcc18f3c700d2e4703c4e25a63fb396a
child 427202 e0fa535753a5cc390f4e33267843e39ddd99cb8c
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersxidorn
bugs1374181, 1404538
milestone58.0a1
Bug 1374181 Part 1: Don't attempt EnsureUniqueInner on incomplete sheets in a StyleSet. r=xidorn 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;