Bug 1403694 Part 2: Cleanup assertions nsStyleSheetService::LoadAndRegisterSheet to account for a Servo sheet not loading. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 29 Sep 2017 11:05:11 -0700
changeset 672745 39a34416928a762d17020c148228909792933a7a
parent 672744 11f421dcd737df628c741f497629a9374ae18911
child 733906 543c5462caa8009ee537c22e1b5a17f95f998501
push id82358
push userbwerth@mozilla.com
push dateFri, 29 Sep 2017 18:08:21 +0000
bugs1403694
milestone58.0a1
Bug 1403694 Part 2: Cleanup assertions nsStyleSheetService::LoadAndRegisterSheet to account for a Servo sheet not loading. MozReview-Commit-ID: HaSkVEG37Nz
layout/base/nsStyleSheetService.cpp
--- a/layout/base/nsStyleSheetService.cpp
+++ b/layout/base/nsStyleSheetService.cpp
@@ -170,32 +170,35 @@ nsStyleSheetService::LoadAndRegisterShee
         u"URI contains unescaped hash character, which might be truncating "
         u"the sheet, if it's a data URI.";
       consoleService->LogStringMessage(message);
     }
   }
 
   rv = LoadAndRegisterSheetInternal(aSheetURI, aSheetType);
   if (NS_SUCCEEDED(rv)) {
-    // We're guaranteed that the new sheet is the last sheet in
-    // m{Gecko,Servo}Sheets[aSheetType]
-
-    MOZ_ASSERT(mGeckoSheets[aSheetType].Length() ==
-                 mServoSheets[aSheetType].Length());
-
-    RefPtr<StyleSheet> geckoSheet = mGeckoSheets[aSheetType].LastElement();
-    RefPtr<StyleSheet> servoSheet = mServoSheets[aSheetType].LastElement();
+    // Success means that at least the Gecko sheet was loaded. It's possible
+    // that a Servo sheet was also loaded. In both cases, the new sheets are
+    // the last sheets in m{Gecko,Servo}Sheets[aSheetType]
+    bool servoSheetWasAdded = false;
+#ifdef MOZ_STYLO
+    servoSheetWasAdded = nsLayoutUtils::StyloSupportedInCurrentProcess();
+#endif
 
     // Hold on to a copy of the registered PresShells.
     nsTArray<nsCOMPtr<nsIPresShell>> toNotify(mPresShells);
     for (nsIPresShell* presShell : toNotify) {
       if (presShell->StyleSet()) {
-        StyleSheet* sheet = presShell->StyleSet()->IsGecko() ? geckoSheet
-                                                             : servoSheet;
-        presShell->NotifyStyleSheetServiceSheetAdded(sheet, aSheetType);
+        bool isGecko = presShell->StyleSet()->IsGecko();
+        // We always have a Gecko sheet; we sometimes have a Servo sheet.
+        if (isGecko || servoSheetWasAdded) {
+          StyleSheet* sheet = isGecko ? mGeckoSheets[aSheetType].LastElement() :
+            mServoSheets[aSheetType].LastElement();
+          presShell->NotifyStyleSheetServiceSheetAdded(sheet, aSheetType);
+        }
       }
     }
 
     if (XRE_IsParentProcess()) {
       nsTArray<dom::ContentParent*> children;
       dom::ContentParent::GetAll(children);
 
       if (children.IsEmpty()) {