Bug 1470420: Make Stop() infallible. r?xidorn
MozReview-Commit-ID: KScKUyUSkjj
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -2515,53 +2515,44 @@ StopLoadingSheets(
data->mIsCancelled = true;
aArr.AppendElement(data);
iter.Remove();
}
}
-nsresult
+void
Loader::Stop()
{
uint32_t pendingCount = mSheets ? mSheets->mPendingDatas.Count() : 0;
uint32_t loadingCount = mSheets ? mSheets->mLoadingDatas.Count() : 0;
LoadDataArray arr(pendingCount + loadingCount + mPostedEvents.Length());
if (pendingCount) {
StopLoadingSheets(mSheets->mPendingDatas, arr);
}
if (loadingCount) {
StopLoadingSheets(mSheets->mLoadingDatas, arr);
}
- uint32_t i;
- for (i = 0; i < mPostedEvents.Length(); ++i) {
- SheetLoadData* data = mPostedEvents[i];
+ for (RefPtr<SheetLoadData>& data : mPostedEvents) {
data->mIsCancelled = true;
- if (arr.AppendElement(data)) {
- // SheetComplete() calls Release(), so give this an extra ref.
- NS_ADDREF(data);
- }
-#ifdef DEBUG
- else {
- NS_NOTREACHED("We preallocated this memory... shouldn't really fail, "
- "except we never check that preallocation succeeds.");
- }
-#endif
+ // SheetComplete() calls Release(), so give this an extra ref.
+ NS_ADDREF(data);
+ // Move since we're about to get rid of the array below.
+ arr.AppendElement(std::move(data));
}
mPostedEvents.Clear();
mDatasToNotifyOn += arr.Length();
- for (i = 0; i < arr.Length(); ++i) {
+ for (RefPtr<SheetLoadData>& data : arr) {
--mDatasToNotifyOn;
- SheetComplete(arr[i], NS_BINDING_ABORTED);
+ SheetComplete(data, NS_BINDING_ABORTED);
}
- return NS_OK;
}
bool
Loader::HasPendingLoads()
{
return
(mSheets && mSheets->mLoadingDatas.Count() != 0) ||
(mSheets && mSheets->mPendingDatas.Count() != 0) ||
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -375,17 +375,17 @@ public:
CORSMode aCORSMode = CORS_NONE,
ReferrerPolicy aReferrerPolicy = mozilla::net::RP_Unset,
const nsAString& aIntegrity = EmptyString());
/**
* Stop loading all sheets. All nsICSSLoaderObservers involved will be
* notified with NS_BINDING_ABORTED as the status, possibly synchronously.
*/
- nsresult Stop(void);
+ void Stop();
/**
* nsresult Loader::StopLoadingSheet(nsIURI* aURL), which notifies the
* nsICSSLoaderObserver with NS_BINDING_ABORTED, was removed in Bug 556446.
* It can be found in revision 2c44a32052ad.
*/
/**
@@ -433,17 +433,17 @@ public:
// These interfaces are public only for the benefit of static functions
// within nsCSSLoader.cpp.
// IsAlternateSheet can change our currently selected style set if none is
// selected and aHasAlternateRel is false.
IsAlternate IsAlternateSheet(const nsAString& aTitle, bool aHasAlternateRel);
- typedef nsTArray<RefPtr<SheetLoadData> > LoadDataArray;
+ typedef nsTArray<RefPtr<SheetLoadData>> LoadDataArray;
// Measure our size.
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
// Marks all the sheets at the given URI obsolete, and removes them from the
// cache.
nsresult ObsoleteSheet(nsIURI* aURI);
@@ -590,17 +590,17 @@ private:
mLoadingDatas; // weak refs
nsDataHashtable<URIPrincipalReferrerPolicyAndCORSModeHashKey, SheetLoadData*>
mPendingDatas; // weak refs
};
nsAutoPtr<Sheets> mSheets;
// The array of posted stylesheet loaded events (SheetLoadDatas) we have.
// Note that these are rare.
- LoadDataArray mPostedEvents;
+ LoadDataArray mPostedEvents;
// Our array of "global" observers
nsTObserverArray<nsCOMPtr<nsICSSLoaderObserver> > mObservers;
// This reference is nulled by the Document in it's destructor through
// DropDocumentReference().
nsIDocument* MOZ_NON_OWNING_REF mDocument; // the document we live for