Bug 1403694 Part 2: Cleanup assertions nsStyleSheetService::LoadAndRegisterSheet to account for a Servo sheet not loading.
MozReview-Commit-ID: HaSkVEG37Nz
--- 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()) {