Bug 1457920: Loader::ParseSheet is not really fallible. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 30 Apr 2018 19:55:56 +0200
changeset 472619 f823923df3e626c88df6b83677ebbb8bb6ef83c3
parent 472618 af58b003b734c75f9b61cbd5ca8e98450638ba80
child 472620 fc7f512b30ecbb2b8050df919d842ff854cc1ae8
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1457920
milestone61.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 1457920: Loader::ParseSheet is not really fallible. r=xidorn MozReview-Commit-ID: IexX1RRCuF4
layout/style/Loader.cpp
layout/style/Loader.h
layout/style/StreamLoader.cpp
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -1628,37 +1628,39 @@ Loader::LoadSheet(SheetLoadData* aLoadDa
   aLoadData->mIsLoading = true;
 
   return NS_OK;
 }
 
 /**
  * ParseSheet handles parsing the data stream.
  */
-nsresult
+void
 Loader::ParseSheet(const nsAString& aUTF16,
                    const nsACString& aUTF8,
                    SheetLoadData* aLoadData,
                    bool aAllowAsync,
                    bool& aCompleted)
 {
   LOG(("css::Loader::ParseSheet"));
   MOZ_ASSERT(aLoadData, "Must have load data");
   MOZ_ASSERT(aLoadData->mSheet, "Must have sheet to parse into");
   aCompleted = false;
   MOZ_ASSERT(aUTF16.IsEmpty() || aUTF8.IsEmpty());
   if (!aUTF16.IsEmpty()) {
-    return DoParseSheetServo(NS_ConvertUTF16toUTF8(aUTF16),
-                             aLoadData, aAllowAsync, aCompleted);
+    DoParseSheetServo(NS_ConvertUTF16toUTF8(aUTF16),
+                      aLoadData,
+                      aAllowAsync,
+                      aCompleted);
   } else {
-    return DoParseSheetServo(aUTF8, aLoadData, aAllowAsync, aCompleted);
+    DoParseSheetServo(aUTF8, aLoadData, aAllowAsync, aCompleted);
   }
 }
 
-nsresult
+void
 Loader::DoParseSheetServo(const nsACString& aBytes,
                           SheetLoadData* aLoadData,
                           bool aAllowAsync,
                           bool& aCompleted)
 {
   aLoadData->mIsBeingParsed = true;
 
   StyleSheet* sheet = aLoadData->mSheet;
@@ -1672,17 +1674,17 @@ Loader::DoParseSheetServo(const nsACStri
 
     bool noPendingChildren = aLoadData->mPendingChildren == 0;
     MOZ_ASSERT_IF(aLoadData->mSyncLoad, noPendingChildren);
     if (noPendingChildren) {
       aCompleted = true;
       SheetComplete(aLoadData, NS_OK);
     }
 
-    return NS_OK;
+    return;
   }
 
   // This parse does not need to be synchronous. \o/
   //
   // Note that we need to block onload because there may be no network requests
   // pending.
   BlockOnload();
   RefPtr<SheetLoadData> loadData = aLoadData;
@@ -1695,18 +1697,16 @@ Loader::DoParseSheetServo(const nsACStri
       // If there are no child sheets outstanding, mark us as complete.
       // Otherwise, the children are holding strong refs to the data and
       // will call SheetComplete() on it when they complete.
       if (loadData->mPendingChildren == 0) {
         loadData->mLoader->SheetComplete(loadData, NS_OK);
       }
     }, [] { MOZ_CRASH("rejected parse promise"); }
   );
-
-  return NS_OK;
 }
 
 /**
  * SheetComplete is the do-it-all cleanup function.  It removes the
  * load data from the "loading" hashtable, adds the sheet to the
  * "completed" hashtable, massages the XUL cache, handles siblings of
  * the load data (other loads for the same URI), handles unblocking
  * blocked parent loads as needed, and most importantly calls
@@ -1974,23 +1974,17 @@ Loader::LoadInlineStyle(nsIContent* aEle
 
   NS_ADDREF(data);
   data->mLineNumber = aLineNumber;
   bool completed = true;
   // Parse completion releases the load data.
   //
   // Note that we need to parse synchronously, since the web expects that the
   // effects of inline stylesheets are visible immediately (aside from @imports).
-  rv = ParseSheet(aBuffer, EmptyCString(),
-                  data,
-                  /* aAllowAsync = */ false,
-                  completed);
-  if (NS_FAILED(rv)) {
-    return Err(rv);
-  }
+  ParseSheet(aBuffer, EmptyCString(), data, /* aAllowAsync = */ false, completed);
 
   // If completed is true, |data| may well be deleted by now.
   if (!completed) {
     data->mMustNotify = true;
   }
   return LoadSheetResult { completed ? Completed::Yes : Completed::No, isAlternate, matched };
 }
 
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -566,26 +566,26 @@ private:
                      StyleSheetState aSheetState,
                      bool aIsPreLoad);
 
   // Parse the stylesheet in aLoadData. The sheet data comes from aUTF16 if
   // UTF-16 and from aUTF8 if UTF-8.
   // Sets aCompleted to true if the parse finished, false otherwise (e.g. if the
   // sheet had an @import).  If aCompleted is true when this returns, then
   // ParseSheet also called SheetComplete on aLoadData.
-  nsresult ParseSheet(const nsAString& aUTF16,
-                      const nsACString& aUTF8,
-                      SheetLoadData* aLoadData,
-                      bool aAllowAsync,
-                      bool& aCompleted);
+  void ParseSheet(const nsAString& aUTF16,
+                  const nsACString& aUTF8,
+                  SheetLoadData* aLoadData,
+                  bool aAllowAsync,
+                  bool& aCompleted);
 
-  nsresult DoParseSheetServo(const nsACString& aBytes,
-                             SheetLoadData* aLoadData,
-                             bool aAllowAsync,
-                             bool& aCompleted);
+  void DoParseSheetServo(const nsACString& aBytes,
+                         SheetLoadData* aLoadData,
+                         bool aAllowAsync,
+                         bool& aCompleted);
 
   // The load of the sheet in aLoadData is done, one way or another.  Do final
   // cleanup, including releasing aLoadData.
   void SheetComplete(SheetLoadData* aLoadData, nsresult aStatus);
 
   // The guts of SheetComplete.  This may be called recursively on parent datas
   // or datas that had glommed on to a single load.  The array is there so load
   // datas whose observers need to be notified can be added to it.
--- a/layout/style/StreamLoader.cpp
+++ b/layout/style/StreamLoader.cpp
@@ -110,22 +110,23 @@ StreamLoader::OnStopRequest(nsIRequest* 
       NS_ENSURE_SUCCESS(rv, rv);
     }
   } // run destructor for `bytes`
 
   // For reasons I don't understand, factoring the below lines into
   // a method on SheetLoadData resulted in a linker error. Hence,
   // accessing fields of mSheetLoadData from here.
   bool dummy;
-  return mSheetLoadData->mLoader->ParseSheet(
+  mSheetLoadData->mLoader->ParseSheet(
     EmptyString(),
     utf8String,
     mSheetLoadData,
     /* aAllowAsync = */ true,
     dummy);
+  return NS_OK;
 }
 
 /* nsIStreamListener implementation */
 NS_IMETHODIMP
 StreamLoader::OnDataAvailable(nsIRequest*,
                               nsISupports*,
                               nsIInputStream* aInputStream,
                               uint64_t,