Bug 1519006 - Stop null checking infallible style sheet accessors in nsDocumentViewer::CreateStyleSet r=xidorn
authorCameron McCormack <cam@mcc.id.au>
Fri, 11 Jan 2019 03:12:28 +0000
changeset 510533 fb705f84a7921bd5a77108b99e2ffab51a53c09b
parent 510532 45d4ae4551a1e07cb5fa97d8405e6f9badcf7554
child 510534 908518e471cc31f9ae277ccf1873865df0ef7c7f
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1519006
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519006 - Stop null checking infallible style sheet accessors in nsDocumentViewer::CreateStyleSet r=xidorn Differential Revision: https://phabricator.services.mozilla.com/D16151
layout/base/nsDocumentViewer.cpp
layout/style/nsLayoutStylesheetCache.cpp
layout/style/nsLayoutStylesheetCache.h
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2303,66 +2303,42 @@ UniquePtr<ServoStyleSet> nsDocumentViewe
                           ? cache->GetUserChromeSheet()
                           : cache->GetUserContentSheet();
 
   if (sheet) {
     styleSet->AppendStyleSheet(SheetType::User, sheet);
   }
 
   // Append chrome sheets (scrollbars + forms).
-  sheet = cache->ScrollbarsSheet();
-  if (sheet) {
-    styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-  }
-
-  sheet = cache->FormsSheet();
-  if (sheet) {
-    styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-  }
-
+  styleSet->PrependStyleSheet(SheetType::Agent, cache->ScrollbarsSheet());
+  styleSet->PrependStyleSheet(SheetType::Agent, cache->FormsSheet());
+
+  // Only load the full XUL sheet if we'll need it.
   if (aDocument->LoadsFullXULStyleSheetUpFront()) {
-    sheet = cache->XULSheet();
-    if (sheet) {
-      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-    }
+    styleSet->PrependStyleSheet(SheetType::Agent, cache->XULSheet());
   }
 
-  sheet = cache->MinimalXULSheet();
-  if (sheet) {
-    // Load the minimal XUL rules for scrollbars and a few other XUL things
-    // that non-XUL (typically HTML) documents commonly use.
-    styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-  }
-
-  sheet = cache->CounterStylesSheet();
-  if (sheet) {
-    styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-  }
+  // Load the minimal XUL rules for scrollbars and a few other XUL things
+  // that non-XUL (typically HTML) documents commonly use.
+  styleSet->PrependStyleSheet(SheetType::Agent, cache->MinimalXULSheet());
+
+  styleSet->PrependStyleSheet(SheetType::Agent, cache->CounterStylesSheet());
 
   if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) {
-    sheet = cache->NoScriptSheet();
-    if (sheet) {
-      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-    }
+    styleSet->PrependStyleSheet(SheetType::Agent, cache->NoScriptSheet());
   }
 
   if (nsLayoutUtils::ShouldUseNoFramesSheet(aDocument)) {
-    sheet = cache->NoFramesSheet();
-    if (sheet) {
-      styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-    }
+    styleSet->PrependStyleSheet(SheetType::Agent, cache->NoFramesSheet());
   }
 
   // We don't add quirk.css here; nsPresContext::CompatibilityModeChanged will
   // append it if needed.
 
-  sheet = cache->HTMLSheet();
-  if (sheet) {
-    styleSet->PrependStyleSheet(SheetType::Agent, sheet);
-  }
+  styleSet->PrependStyleSheet(SheetType::Agent, cache->HTMLSheet());
 
   if (MOZ_LIKELY(mDocument->NodeInfoManager()->SVGEnabled())) {
     styleSet->PrependStyleSheet(SheetType::Agent, cache->SVGSheet());
   }
 
   if (MOZ_LIKELY(mDocument->NodeInfoManager()->MathMLEnabled())) {
     styleSet->PrependStyleSheet(SheetType::Agent, cache->MathMLSheet());
   }
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -45,21 +45,21 @@ nsresult nsLayoutStylesheetCache::Observ
     mFormsSheet = nullptr;
   } else {
     MOZ_ASSERT_UNREACHABLE("Unexpected observer topic.");
   }
   return NS_OK;
 }
 
 #define STYLE_SHEET(identifier_, url_, lazy_)                                  \
-  StyleSheet* nsLayoutStylesheetCache::identifier_##Sheet() {                  \
+  NotNull<StyleSheet*> nsLayoutStylesheetCache::identifier_##Sheet() {         \
     if (lazy_ && !m##identifier_##Sheet) {                                     \
       LoadSheetURL(url_, &m##identifier_##Sheet, eAgentSheetFeatures, eCrash); \
     }                                                                          \
-    return m##identifier_##Sheet;                                              \
+    return WrapNotNull(m##identifier_##Sheet);                                 \
   }
 #include "mozilla/UserAgentStyleSheetList.h"
 #undef STYLE_SHEET
 
 StyleSheet* nsLayoutStylesheetCache::GetUserContentSheet() {
   return mUserContentSheet;
 }
 
--- a/layout/style/nsLayoutStylesheetCache.h
+++ b/layout/style/nsLayoutStylesheetCache.h
@@ -6,16 +6,17 @@
 
 #ifndef nsLayoutStylesheetCache_h__
 #define nsLayoutStylesheetCache_h__
 
 #include "nsIMemoryReporter.h"
 #include "nsIObserver.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/NotNull.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/css/Loader.h"
 
 class nsIFile;
 class nsIURI;
 
 namespace mozilla {
 class CSSStyleSheet;
@@ -34,17 +35,17 @@ class nsLayoutStylesheetCache final : pu
                                       public nsIMemoryReporter {
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIMEMORYREPORTER
 
   static nsLayoutStylesheetCache* Singleton();
 
 #define STYLE_SHEET(identifier_, url_, lazy_) \
-  mozilla::StyleSheet* identifier_##Sheet();
+  mozilla::NotNull<mozilla::StyleSheet*> identifier_##Sheet();
 #include "mozilla/UserAgentStyleSheetList.h"
 #undef STYLE_SHEET
 
   mozilla::StyleSheet* GetUserContentSheet();
   mozilla::StyleSheet* GetUserChromeSheet();
   mozilla::StyleSheet* ChromePreferenceSheet(nsPresContext* aPresContext);
   mozilla::StyleSheet* ContentPreferenceSheet(nsPresContext* aPresContext);