diff --git a/accessible/base/EventQueue.cpp b/accessible/base/EventQueue.cpp index 71e06483efbb..34a2f658e698 100644 --- a/accessible/base/EventQueue.cpp +++ b/accessible/base/EventQueue.cpp @@ -31,7 +31,9 @@ bool EventQueue::PushEvent(AccEvent* aEvent) { aEvent->Document() == mDocument, "Queued event belongs to another document!"); - if (!mEvents.AppendElement(aEvent)) return false; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mEvents.AppendElement(aEvent); // Filter events. CoalesceEvents(); diff --git a/accessible/base/NotificationController.h b/accessible/base/NotificationController.h index c6aa1cf44c8b..f239731e0ff0 100644 --- a/accessible/base/NotificationController.h +++ b/accessible/base/NotificationController.h @@ -198,7 +198,10 @@ class NotificationController final : public EventQueue, * Pend an accessible subtree relocation. */ void ScheduleRelocation(Accessible* aOwner) { - if (!mRelocations.Contains(aOwner) && mRelocations.AppendElement(aOwner)) { + if (!mRelocations.Contains(aOwner)) { + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mRelocations.AppendElement(aOwner); ScheduleProcessing(); } } @@ -234,8 +237,12 @@ class NotificationController final : public EventQueue, RefPtr notification = new TNotification(aInstance, aMethod, aArgs...); - if (notification && mNotifications.AppendElement(notification)) + if (notification) { + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mNotifications.AppendElement(notification); ScheduleProcessing(); + } } /** @@ -249,8 +256,12 @@ class NotificationController final : public EventQueue, Class* aInstance, typename TNotification::Callback aMethod) { RefPtr notification = new TNotification(aInstance, aMethod); - if (notification && mNotifications.AppendElement(notification)) + if (notification) { + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mNotifications.AppendElement(notification); ScheduleProcessing(); + } } template @@ -259,7 +270,10 @@ class NotificationController final : public EventQueue, Arg* aArg) { RefPtr notification = new TNotification(aInstance, aMethod, aArg); - if (notification && mNotifications.AppendElement(notification)) { + if (notification) { + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mNotifications.AppendElement(notification); ScheduleProcessing(); } } diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index a64254db811b..82ca788e3efa 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -2130,8 +2130,9 @@ bool Accessible::InsertChildAt(uint32_t aIndex, Accessible* aChild) { if (!aChild) return false; if (aIndex == mChildren.Length()) { - if (!mChildren.AppendElement(aChild)) return false; - + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mChildren.AppendElement(aChild); } else { // XXX(Bug 1631371) Check if this should use a fallible operation as it // pretended earlier. diff --git a/accessible/generic/DocAccessible.h b/accessible/generic/DocAccessible.h index 4aa4314c5b44..48a6437b297f 100644 --- a/accessible/generic/DocAccessible.h +++ b/accessible/generic/DocAccessible.h @@ -424,7 +424,10 @@ class DocAccessible : public HyperTextAccessibleWrap, * accessibles. */ bool AppendChildDocument(DocAccessible* aChildDocument) { - return mChildDocuments.AppendElement(aChildDocument); + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mChildDocuments.AppendElement(aChildDocument); + return true; } /** diff --git a/docshell/base/nsDocShellEnumerator.cpp b/docshell/base/nsDocShellEnumerator.cpp index c759c8545af0..369878309bee 100644 --- a/docshell/base/nsDocShellEnumerator.cpp +++ b/docshell/base/nsDocShellEnumerator.cpp @@ -74,7 +74,7 @@ nsresult nsDocShellEnumerator::BuildArrayRecursiveBackwards( // add this item to the array if (mDocShellType == nsIDocShellTreeItem::typeAll || aItem->ItemType() == mDocShellType) { - if (!aItemArray.AppendElement(aItem)) { + if (!aItemArray.AppendElement(aItem, fallible)) { return NS_ERROR_OUT_OF_MEMORY; } } diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index d9e40bbe9b35..1e112d2047ed 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -692,10 +692,9 @@ bool CustomElementRegistry::JSObjectToAtomArray( return false; } - if (!aArray.AppendElement(NS_Atomize(attrStr))) { - aRv.Throw(NS_ERROR_OUT_OF_MEMORY); - return false; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aArray.AppendElement(NS_Atomize(attrStr)); } } diff --git a/dom/base/DOMStringList.h b/dom/base/DOMStringList.h index d08345336d1a..3c540f2dda6e 100644 --- a/dom/base/DOMStringList.h +++ b/dom/base/DOMStringList.h @@ -57,9 +57,11 @@ class DOMStringList : public nsISupports, public nsWrapperCache { } bool Add(const nsAString& aName) { - // XXXbz mNames should really be a fallible array; otherwise this - // return value is meaningless. - return mNames.AppendElement(aName) != nullptr; + // XXXbz(Bug 1631374) mNames should really be a fallible array; otherwise + // this return value is meaningless. return mNames.AppendElement(aName) != + // nullptr; + mNames.AppendElement(aName); + return true; } void Clear() { mNames.Clear(); } diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index 61eab0f9713b..519da2d22051 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -970,9 +970,9 @@ nsresult Selection::StyledRanges::MaybeAddRangeAndTruncateOverlaps( // a common case is that we have no ranges yet if (mRanges.Length() == 0) { - if (!mRanges.AppendElement(StyledRange(aRange))) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mRanges.AppendElement(StyledRange(aRange)); aRange->RegisterSelection(aSelection); *aOutIndex = 0; @@ -1175,8 +1175,9 @@ nsresult Selection::GetRangesForIntervalArray( if (startIndex == -1 || endIndex == -1) return NS_OK; for (int32_t i = startIndex; i < endIndex; i++) { - if (!aRanges->AppendElement(mStyledRanges.mRanges[i].mRange)) - return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aRanges->AppendElement(mStyledRanges.mRanges[i].mRange); } return NS_OK; diff --git a/dom/base/nsAttrValue.cpp b/dom/base/nsAttrValue.cpp index 1864fbd78715..3b720792db65 100644 --- a/dom/base/nsAttrValue.cpp +++ b/dom/base/nsAttrValue.cpp @@ -290,11 +290,13 @@ void nsAttrValue::SetTo(const nsAttrValue& aOther) { break; } case eAtomArray: { - if (!EnsureEmptyAtomArray() || - !GetAtomArrayValue()->AppendElements(*otherCont->mValue.mAtomArray)) { + if (!EnsureEmptyAtomArray()) { Reset(); return; } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + GetAtomArrayValue()->AppendElements(*otherCont->mValue.mAtomArray); break; } case eDoubleValue: { @@ -1125,10 +1127,9 @@ void nsAttrValue::ParseAtomArray(const nsAString& aValue) { AtomArray* array = GetAtomArrayValue(); - if (!array->AppendElement(std::move(classAtom))) { - Reset(); - return; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + array->AppendElement(std::move(classAtom)); // parse the rest of the classnames while (iter != end) { @@ -1140,10 +1141,9 @@ void nsAttrValue::ParseAtomArray(const nsAString& aValue) { classAtom = NS_AtomizeMainThread(Substring(start, iter)); - if (!array->AppendElement(std::move(classAtom))) { - Reset(); - return; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + array->AppendElement(std::move(classAtom)); // skip whitespace while (iter != end && nsContentUtils::IsHTMLWhitespace(*iter)) { diff --git a/dom/base/nsLineBreaker.cpp b/dom/base/nsLineBreaker.cpp index abd46d7e8094..c582a5b2037b 100644 --- a/dom/base/nsLineBreaker.cpp +++ b/dom/base/nsLineBreaker.cpp @@ -61,9 +61,9 @@ static void SetupCapitalization(const char16_t* aWord, uint32_t aLength, nsresult nsLineBreaker::FlushCurrentWord() { uint32_t length = mCurrentWord.Length(); AutoTArray breakState; - if (!breakState.AppendElements(length)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + breakState.AppendElements(length); nsTArray capitalizationState; @@ -128,8 +128,9 @@ nsresult nsLineBreaker::FlushCurrentWord() { if (!mWordContinuation && (ti->mFlags & BREAK_NEED_CAPITALIZATION)) { if (capitalizationState.Length() == 0) { - if (!capitalizationState.AppendElements(length)) - return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as + // it pretended earlier. + capitalizationState.AppendElements(length); memset(capitalizationState.Elements(), false, length * sizeof(bool)); SetupCapitalization(mCurrentWord.Elements(), length, capitalizationState.Elements()); @@ -192,14 +193,17 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, AutoTArray breakState; if (aSink) { - if (!breakState.AppendElements(aLength)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + breakState.AppendElements(aLength); } bool noCapitalizationNeeded = true; nsTArray capitalizationState; if (aSink && (aFlags & BREAK_NEED_CAPITALIZATION)) { - if (!capitalizationState.AppendElements(aLength)) - return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + capitalizationState.AppendElements(aLength); memset(capitalizationState.Elements(), false, aLength * sizeof(bool)); noCapitalizationNeeded = false; } @@ -370,7 +374,9 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage, AutoTArray breakState; if (aSink) { - if (!breakState.AppendElements(aLength)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + breakState.AppendElements(aLength); } uint32_t start = offset; diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index e6739c529a26..a2edd7f8f694 100644 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -2919,10 +2919,8 @@ bool Console::ArgumentData::Initialize(JSContext* aCx, const Sequence& aArguments) { mGlobal = JS::CurrentGlobalOrNull(aCx); - for (uint32_t i = 0; i < aArguments.Length(); ++i) { - if (NS_WARN_IF(!mArguments.AppendElement(aArguments[i]))) { - return false; - } + if (NS_WARN_IF(!mArguments.AppendElements(aArguments, fallible))) { + return false; } return true; diff --git a/dom/html/HTMLFormControlsCollection.cpp b/dom/html/HTMLFormControlsCollection.cpp index 6f76b32f707c..e779b4dd5704 100644 --- a/dom/html/HTMLFormControlsCollection.cpp +++ b/dom/html/HTMLFormControlsCollection.cpp @@ -208,11 +208,10 @@ nsresult HTMLFormControlsCollection::GetSortedControls( NS_ASSERTION(notInElementsIdx < notInElementsLen, "Should have remaining not-in-elements"); // Append the remaining mNotInElements elements - if (!aControls.AppendElements( - mNotInElements.Elements() + notInElementsIdx, - notInElementsLen - notInElementsIdx)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aControls.AppendElements(mNotInElements.Elements() + notInElementsIdx, + notInElementsLen - notInElementsIdx); break; } // Check whether we're done with mNotInElements @@ -220,10 +219,10 @@ nsresult HTMLFormControlsCollection::GetSortedControls( NS_ASSERTION(elementsIdx < elementsLen, "Should have remaining in-elements"); // Append the remaining mElements elements - if (!aControls.AppendElements(mElements.Elements() + elementsIdx, - elementsLen - elementsIdx)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aControls.AppendElements(mElements.Elements() + elementsIdx, + elementsLen - elementsIdx); break; } // Both lists have elements left. @@ -242,9 +241,9 @@ nsresult HTMLFormControlsCollection::GetSortedControls( ++notInElementsIdx; } // Add the first element to the list. - if (!aControls.AppendElement(elementToAdd)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aControls.AppendElement(elementToAdd); } NS_ASSERTION(aControls.Length() == elementsLen + notInElementsLen, diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index b66d0ed47411..5432a9c56302 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -920,7 +920,9 @@ int32_t MediaCache::FindBlockForIncomingData(AutoLock& aLock, TimeStamp aNow, PredictNextUseForIncomingData(aLock, aStream) >= PredictNextUse(aLock, aNow, blockIndex))) { blockIndex = mIndex.Length(); - if (!mIndex.AppendElement()) return -1; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mIndex.AppendElement(); mIndexWatermark = std::max(mIndexWatermark, blockIndex + 1); mFreeBlocks.AddFirstBlock(blockIndex); return blockIndex; diff --git a/dom/media/MediaStreamTrack.cpp b/dom/media/MediaStreamTrack.cpp index 4d89c6ac4379..08dbee41e176 100644 --- a/dom/media/MediaStreamTrack.cpp +++ b/dom/media/MediaStreamTrack.cpp @@ -497,7 +497,10 @@ void MediaStreamTrack::NotifyEnabledChanged() { bool MediaStreamTrack::AddPrincipalChangeObserver( PrincipalChangeObserver* aObserver) { - return mPrincipalChangeObservers.AppendElement(aObserver) != nullptr; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mPrincipalChangeObservers.AppendElement(aObserver); + return true; } bool MediaStreamTrack::RemovePrincipalChangeObserver( diff --git a/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp b/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp index cf61941827df..870663c939eb 100644 --- a/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp +++ b/dom/media/platforms/agnostic/bytestreams/AnnexB.cpp @@ -293,9 +293,9 @@ bool AnnexB::ConvertSampleToAVCC(mozilla::MediaRawData* aSample, 0xe0 /* num SPS (0) */, 0 /* num PPS (0) */ }; - if (!extradata->AppendElements(kFakeExtraData, ArrayLength(kFakeExtraData))) { - return false; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + extradata->AppendElements(kFakeExtraData, ArrayLength(kFakeExtraData)); aSample->mExtraData = std::move(extradata); return true; } diff --git a/dom/plugins/base/nsNPAPIPluginInstance.cpp b/dom/plugins/base/nsNPAPIPluginInstance.cpp index ae86ac1dece5..530f070a8484 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.cpp +++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp @@ -773,11 +773,9 @@ nsresult nsNPAPIPluginInstance::PushPopupsEnabledState(bool aEnabled) { aEnabled ? PopupBlocker::openAllowed : PopupBlocker::openAbused, true); - if (!mPopupStates.AppendElement(oldState)) { - // Appending to our state stack failed, pop what we just pushed. - PopupBlocker::PopPopupControlState(oldState); - return NS_ERROR_FAILURE; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mPopupStates.AppendElement(oldState); return NS_OK; } diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h index 6aff54bb1a40..18ec4378664f 100644 --- a/dom/script/ScriptLoader.h +++ b/dom/script/ScriptLoader.h @@ -340,7 +340,10 @@ class ScriptLoader final : public nsISupports { nsresult ProcessOffThreadRequest(ScriptLoadRequest* aRequest); bool AddPendingChildLoader(ScriptLoader* aChild) { - return mPendingChildLoaders.AppendElement(aChild) != nullptr; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. Else, change the return type to void. + mPendingChildLoaders.AppendElement(aChild); + return true; } mozilla::dom::DocGroup* GetDocGroup() const { diff --git a/dom/svg/SVGPathData.cpp b/dom/svg/SVGPathData.cpp index 2cba669e2741..f442ff5c524b 100644 --- a/dom/svg/SVGPathData.cpp +++ b/dom/svg/SVGPathData.cpp @@ -143,10 +143,9 @@ bool SVGPathData::GetSegmentLengths(nsTArray* aLengths) const { while (i < mData.Length()) { state.length = 0.0; SVGPathSegUtils::TraversePathSegment(&mData[i], state); - if (!aLengths->AppendElement(state.length)) { - aLengths->Clear(); - return false; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aLengths->AppendElement(state.length); i += 1 + SVGPathSegUtils::ArgCountForType(mData[i]); } @@ -1043,12 +1042,11 @@ void SVGPathData::GetMarkerPositioningData(nsTArray* aMarks) const { } // Add the mark at the end of this segment, and set its position: - if (!aMarks->AppendElement(SVGMark(static_cast(segEnd.x), - static_cast(segEnd.y), 0.0f, - SVGMark::eMid))) { - aMarks->Clear(); // OOM, so try to free some - return; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aMarks->AppendElement(SVGMark(static_cast(segEnd.x), + static_cast(segEnd.y), 0.0f, + SVGMark::eMid)); if (segType == PATHSEG_CLOSEPATH && prevSegType != PATHSEG_CLOSEPATH) { aMarks->LastElement().angle = aMarks->ElementAt(pathStartIndex).angle = diff --git a/dom/workers/Queue.h b/dom/workers/Queue.h index 440b3807065f..7b39eb9be1db 100644 --- a/dom/workers/Queue.h +++ b/dom/workers/Queue.h @@ -38,7 +38,10 @@ struct StorageWithTArray { } static bool Push(StorageType& aStorage, const T& aEntry) { - return !!aStorage.AppendElement(aEntry); + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aStorage.AppendElement(aEntry); + return true; } static bool Pop(StorageType& aStorage, T& aEntry) { diff --git a/dom/xslt/base/txNamespaceMap.cpp b/dom/xslt/base/txNamespaceMap.cpp index d9f282685ca5..a8e80ebee83c 100644 --- a/dom/xslt/base/txNamespaceMap.cpp +++ b/dom/xslt/base/txNamespaceMap.cpp @@ -47,15 +47,13 @@ nsresult txNamespaceMap::mapNamespace(nsAtom* aPrefix, } // New mapping - if (!mPrefixes.AppendElement(prefix)) { - return NS_ERROR_OUT_OF_MEMORY; - } - - if (mNamespaces.AppendElement(nsId) == nullptr) { - mPrefixes.RemoveLastElement(); + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mPrefixes.AppendElement(prefix); - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mNamespaces.AppendElement(nsId); return NS_OK; } diff --git a/dom/xslt/base/txStack.h b/dom/xslt/base/txStack.h index a253d3c6b51e..310457e8cd78 100644 --- a/dom/xslt/base/txStack.h +++ b/dom/xslt/base/txStack.h @@ -28,7 +28,10 @@ class txStack : private nsTArray { * top of this stack. */ inline nsresult push(void* aObject) { - return AppendElement(aObject) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + AppendElement(aObject); + return NS_OK; } /** diff --git a/dom/xslt/xpath/txExpr.h b/dom/xslt/xpath/txExpr.h index 8122976c04d7..98af9ef65ea9 100644 --- a/dom/xslt/xpath/txExpr.h +++ b/dom/xslt/xpath/txExpr.h @@ -225,7 +225,10 @@ class FunctionCall : public Expr { * @return nsresult indicating out of memory */ nsresult addParam(Expr* aExpr) { - return mParams.AppendElement(aExpr) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mParams.AppendElement(aExpr); + return NS_OK; } /** @@ -448,7 +451,10 @@ class PredicateList { */ nsresult add(Expr* aExpr) { NS_ASSERTION(aExpr, "missing expression"); - return mPredicates.AppendElement(aExpr) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mPredicates.AppendElement(aExpr); + return NS_OK; } nsresult evaluatePredicates(txNodeSet* aNodes, txIMatchContext* aContext); @@ -784,7 +790,10 @@ class UnionExpr : public Expr { * @return nsresult indicating out of memory */ nsresult addExpr(Expr* aExpr) { - return mExpressions.AppendElement(aExpr) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mExpressions.AppendElement(aExpr); + return NS_OK; } /** @@ -826,7 +835,10 @@ class txNamedAttributeStep : public Expr { class txUnionNodeTest : public txNodeTest { public: nsresult addNodeTest(txNodeTest* aNodeTest) { - return mNodeTests.AppendElement(aNodeTest) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mNodeTests.AppendElement(aNodeTest); + return NS_OK; } TX_DECL_NODE_TEST diff --git a/dom/xslt/xslt/txBufferingHandler.cpp b/dom/xslt/xslt/txBufferingHandler.cpp index 815eb88e136b..e3fbd5c82e1f 100644 --- a/dom/xslt/xslt/txBufferingHandler.cpp +++ b/dom/xslt/xslt/txBufferingHandler.cpp @@ -288,9 +288,9 @@ txResultBuffer::~txResultBuffer() { } nsresult txResultBuffer::addTransaction(txOutputTransaction* aTransaction) { - if (mTransactions.AppendElement(aTransaction) == nullptr) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mTransactions.AppendElement(aTransaction); return NS_OK; } diff --git a/dom/xslt/xslt/txExecutionState.cpp b/dom/xslt/xslt/txExecutionState.cpp index b595e5278b79..ac33745f1fa0 100644 --- a/dom/xslt/xslt/txExecutionState.cpp +++ b/dom/xslt/xslt/txExecutionState.cpp @@ -319,7 +319,10 @@ txIEvalContext* txExecutionState::popEvalContext() { } nsresult txExecutionState::pushBool(bool aBool) { - return mBoolStack.AppendElement(aBool) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mBoolStack.AppendElement(aBool); + return NS_OK; } bool txExecutionState::popBool() { diff --git a/dom/xslt/xslt/txStylesheet.cpp b/dom/xslt/xslt/txStylesheet.cpp index 0769dc9c665a..c81158c0d4bf 100644 --- a/dom/xslt/xslt/txStylesheet.cpp +++ b/dom/xslt/xslt/txStylesheet.cpp @@ -305,9 +305,9 @@ nsresult txStylesheet::doneCompiling() { itemIter.remove(); // remove() moves to the previous itemIter.next(); } - if (!mStripSpaceTests.AppendElements(frameStripSpaceTests)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mStripSpaceTests.AppendElements(frameStripSpaceTests); frameStripSpaceTests.Clear(); } diff --git a/dom/xslt/xslt/txStylesheetCompiler.cpp b/dom/xslt/xslt/txStylesheetCompiler.cpp index f68f5910cd33..cfe3542c59ad 100644 --- a/dom/xslt/xslt/txStylesheetCompiler.cpp +++ b/dom/xslt/xslt/txStylesheetCompiler.cpp @@ -212,10 +212,9 @@ nsresult txStylesheetCompiler::startElementInternal( if (namespaceID == kNameSpaceID_Unknown) return NS_ERROR_XSLT_PARSE_FAILURE; - if (!mElementContext->mInstructionNamespaces.AppendElement( - namespaceID)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mElementContext->mInstructionNamespaces.AppendElement(namespaceID); } attr->mLocalName = nullptr; @@ -678,9 +677,9 @@ nsresult txStylesheetCompilerState::loadIncludedStylesheet( // step forward before calling the observer in case of syncronous loading mToplevelIterator.next(); - if (mChildCompilerList.AppendElement(compiler) == nullptr) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mChildCompilerList.AppendElement(compiler); rv = mObserver->loadURI(aURI, mStylesheetURI, mReferrerPolicy, compiler); if (NS_FAILED(rv)) { @@ -709,9 +708,9 @@ nsresult txStylesheetCompilerState::loadImportedStylesheet( aURI, mStylesheet, &iter, mReferrerPolicy, observer); NS_ENSURE_TRUE(compiler, NS_ERROR_OUT_OF_MEMORY); - if (mChildCompilerList.AppendElement(compiler) == nullptr) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mChildCompilerList.AppendElement(compiler); nsresult rv = mObserver->loadURI(aURI, mStylesheetURI, mReferrerPolicy, compiler); @@ -724,20 +723,17 @@ nsresult txStylesheetCompilerState::loadImportedStylesheet( nsresult txStylesheetCompilerState::addGotoTarget( txInstruction** aTargetPointer) { - if (mGotoTargetPointers.AppendElement(aTargetPointer) == nullptr) { - return NS_ERROR_OUT_OF_MEMORY; - } - + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mGotoTargetPointers.AppendElement(aTargetPointer); return NS_OK; } nsresult txStylesheetCompilerState::addVariable(const txExpandedName& aName) { txInScopeVariable* var = new txInScopeVariable(aName); - if (!mInScopeVariables.AppendElement(var)) { - delete var; - return NS_ERROR_OUT_OF_MEMORY; - } - + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mInScopeVariables.AppendElement(var); return NS_OK; } diff --git a/dom/xslt/xslt/txToplevelItems.cpp b/dom/xslt/xslt/txToplevelItems.cpp index 88b5d48a64e2..34d2681ce888 100644 --- a/dom/xslt/xslt/txToplevelItems.cpp +++ b/dom/xslt/xslt/txToplevelItems.cpp @@ -27,10 +27,9 @@ txStripSpaceItem::~txStripSpaceItem() { nsresult txStripSpaceItem::addStripSpaceTest( txStripSpaceTest* aStripSpaceTest) { - if (!mStripSpaceTests.AppendElement(aStripSpaceTest)) { - return NS_ERROR_OUT_OF_MEMORY; - } - + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mStripSpaceTests.AppendElement(aStripSpaceTest); return NS_OK; } diff --git a/dom/xslt/xslt/txXSLTPatterns.h b/dom/xslt/xslt/txXSLTPatterns.h index a309bf05b5b2..2acc526225ea 100644 --- a/dom/xslt/xslt/txXSLTPatterns.h +++ b/dom/xslt/xslt/txXSLTPatterns.h @@ -103,8 +103,10 @@ class txPattern { class txUnionPattern : public txPattern { public: nsresult addPattern(txPattern* aPattern) { - return mLocPathPatterns.AppendElement(aPattern) ? NS_OK - : NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mLocPathPatterns.AppendElement(aPattern); + return NS_OK; } TX_DECL_PATTERN; diff --git a/dom/xul/nsXULContentSink.cpp b/dom/xul/nsXULContentSink.cpp index 838ff5cd4793..80c4bc62d394 100644 --- a/dom/xul/nsXULContentSink.cpp +++ b/dom/xul/nsXULContentSink.cpp @@ -524,9 +524,9 @@ XULContentSinkImpl::HandleProcessingInstruction(const char16_t* aTarget, return rv; } - if (!children->AppendElement(pi)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + children->AppendElement(pi); return NS_OK; } diff --git a/dom/xul/nsXULPrototypeDocument.cpp b/dom/xul/nsXULPrototypeDocument.cpp index 9e711a82f252..5574e771af07 100644 --- a/dom/xul/nsXULPrototypeDocument.cpp +++ b/dom/xul/nsXULPrototypeDocument.cpp @@ -365,9 +365,9 @@ void nsXULPrototypeDocument::SetRootElement(nsXULPrototypeElement* aElement) { nsresult nsXULPrototypeDocument::AddProcessingInstruction( nsXULPrototypePI* aPI) { MOZ_ASSERT(aPI, "null ptr"); - if (!mProcessingInstructions.AppendElement(aPI)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mProcessingInstructions.AppendElement(aPI); return NS_OK; } @@ -400,9 +400,9 @@ nsresult nsXULPrototypeDocument::AwaitLoadDone(Callback&& aCallback, *aResult = mLoaded; if (!mLoaded) { - rv = mPrototypeWaiters.AppendElement(std::move(aCallback)) - ? NS_OK - : NS_ERROR_OUT_OF_MEMORY; // addrefs + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mPrototypeWaiters.AppendElement(std::move(aCallback)); } return rv; diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp index dfd86a3f0181..76a3c3cc721c 100644 --- a/gfx/thebes/gfxWindowsPlatform.cpp +++ b/gfx/thebes/gfxWindowsPlatform.cpp @@ -970,11 +970,14 @@ void gfxWindowsPlatform::GetDLLVersion(char16ptr_t aDLLPath, versInfoSize = GetFileVersionInfoSizeW(aDLLPath, nullptr); AutoTArray versionInfo; - if (versInfoSize == 0 || - !versionInfo.AppendElements(uint32_t(versInfoSize))) { + if (versInfoSize == 0) { return; } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + versionInfo.AppendElements(uint32_t(versInfoSize)); + if (!GetFileVersionInfoW(aDLLPath, 0, versInfoSize, LPBYTE(versionInfo.Elements()))) { return; diff --git a/image/encoders/bmp/nsBMPEncoder.cpp b/image/encoders/bmp/nsBMPEncoder.cpp index 9401873f04fe..2d97f7305a37 100644 --- a/image/encoders/bmp/nsBMPEncoder.cpp +++ b/image/encoders/bmp/nsBMPEncoder.cpp @@ -271,17 +271,13 @@ nsresult nsBMPEncoder::ParseOptions(const nsAString& aOptions, // From a format like: name=value;bpp=;name=value // to format: [0] = name=value, [1] = bpp=, [2] = name=value nsTArray nameValuePairs; - if (!ParseString(NS_ConvertUTF16toUTF8(aOptions), ';', nameValuePairs)) { - return NS_ERROR_INVALID_ARG; - } + ParseString(NS_ConvertUTF16toUTF8(aOptions), ';', nameValuePairs); // For each name/value pair in the set for (uint32_t i = 0; i < nameValuePairs.Length(); ++i) { // Split the name value pair [0] = name, [1] = value nsTArray nameValuePair; - if (!ParseString(nameValuePairs[i], '=', nameValuePair)) { - return NS_ERROR_INVALID_ARG; - } + ParseString(nameValuePairs[i], '=', nameValuePair); if (nameValuePair.Length() != 2) { return NS_ERROR_INVALID_ARG; } diff --git a/image/encoders/ico/nsICOEncoder.cpp b/image/encoders/ico/nsICOEncoder.cpp index c4a75331b6e7..fd7d0a0a9731 100644 --- a/image/encoders/ico/nsICOEncoder.cpp +++ b/image/encoders/ico/nsICOEncoder.cpp @@ -261,17 +261,13 @@ nsresult nsICOEncoder::ParseOptions(const nsAString& aOptions, // From format: format=;bpp= // to format: [0] = format=, [1] = bpp= nsTArray nameValuePairs; - if (!ParseString(NS_ConvertUTF16toUTF8(aOptions), ';', nameValuePairs)) { - return NS_ERROR_INVALID_ARG; - } + ParseString(NS_ConvertUTF16toUTF8(aOptions), ';', nameValuePairs); // For each name/value pair in the set for (unsigned i = 0; i < nameValuePairs.Length(); ++i) { // Split the name value pair [0] = name, [1] = value nsTArray nameValuePair; - if (!ParseString(nameValuePairs[i], '=', nameValuePair)) { - return NS_ERROR_INVALID_ARG; - } + ParseString(nameValuePairs[i], '=', nameValuePair); if (nameValuePair.Length() != 2) { return NS_ERROR_INVALID_ARG; } diff --git a/intl/lwbrk/LineBreaker.cpp b/intl/lwbrk/LineBreaker.cpp index 8a148ebf436f..23c9aea5f66d 100644 --- a/intl/lwbrk/LineBreaker.cpp +++ b/intl/lwbrk/LineBreaker.cpp @@ -921,16 +921,18 @@ int32_t LineBreaker::WordMove(const char16_t* aText, uint32_t aLen, int32_t ret; AutoTArray breakState; - if (!textNeedsJISx4051 || !breakState.AppendElements(end - begin)) { + if (!textNeedsJISx4051) { // No complex text character, do not try to do complex line break. // (This is required for serializers. See Bug #344816.) - // Also fall back to this when out of memory. if (aDirection < 0) { ret = (begin == int32_t(aPos)) ? begin - 1 : begin; } else { ret = end; } } else { + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + breakState.AppendElements(end - begin); GetJISx4051Breaks(aText + begin, end - begin, WordBreak::Normal, Strictness::Auto, false, breakState.Elements()); diff --git a/intl/lwbrk/nsPangoBreaker.cpp b/intl/lwbrk/nsPangoBreaker.cpp index 4fb126c560e1..ca3d3d54c9f6 100644 --- a/intl/lwbrk/nsPangoBreaker.cpp +++ b/intl/lwbrk/nsPangoBreaker.cpp @@ -17,7 +17,9 @@ void NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength, memset(aBreakBefore, false, aLength * sizeof(uint8_t)); AutoTArray attrBuffer; - if (!attrBuffer.AppendElements(aLength + 1)) return; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + attrBuffer.AppendElements(aLength + 1); NS_ConvertUTF16toUTF8 aUTF8(aText, aLength); diff --git a/intl/lwbrk/nsUniscribeBreaker.cpp b/intl/lwbrk/nsUniscribeBreaker.cpp index d9950be64aa6..503b756b61d4 100644 --- a/intl/lwbrk/nsUniscribeBreaker.cpp +++ b/intl/lwbrk/nsUniscribeBreaker.cpp @@ -24,14 +24,16 @@ void NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength, memset(aBreakBefore, false, aLength); - if (!items.AppendElements(64)) return; + items.AppendElements(64); do { result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr, items.Elements(), &outItems); if (result == E_OUTOFMEMORY) { - if (!items.AppendElements(items.Length())) return; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + items.AppendElements(items.Length()); } } while (result == E_OUTOFMEMORY); @@ -41,7 +43,9 @@ void NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength, uint32_t startOffset = items[iItem].iCharPos; AutoTArray sla; - if (!sla.AppendElements(endOffset - startOffset)) return; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + sla.AppendElements(endOffset - startOffset); if (ScriptBreak(text + startOffset, endOffset - startOffset, &items[iItem].a, sla.Elements()) < 0) diff --git a/ipc/glue/WindowsMessageLoop.cpp b/ipc/glue/WindowsMessageLoop.cpp index 813070feb4f8..1c20e55052f6 100644 --- a/ipc/glue/WindowsMessageLoop.cpp +++ b/ipc/glue/WindowsMessageLoop.cpp @@ -539,10 +539,9 @@ LRESULT CALLBACK CallWindowProcedureHook(int nCode, WPARAM wParam, if (!gNeuteredWindows->Contains(hWnd) && !SuppressedNeuteringRegion::IsNeuteringSuppressed() && NeuterWindowProcedure(hWnd)) { - if (!gNeuteredWindows->AppendElement(hWnd)) { - NS_ERROR("Out of memory!"); - RestoreWindowProcedure(hWnd); - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + gNeuteredWindows->AppendElement(hWnd); } } return CallNextHookEx(nullptr, nCode, wParam, lParam); diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp index f586bbc7f9e8..05c4c0b712fd 100644 --- a/js/xpconnect/src/ExportHelpers.cpp +++ b/js/xpconnect/src/ExportHelpers.cpp @@ -134,9 +134,9 @@ class MOZ_STACK_CLASS StackScopedCloneData : public StructuredCloneHolderBase { BlobImpl* blobImpl = blob->Impl(); MOZ_ASSERT(blobImpl); - if (!mBlobImpls.AppendElement(blobImpl)) { - return false; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mBlobImpls.AppendElement(blobImpl); size_t idx = mBlobImpls.Length() - 1; return JS_WriteUint32Pair(aWriter, SCTAG_BLOB, 0) && diff --git a/js/xpconnect/src/XPCWrappedNative.cpp b/js/xpconnect/src/XPCWrappedNative.cpp index f5b8fe9da4bc..ffc7df8b1da5 100644 --- a/js/xpconnect/src/XPCWrappedNative.cpp +++ b/js/xpconnect/src/XPCWrappedNative.cpp @@ -1421,11 +1421,9 @@ bool CallMethodHelper::InitializeDispatchParams() { mJSContextIndex = mMethodInfo->IndexOfJSContext(); // Allocate enough space in mDispatchParams up-front. - if (!mDispatchParams.AppendElements(paramCount + wantsJSContext + - wantsOptArgc)) { - Throw(NS_ERROR_OUT_OF_MEMORY, mCallContext); - return false; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mDispatchParams.AppendElements(paramCount + wantsJSContext + wantsOptArgc); // Initialize each parameter to a valid state (for safe cleanup later). for (uint8_t i = 0, paramIdx = 0; i < mDispatchParams.Length(); i++) { diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index 053fd94e83cc..05b8a8efa328 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -4992,8 +4992,10 @@ already_AddRefed PresShell::RenderNode( } UniquePtr info = CreateRangePaintInfo(range, area, false); - if (info && !rangeItems.AppendElement(std::move(info))) { - return nullptr; + if (info) { + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + rangeItems.AppendElement(std::move(info)); } Maybe region = aRegion; @@ -5035,8 +5037,10 @@ already_AddRefed PresShell::RenderSelection( RefPtr range = aSelection->GetRangeAt(r); UniquePtr info = CreateRangePaintInfo(range, area, true); - if (info && !rangeItems.AppendElement(std::move(info))) { - return nullptr; + if (info) { + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + rangeItems.AppendElement(std::move(info)); } } diff --git a/layout/forms/nsColorControlFrame.cpp b/layout/forms/nsColorControlFrame.cpp index 8c23550a6d07..b51e79c39817 100644 --- a/layout/forms/nsColorControlFrame.cpp +++ b/layout/forms/nsColorControlFrame.cpp @@ -66,9 +66,9 @@ nsresult nsColorControlFrame::CreateAnonymousContent( nsresult rv = UpdateColor(); NS_ENSURE_SUCCESS(rv, rv); - if (!aElements.AppendElement(mColorContent)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aElements.AppendElement(mColorContent); return NS_OK; } diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index 745c7ec90027..537d566cf9ed 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -1163,7 +1163,9 @@ nsresult nsComboboxControlFrame::CreateAnonymousContent( } ActuallyDisplayText(false); - if (!aElements.AppendElement(mDisplayContent)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aElements.AppendElement(mDisplayContent); mButtonContent = mContent->OwnerDoc()->CreateHTMLElement(nsGkAtoms::button); if (!mButtonContent) return NS_ERROR_OUT_OF_MEMORY; @@ -1188,7 +1190,9 @@ nsresult nsComboboxControlFrame::CreateAnonymousContent( false); } - if (!aElements.AppendElement(mButtonContent)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aElements.AppendElement(mButtonContent); return NS_OK; } diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index f4d908723bcc..114c4a713961 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -256,9 +256,12 @@ nsresult nsFileControlFrame::CreateAnonymousContent( fileContent->GetAccessKey(accessKey); mBrowseFilesOrDirs = MakeAnonButton(doc, "Browse", fileContent, accessKey); - if (!mBrowseFilesOrDirs || !aElements.AppendElement(mBrowseFilesOrDirs)) { + if (!mBrowseFilesOrDirs) { return NS_ERROR_OUT_OF_MEMORY; } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aElements.AppendElement(mBrowseFilesOrDirs); // Create and setup the text showing the selected files. mTextContent = doc->CreateHTMLElement(nsGkAtoms::label); diff --git a/layout/forms/nsProgressFrame.cpp b/layout/forms/nsProgressFrame.cpp index b3eff1c23da6..6b90873b9069 100644 --- a/layout/forms/nsProgressFrame.cpp +++ b/layout/forms/nsProgressFrame.cpp @@ -56,9 +56,9 @@ nsresult nsProgressFrame::CreateAnonymousContent( // Associate ::-moz-progress-bar pseudo-element to the anonymous child. mBarDiv->SetPseudoElementType(PseudoStyleType::mozProgressBar); - if (!aElements.AppendElement(mBarDiv)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aElements.AppendElement(mBarDiv); return NS_OK; } diff --git a/layout/forms/nsRangeFrame.cpp b/layout/forms/nsRangeFrame.cpp index 09bf372ded8a..b47f0393096f 100644 --- a/layout/forms/nsRangeFrame.cpp +++ b/layout/forms/nsRangeFrame.cpp @@ -105,9 +105,9 @@ nsresult nsRangeFrame::MakeAnonymousDiv(Element** aResult, // Associate the pseudo-element with the anonymous child. resultElement->SetPseudoElementType(aPseudoType); - if (!aElements.AppendElement(resultElement)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aElements.AppendElement(resultElement); resultElement.forget(aResult); return NS_OK; diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 34e028148e45..f03ecca0401e 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -8001,10 +8001,9 @@ ClusterIterator::ClusterIterator(nsTextFrame* aTextFrame, int32_t aPosition, int32_t textOffset = aTextFrame->GetContentOffset(); int32_t textLen = aTextFrame->GetContentLength(); - if (!mWordBreaks.AppendElements(textLen + 1)) { - mDirection = 0; // signal failure - return; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mWordBreaks.AppendElements(textLen + 1); memset(mWordBreaks.Elements(), false, (textLen + 1) * sizeof(bool)); int32_t textStart; if (aDirection > 0) { diff --git a/layout/generic/nsTextRunTransformations.cpp b/layout/generic/nsTextRunTransformations.cpp index f54a021baa8b..12e3788c0bd8 100644 --- a/layout/generic/nsTextRunTransformations.cpp +++ b/layout/generic/nsTextRunTransformations.cpp @@ -59,9 +59,9 @@ already_AddRefed nsTransformedTextRun::Create( void nsTransformedTextRun::SetCapitalization(uint32_t aStart, uint32_t aLength, bool* aCapitalization) { if (mCapitalize.IsEmpty()) { - if (!mCapitalize.AppendElements(GetLength())) { - return; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mCapitalize.AppendElements(GetLength()); memset(mCapitalize.Elements(), 0, GetLength() * sizeof(bool)); } memcpy(mCapitalize.Elements() + aStart, aCapitalization, diff --git a/layout/generic/nsVideoFrame.cpp b/layout/generic/nsVideoFrame.cpp index 2f399ee36e6c..6e0c6d11834f 100644 --- a/layout/generic/nsVideoFrame.cpp +++ b/layout/generic/nsVideoFrame.cpp @@ -113,7 +113,9 @@ nsresult nsVideoFrame::CreateAnonymousContent( UpdatePosterSource(false); - if (!aElements.AppendElement(mPosterImage)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aElements.AppendElement(mPosterImage); // Set up the caption overlay div for showing any TextTrack data nodeInfo = nodeInfoManager->GetNodeInfo( @@ -125,7 +127,9 @@ nsresult nsVideoFrame::CreateAnonymousContent( static_cast(mCaptionDiv.get()); div->SetClassName(NS_LITERAL_STRING("caption-box")); - if (!aElements.AppendElement(mCaptionDiv)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aElements.AppendElement(mCaptionDiv); UpdateTextTrack(); } diff --git a/layout/mathml/nsMathMLmencloseFrame.cpp b/layout/mathml/nsMathMLmencloseFrame.cpp index 108446c7c926..aa89c37a7d70 100644 --- a/layout/mathml/nsMathMLmencloseFrame.cpp +++ b/layout/mathml/nsMathMLmencloseFrame.cpp @@ -73,7 +73,9 @@ nsresult nsMathMLmencloseFrame::AllocateMathMLChar(nsMencloseNotation mask) { uint32_t i = mMathMLChar.Length(); nsAutoString Char; - if (!mMathMLChar.AppendElement()) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mMathMLChar.AppendElement(); if (mask == NOTATION_LONGDIV) { Char.Assign(kLongDivChar); diff --git a/layout/style/nsTransitionManager.cpp b/layout/style/nsTransitionManager.cpp index c10fbe231414..54a3275f9519 100644 --- a/layout/style/nsTransitionManager.cpp +++ b/layout/style/nsTransitionManager.cpp @@ -849,10 +849,9 @@ bool nsTransitionManager::ConsiderInitiatingTransition( oldTransition = nullptr; // Clear pointer so it doesn't dangle animations[currentIndex] = animation; } else { - if (!animations.AppendElement(animation)) { - NS_WARNING("out of memory"); - return false; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + animations.AppendElement(animation); } EffectSet* effectSet = EffectSet::GetEffectSet(aElement, aPseudoType); diff --git a/layout/tables/nsCellMap.cpp b/layout/tables/nsCellMap.cpp index 060c2b453594..448b5122556e 100644 --- a/layout/tables/nsCellMap.cpp +++ b/layout/tables/nsCellMap.cpp @@ -254,12 +254,9 @@ void nsTableCellMap::Synchronize(nsTableFrame* aTableFrame) { map = GetMapFor(static_cast(rgFrame->FirstInFlow()), map); if (map) { - if (!maps.AppendElement(map)) { - delete map; - map = nullptr; - NS_WARNING("Could not AppendElement"); - break; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + maps.AppendElement(map); } } if (maps.IsEmpty()) { @@ -382,13 +379,13 @@ CellData* nsTableCellMap::GetDataAt(int32_t aRowIndex, } void nsTableCellMap::AddColsAtEnd(uint32_t aNumCols) { - if (!mCols.AppendElements(aNumCols)) { - NS_WARNING("Could not AppendElement"); - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mCols.AppendElements(aNumCols); if (mBCInfo) { - if (!mBCInfo->mBEndBorders.AppendElements(aNumCols)) { - NS_WARNING("Could not AppendElement"); - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mBCInfo->mBEndBorders.AppendElements(aNumCols); } } diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp index c827965f983f..4ae6c6d99548 100644 --- a/layout/tables/nsTableRowGroupFrame.cpp +++ b/layout/tables/nsTableRowGroupFrame.cpp @@ -568,9 +568,9 @@ void nsTableRowGroupFrame::CalculateRowBSizes(nsPresContext* aPresContext, if (numRows <= 0) return; AutoTArray rowInfo; - if (!rowInfo.AppendElements(numRows)) { - return; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + rowInfo.AppendElements(numRows); bool hasRowSpanningCell = false; nscoord bSizeOfRows = 0; @@ -1945,7 +1945,10 @@ bool nsTableRowGroupFrame::FrameCursorData::AppendFrame(nsIFrame* aFrame) { nscoord overflowBelow = overflowRect.YMost() - aFrame->GetSize().height; mOverflowAbove = std::max(mOverflowAbove, overflowAbove); mOverflowBelow = std::max(mOverflowBelow, overflowBelow); - return mFrames.AppendElement(aFrame) != nullptr; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mFrames.AppendElement(aFrame); + return true; } void nsTableRowGroupFrame::InvalidateFrame(uint32_t aDisplayItemKey, diff --git a/layout/xul/nsDocElementBoxFrame.cpp b/layout/xul/nsDocElementBoxFrame.cpp index 0776ba0b7898..c7faaf9559a8 100644 --- a/layout/xul/nsDocElementBoxFrame.cpp +++ b/layout/xul/nsDocElementBoxFrame.cpp @@ -98,8 +98,9 @@ nsresult nsDocElementBoxFrame::CreateAnonymousContent( nodeInfo.forget(), dom::NOT_FROM_PARSER); NS_ENSURE_SUCCESS(rv, rv); - if (!aElements.AppendElement(mPopupgroupContent)) - return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aElements.AppendElement(mPopupgroupContent); // create the top-secret default tooltip node. shhhhh! nodeInfo = nodeInfoManager->GetNodeInfo( @@ -113,7 +114,9 @@ nsresult nsDocElementBoxFrame::CreateAnonymousContent( mTooltipContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_default, NS_LITERAL_STRING("true"), false); - if (!aElements.AppendElement(mTooltipContent)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aElements.AppendElement(mTooltipContent); return NS_OK; } diff --git a/modules/libjar/zipwriter/nsZipWriter.cpp b/modules/libjar/zipwriter/nsZipWriter.cpp index 5dbd4e037a42..e129f64cbd36 100644 --- a/modules/libjar/zipwriter/nsZipWriter.cpp +++ b/modules/libjar/zipwriter/nsZipWriter.cpp @@ -289,7 +289,9 @@ NS_IMETHODIMP nsZipWriter::AddEntryDirectory(const nsACString& aZipEntry, item.mZipEntry = aZipEntry; item.mModTime = aModTime; item.mPermissions = PERMISSIONS_DIR; - if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mQueue.AppendElement(item); return NS_OK; } @@ -311,7 +313,9 @@ NS_IMETHODIMP nsZipWriter::AddEntryFile(const nsACString& aZipEntry, item.mCompression = aCompression; rv = aFile->Clone(getter_AddRefs(item.mFile)); NS_ENSURE_SUCCESS(rv, rv); - if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mQueue.AppendElement(item); return NS_OK; } @@ -365,7 +369,9 @@ NS_IMETHODIMP nsZipWriter::AddEntryChannel(const nsACString& aZipEntry, item.mCompression = aCompression; item.mPermissions = PERMISSIONS_FILE; item.mChannel = aChannel; - if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mQueue.AppendElement(item); return NS_OK; } @@ -408,7 +414,9 @@ nsresult nsZipWriter::AddEntryStream(const nsACString& aZipEntry, item.mCompression = aCompression; item.mPermissions = aPermissions; item.mStream = aStream; - if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mQueue.AppendElement(item); return NS_OK; } @@ -454,7 +462,9 @@ NS_IMETHODIMP nsZipWriter::RemoveEntry(const nsACString& aZipEntry, nsZipQueueItem item; item.mOperation = OPERATION_REMOVE; item.mZipEntry = aZipEntry; - if (!mQueue.AppendElement(item)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mQueue.AppendElement(item); return NS_OK; } diff --git a/netwerk/base/Dashboard.cpp b/netwerk/base/Dashboard.cpp index d31452bcfd78..1e2e59730c23 100644 --- a/netwerk/base/Dashboard.cpp +++ b/netwerk/base/Dashboard.cpp @@ -493,9 +493,9 @@ Dashboard::AddHost(const nsACString& aHost, uint32_t aSerial, bool aEncrypted) { if (mWs.data.Contains(mData)) { return NS_OK; } - if (!mWs.data.AppendElement(mData)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mWs.data.AppendElement(mData); return NS_OK; } return NS_ERROR_FAILURE; diff --git a/netwerk/base/nsLoadGroup.cpp b/netwerk/base/nsLoadGroup.cpp index 3a1034a1b252..d2429eade624 100644 --- a/netwerk/base/nsLoadGroup.cpp +++ b/netwerk/base/nsLoadGroup.cpp @@ -159,10 +159,9 @@ static bool AppendRequestsToArray(PLDHashTable* aTable, nsIRequest* request = e->mKey; NS_ASSERTION(request, "What? Null key in PLDHashTable entry?"); - bool ok = !!aArray->AppendElement(request); - if (!ok) { - break; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + aArray->AppendElement(request); NS_ADDREF(request); } diff --git a/netwerk/cache2/CacheIOThread.cpp b/netwerk/cache2/CacheIOThread.cpp index b6a24267b193..236e8853d312 100644 --- a/netwerk/cache2/CacheIOThread.cpp +++ b/netwerk/cache2/CacheIOThread.cpp @@ -562,9 +562,9 @@ void CacheIOThread::LoopOneLevel(uint32_t aLevel) { events.RemoveElementsAt(0, index); // Move events that might have been scheduled on this queue to the tail to // preserve the expected per-queue FIFO order. - if (!events.AppendElements(std::move(mEventQueue[aLevel]))) { - MOZ_CRASH("Can't allocate memory for cache IO thread queue"); - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + events.AppendElements(std::move(mEventQueue[aLevel])); // And finally move everything back to the main queue. events.SwapElements(mEventQueue[aLevel]); } diff --git a/netwerk/protocol/http/nsHttpActivityDistributor.cpp b/netwerk/protocol/http/nsHttpActivityDistributor.cpp index 7dcf55376d09..bceb6c8e45ed 100644 --- a/netwerk/protocol/http/nsHttpActivityDistributor.cpp +++ b/netwerk/protocol/http/nsHttpActivityDistributor.cpp @@ -144,7 +144,9 @@ nsHttpActivityDistributor::AddObserver(nsIHttpActivityObserver* aObserver) { { MutexAutoLock lock(mLock); wasEmpty = mObservers.IsEmpty(); - if (!mObservers.AppendElement(observer)) return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mObservers.AppendElement(observer); } if (nsIOService::UseSocketProcess() && wasEmpty) { diff --git a/netwerk/streamconv/nsStreamConverterService.cpp b/netwerk/streamconv/nsStreamConverterService.cpp index 3c6e3b0c4705..9f11bda8e896 100644 --- a/netwerk/streamconv/nsStreamConverterService.cpp +++ b/netwerk/streamconv/nsStreamConverterService.cpp @@ -139,7 +139,10 @@ nsresult nsStreamConverterService::AddAdjacency(const char* aContractID) { NS_ASSERTION(fromEdges, "something wrong in adjacency list construction"); if (!fromEdges) return NS_ERROR_FAILURE; - return fromEdges->AppendElement(vertex) ? NS_OK : NS_ERROR_FAILURE; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + fromEdges->AppendElement(vertex); + return NS_OK; } nsresult nsStreamConverterService::ParseFromTo(const char* aContractID, @@ -309,10 +312,9 @@ nsresult nsStreamConverterService::FindConverter( newContractID.Append(data->key); // Add this CONTRACTID to the chain. - rv = shortestPath->AppendElement(newContractID) - ? NS_OK - : NS_ERROR_FAILURE; // XXX this method incorrectly returns a bool - NS_ASSERTION(NS_SUCCEEDED(rv), "AppendElement failed"); + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + shortestPath->AppendElement(newContractID); // move up the tree. data = predecessorData; diff --git a/security/certverifier/NSSCertDBTrustDomain.cpp b/security/certverifier/NSSCertDBTrustDomain.cpp index 43df868f781b..3b1bf63e6aff 100644 --- a/security/certverifier/NSSCertDBTrustDomain.cpp +++ b/security/certverifier/NSSCertDBTrustDomain.cpp @@ -232,10 +232,10 @@ Result NSSCertDBTrustDomain::FindIssuer(Input encodedIssuerName, return Result::FATAL_ERROR_LIBRARY_FAILURE; } nsTArray subject; - if (!subject.AppendElements(encodedIssuerName.UnsafeGetData(), - encodedIssuerName.GetLength())) { - return Result::FATAL_ERROR_NO_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + subject.AppendElements(encodedIssuerName.UnsafeGetData(), + encodedIssuerName.GetLength()); nsTArray> certs; nsresult rv = mCertStorage->FindCertsBySubject(subject, certs); if (NS_FAILED(rv)) { diff --git a/security/manager/ssl/EnterpriseRoots.cpp b/security/manager/ssl/EnterpriseRoots.cpp index d62e3b02a8cd..e50c74928bfc 100644 --- a/security/manager/ssl/EnterpriseRoots.cpp +++ b/security/manager/ssl/EnterpriseRoots.cpp @@ -48,9 +48,9 @@ nsresult EnterpriseCert::Init(const EnterpriseCert& orig) { nsresult EnterpriseCert::CopyBytes(nsTArray& dest) const { dest.Clear(); - if (!dest.AppendElements(mDER.begin(), mDER.length())) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + dest.AppendElements(mDER.begin(), mDER.length()); return NS_OK; } diff --git a/security/manager/ssl/nsNSSComponent.cpp b/security/manager/ssl/nsNSSComponent.cpp index 65d05e99097b..fda2a2f632f0 100644 --- a/security/manager/ssl/nsNSSComponent.cpp +++ b/security/manager/ssl/nsNSSComponent.cpp @@ -581,9 +581,9 @@ nsresult nsNSSComponent::CommonGetEnterpriseCerts( if (NS_FAILED(rv)) { return rv; } - if (!enterpriseCerts.AppendElement(std::move(certCopy))) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + enterpriseCerts.AppendElement(std::move(certCopy)); } } return NS_OK; diff --git a/toolkit/components/places/Database.cpp b/toolkit/components/places/Database.cpp index 062b7f0075e6..2fe165aa2f03 100644 --- a/toolkit/components/places/Database.cpp +++ b/toolkit/components/places/Database.cpp @@ -2164,9 +2164,9 @@ nsresult Database::MigrateV50Up() { rv = stmt->GetUTF8String(1, url); if (NS_FAILED(rv)) return rv; - if (!placeURLs.AppendElement(std::make_pair(placeId, url))) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + placeURLs.AppendElement(std::make_pair(placeId, url)); } if (placeURLs.IsEmpty()) { @@ -2470,9 +2470,9 @@ nsresult Database::ConvertOldStyleQuery(nsCString& aURL) { const QueryKeyValuePair& kvp = tokens[j]; if (!kvp.key.EqualsLiteral("folder")) { - if (!newTokens.AppendElement(kvp)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + newTokens.AppendElement(kvp); continue; } @@ -2518,9 +2518,9 @@ nsresult Database::ConvertOldStyleQuery(nsCString& aURL) { } else { newPair = new QueryKeyValuePair(NS_LITERAL_CSTRING("parent"), guid); } - if (!newTokens.AppendElement(*newPair)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + newTokens.AppendElement(*newPair); delete newPair; } diff --git a/toolkit/components/places/Helpers.cpp b/toolkit/components/places/Helpers.cpp index eaa61f4e2ad2..179b4d964c1d 100644 --- a/toolkit/components/places/Helpers.cpp +++ b/toolkit/components/places/Helpers.cpp @@ -340,9 +340,10 @@ nsresult TokenizeQueryString(const nsACString& aQuery, if (query[i] == '&') { // new clause, save last one if (i - keyFirstIndex > 1) { - if (!aTokens->AppendElement( - QueryKeyValuePair(query, keyFirstIndex, equalsIndex, i))) - return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aTokens->AppendElement( + QueryKeyValuePair(query, keyFirstIndex, equalsIndex, i)); } keyFirstIndex = equalsIndex = i + 1; } else if (query[i] == '=') { @@ -352,9 +353,10 @@ nsresult TokenizeQueryString(const nsACString& aQuery, // handle last pair, if any if (query.Length() - keyFirstIndex > 1) { - if (!aTokens->AppendElement(QueryKeyValuePair(query, keyFirstIndex, - equalsIndex, query.Length()))) - return NS_ERROR_OUT_OF_MEMORY; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aTokens->AppendElement( + QueryKeyValuePair(query, keyFirstIndex, equalsIndex, query.Length())); } return NS_OK; } diff --git a/toolkit/components/places/nsNavHistoryQuery.cpp b/toolkit/components/places/nsNavHistoryQuery.cpp index 47ee5e2c354b..492aa6cac6ec 100644 --- a/toolkit/components/places/nsNavHistoryQuery.cpp +++ b/toolkit/components/places/nsNavHistoryQuery.cpp @@ -851,11 +851,9 @@ NS_IMETHODIMP nsNavHistoryQuery::SetTags(nsIVariant* aTags) { // Don't store duplicate tags. This isn't just to save memory or to be // fancy; the SQL that's built from the tags relies on no dupes. if (!mTags.Contains(tag)) { - if (!mTags.AppendElement(tag)) { - free(tags[i]); - free(tags); - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mTags.AppendElement(tag); } free(tags[i]); } diff --git a/toolkit/components/places/nsNavHistoryResult.cpp b/toolkit/components/places/nsNavHistoryResult.cpp index 0d4e6b32dad5..673683cbf08f 100644 --- a/toolkit/components/places/nsNavHistoryResult.cpp +++ b/toolkit/components/places/nsNavHistoryResult.cpp @@ -2719,9 +2719,9 @@ nsNavHistoryFolderResultNode::GetQuery(nsINavHistoryQuery** _query) { nsTArray parents; // query just has the folder ID set and nothing else - if (!parents.AppendElement(mTargetFolderGuid)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + parents.AppendElement(mTargetFolderGuid); nsresult rv = query->SetParents(parents); NS_ENSURE_SUCCESS(rv, rv); diff --git a/toolkit/components/telemetry/core/TelemetryHistogram.cpp b/toolkit/components/telemetry/core/TelemetryHistogram.cpp index 8d9386b7c958..30e2a64cb184 100644 --- a/toolkit/components/telemetry/core/TelemetryHistogram.cpp +++ b/toolkit/components/telemetry/core/TelemetryHistogram.cpp @@ -747,9 +747,9 @@ nsresult internal_GetHistogramAndSamples(const StaticMutexAutoLock& aLock, // Convert the ranges of the buckets to a nsTArray. const size_t bucketCount = h->bucket_count(); for (size_t i = 0; i < bucketCount; i++) { - if (!aSnapshot.mBucketRanges.AppendElement(h->ranges(i))) { - return NS_ERROR_FAILURE; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aSnapshot.mBucketRanges.AppendElement(h->ranges(i)); } // Get a snapshot of the samples. @@ -758,9 +758,9 @@ nsresult internal_GetHistogramAndSamples(const StaticMutexAutoLock& aLock, // Get the number of samples in each bucket. for (size_t i = 0; i < bucketCount; i++) { - if (!aSnapshot.mBucketCounts.AppendElement(ss.counts(i))) { - return NS_ERROR_FAILURE; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + aSnapshot.mBucketCounts.AppendElement(ss.counts(i)); } // Finally, save the |sum|. We don't need to reflect declared_min, diff --git a/toolkit/components/windowwatcher/nsWindowWatcher.cpp b/toolkit/components/windowwatcher/nsWindowWatcher.cpp index 2f6825bd0b40..faa9e4811252 100644 --- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp +++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp @@ -1617,7 +1617,10 @@ nsWindowWatcher::GetWindowByName(const nsAString& aTargetName, bool nsWindowWatcher::AddEnumerator(nsWatcherWindowEnumerator* aEnumerator) { // (requires a lock; assumes it's called by someone holding the lock) - return mEnumeratorList.AppendElement(aEnumerator) != nullptr; + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier, or change the return type to void. + mEnumeratorList.AppendElement(aEnumerator); + return true; } bool nsWindowWatcher::RemoveEnumerator(nsWatcherWindowEnumerator* aEnumerator) { diff --git a/toolkit/system/gnome/nsGIOService.cpp b/toolkit/system/gnome/nsGIOService.cpp index 3ecc676170c2..c558c3c3760a 100644 --- a/toolkit/system/gnome/nsGIOService.cpp +++ b/toolkit/system/gnome/nsGIOService.cpp @@ -298,9 +298,9 @@ nsGIOMimeApp::GetSupportedURISchemes(nsIUTF8StringEnumerator** aSchemes) { const gchar* const* uri_schemes = g_vfs_get_supported_uri_schemes(gvfs); while (*uri_schemes != nullptr) { - if (!array->mStrings.AppendElement(*uri_schemes)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + array->mStrings.AppendElement(*uri_schemes); uri_schemes++; } diff --git a/toolkit/system/osxproxy/ProxyUtils.mm b/toolkit/system/osxproxy/ProxyUtils.mm index fed145f21010..cade1c5faeea 100644 --- a/toolkit/system/osxproxy/ProxyUtils.mm +++ b/toolkit/system/osxproxy/ProxyUtils.mm @@ -16,11 +16,9 @@ * Normalize the short IP form into the complete form. * For example, it converts "192.168" into "192.168.0.0" */ -static bool NormalizeAddr(const nsACString& aAddr, nsCString& aNormalized) { +static void NormalizeAddr(const nsACString& aAddr, nsCString& aNormalized) { nsTArray addr; - if (!ParseString(aAddr, '.', addr)) { - return false; - } + ParseString(aAddr, '.', addr); aNormalized = ""; for (uint32_t i = 0; i < 4; ++i) { if (i != 0) { @@ -32,7 +30,6 @@ static bool NormalizeAddr(const nsACString& aAddr, nsCString& aNormalized) { aNormalized.AppendLiteral("0"); } } - return true; } static PRUint32 MaskIPv4Addr(PRUint32 aAddr, uint16_t aMaskLen) { @@ -81,9 +78,7 @@ static bool IsMatchMask(const nsACString& aHost, const nsACString& aOverride) { } nsAutoCString override(aOverride); - if (!NormalizeAddr(Substring(aOverride, 0, tokenEnd), override)) { - return false; - } + NormalizeAddr(Substring(aOverride, 0, tokenEnd), override); PRNetAddr prAddrHost; PRNetAddr prAddrOverride; diff --git a/toolkit/system/windowsproxy/ProxyUtils.cpp b/toolkit/system/windowsproxy/ProxyUtils.cpp index 9f62e9a80401..8ad81529eb66 100644 --- a/toolkit/system/windowsproxy/ProxyUtils.cpp +++ b/toolkit/system/windowsproxy/ProxyUtils.cpp @@ -16,11 +16,9 @@ namespace system { * Normalize the short IP form into the complete form. * For example, it converts "192.168" into "192.168.0.0" */ -static bool NormalizeAddr(const nsACString& aAddr, nsCString& aNormalized) { +static void NormalizeAddr(const nsACString& aAddr, nsCString& aNormalized) { nsTArray addr; - if (!ParseString(aAddr, '.', addr)) { - return false; - } + ParseString(aAddr, '.', addr); aNormalized = ""; for (uint32_t i = 0; i < 4; ++i) { if (i != 0) { @@ -32,7 +30,6 @@ static bool NormalizeAddr(const nsACString& aAddr, nsCString& aNormalized) { aNormalized.AppendLiteral("0"); } } - return true; } static PRUint32 MaskIPv4Addr(PRUint32 aAddr, uint16_t aMaskLen) { @@ -86,9 +83,7 @@ static bool IsMatchMask(const nsACString& aHost, const nsACString& aOverride) { } nsAutoCString override(aOverride); - if (!NormalizeAddr(Substring(aOverride, 0, tokenEnd), override)) { - return false; - } + NormalizeAddr(Substring(aOverride, 0, tokenEnd), override); PRNetAddr prAddrHost; PRNetAddr prAddrOverride; diff --git a/widget/nsIdleService.cpp b/widget/nsIdleService.cpp index 1751fbdc7162..25329c59ba6f 100644 --- a/widget/nsIdleService.cpp +++ b/widget/nsIdleService.cpp @@ -419,9 +419,9 @@ nsIdleService::AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS) { // Put the time + observer in a struct we can keep: IdleListener listener(aObserver, aIdleTimeInS); - if (!mArrayListeners.AppendElement(listener)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mArrayListeners.AppendElement(listener); // Create our timer callback if it's not there already. if (!mTimer) { diff --git a/widget/nsNativeTheme.cpp b/widget/nsNativeTheme.cpp index b0a6a83992be..d1345419916f 100644 --- a/widget/nsNativeTheme.cpp +++ b/widget/nsNativeTheme.cpp @@ -557,10 +557,9 @@ bool nsNativeTheme::QueueAnimatedContentForRefresh(nsIContent* aContent, mAnimatedContentTimeout = timeout; } - if (!mAnimatedContentList.AppendElement(aContent)) { - NS_WARNING("Out of memory!"); - return false; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + mAnimatedContentList.AppendElement(aContent); return true; } diff --git a/widget/windows/WindowHook.cpp b/widget/windows/WindowHook.cpp index a0e0ada81d40..06773f21b75d 100644 --- a/widget/windows/WindowHook.cpp +++ b/widget/windows/WindowHook.cpp @@ -37,7 +37,8 @@ nsresult WindowHook::RemoveHook(UINT nMsg, Callback callback, void* context) { nsresult WindowHook::AddMonitor(UINT nMsg, Callback callback, void* context) { MessageData* data = LookupOrCreate(nMsg); - return (data && data->monitors.AppendElement(CallbackData(callback, context))) + return (data && data->monitors.AppendElement(CallbackData(callback, context), + fallible)) ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } diff --git a/xpcom/ds/nsExpirationTracker.h b/xpcom/ds/nsExpirationTracker.h index 9167e2b9f82a..c82ee1412bd0 100644 --- a/xpcom/ds/nsExpirationTracker.h +++ b/xpcom/ds/nsExpirationTracker.h @@ -162,9 +162,9 @@ class ExpirationTrackerImpl { return rv; } } - if (!generation.AppendElement(aObj)) { - return NS_ERROR_OUT_OF_MEMORY; - } + // XXX(Bug 1631371) Check if this should use a fallible operation as it + // pretended earlier. + generation.AppendElement(aObj); state->mGeneration = mNewestGeneration; state->mIndexInGeneration = index; return NS_OK; diff --git a/xpcom/ds/nsTArray.h b/xpcom/ds/nsTArray.h index 44c49e4e15e9..9c9288284fe3 100644 --- a/xpcom/ds/nsTArray.h +++ b/xpcom/ds/nsTArray.h @@ -317,7 +317,21 @@ class nsTArray_CopyEnabler { nsTArray_CopyEnabler() = default; nsTArray_CopyEnabler(const nsTArray_CopyEnabler& aOther) { - static_cast(this)->AppendElements(static_cast(aOther)); + /// XXX Bug 1628692 will make FallibleTArray uncopyable. The Fallible + /// variant should be removed then again. + if constexpr (std::is_same_v) { + auto res = static_cast(this)->AppendElements( + static_cast(aOther), mozilla::fallible); +#ifdef DEBUG + MOZ_ASSERT(res); +#else + (void)res; +#endif + } else { + static_cast(this)->template AppendElementsInternal( + static_cast(aOther).Elements(), + static_cast(aOther).Length()); + } } nsTArray_CopyEnabler& operator=(const nsTArray_CopyEnabler& aOther) { @@ -1122,9 +1136,6 @@ class nsTArray_Impl // |const nsTArray_Impl&|. nsTArray_Impl(const nsTArray_Impl&) = default; - explicit nsTArray_Impl(std::initializer_list aIL) { - AppendElements(aIL.begin(), aIL.size()); - } // Allow converting to a const array with a different kind of allocator, // Since the allocator doesn't matter for const arrays template @@ -1737,64 +1748,52 @@ class nsTArray_Impl return InsertElementSorted(std::forward(aItem)); } + private: + template + elem_type* AppendElementsInternal(const Item* aArray, size_type aArrayLen); + // This method appends elements to the end of this array. // @param aArray The elements to append to this array. // @param aArrayLen The number of elements to append to this array. // @return A pointer to the new elements in the array, or null if // the operation failed due to insufficient memory. - protected: - template - elem_type* AppendElements(const Item* aArray, size_type aArrayLen); - - template - elem_type* AppendElements(mozilla::Span aSpan) { - return AppendElements(aSpan.Elements(), aSpan.Length()); - } - public: template /* [[nodiscard]] */ elem_type* AppendElements(const Item* aArray, size_type aArrayLen, const mozilla::fallible_t&) { - return AppendElements(aArray, aArrayLen); + return AppendElementsInternal(aArray, aArrayLen); } template /* [[nodiscard]] */ elem_type* AppendElements(mozilla::Span aSpan, const mozilla::fallible_t&) { - return AppendElements(aSpan.Elements(), - aSpan.Length()); + return AppendElementsInternal(aSpan.Elements(), + aSpan.Length()); } // A variation on the AppendElements method defined above. - protected: - template - elem_type* AppendElements(const nsTArray_Impl& aArray) { - return AppendElements(aArray.Elements(), - aArray.Length()); - } - - public: template /* [[nodiscard]] */ elem_type* AppendElements(const nsTArray_Impl& aArray, const mozilla::fallible_t&) { - return AppendElements(aArray); + return AppendElementsInternal(aArray.Elements(), + aArray.Length()); } + private: + template + elem_type* AppendElementsInternal(nsTArray_Impl&& aArray); + // Move all elements from another array to the end of this array. // @return A pointer to the newly appended elements, or null on OOM. - protected: - template - elem_type* AppendElements(nsTArray_Impl&& aArray); - public: - template + template /* [[nodiscard]] */ elem_type* AppendElements(nsTArray_Impl&& aArray, const mozilla::fallible_t&) { - return AppendElements(std::move(aArray)); + return AppendElementsInternal(std::move(aArray)); } // Append a new element, constructed in place from the provided arguments. @@ -1810,24 +1809,21 @@ class nsTArray_Impl std::forward(aArgs)...); } - // Append a new element, move constructing if possible. - protected: - template - elem_type* AppendElement(Item&& aItem); + private: + template + elem_type* AppendElementInternal(Item&& aItem); + // Append a new element, move constructing if possible. public: template /* [[nodiscard]] */ elem_type* AppendElement(Item&& aItem, const mozilla::fallible_t&) { - return AppendElement(std::forward(aItem)); + return AppendElementInternal(std::forward(aItem)); } - // Append new elements without copy-constructing. This is useful to avoid - // temporaries. - // @return A pointer to the newly appended elements, or null on OOM. - protected: - template - elem_type* AppendElements(size_type aCount) { + private: + template + elem_type* AppendElementsInternal(size_type aCount) { if (!ActualAlloc::Successful(this->template ExtendCapacity( Length(), aCount, sizeof(elem_type)))) { return nullptr; @@ -1841,25 +1837,23 @@ class nsTArray_Impl return elems; } + // Append new elements without copy-constructing. This is useful to avoid + // temporaries. + // @return A pointer to the newly appended elements, or null on OOM. public: /* [[nodiscard]] */ elem_type* AppendElements(size_type aCount, const mozilla::fallible_t&) { - return AppendElements(aCount); + return AppendElementsInternal(aCount); } + private: // Append a new element without copy-constructing. This is useful to avoid // temporaries. // @return A pointer to the newly appended element, or null on OOM. - protected: - template - elem_type* AppendElement() { - return AppendElements(1); - } - public: /* [[nodiscard]] */ elem_type* AppendElement(const mozilla::fallible_t&) { - return AppendElement(); + return AppendElements(1, mozilla::fallible); } // This method removes a single element from this array, like @@ -2573,9 +2567,9 @@ auto nsTArray_Impl::InsertElementAtInternal(index_type aIndex, } template -template -auto nsTArray_Impl::AppendElements(const Item* aArray, - size_type aArrayLen) +template +auto nsTArray_Impl::AppendElementsInternal(const Item* aArray, + size_type aArrayLen) -> elem_type* { if (!ActualAlloc::Successful(this->template ExtendCapacity( Length(), aArrayLen, sizeof(elem_type)))) { @@ -2588,8 +2582,8 @@ auto nsTArray_Impl::AppendElements(const Item* aArray, } template -template -auto nsTArray_Impl::AppendElements( +template +auto nsTArray_Impl::AppendElementsInternal( nsTArray_Impl&& aArray) -> elem_type* { if constexpr (std::is_same_v) { MOZ_ASSERT(&aArray != this, "argument must be different aArray"); @@ -2614,8 +2608,9 @@ auto nsTArray_Impl::AppendElements( } template -template -auto nsTArray_Impl::AppendElement(Item&& aItem) -> elem_type* { +template +auto nsTArray_Impl::AppendElementInternal(Item&& aItem) + -> elem_type* { // Length() + 1 is guaranteed to not overflow, so EnsureCapacity is OK. if (!ActualAlloc::Successful(this->template EnsureCapacity( Length() + 1, sizeof(elem_type)))) { @@ -2674,7 +2669,9 @@ class nsTArray : public nsTArray_Impl { nsTArray() {} explicit nsTArray(size_type aCapacity) : base_type(aCapacity) {} - MOZ_IMPLICIT nsTArray(std::initializer_list aIL) : base_type(aIL) {} + MOZ_IMPLICIT nsTArray(std::initializer_list aIL) { + AppendElements(aIL.begin(), aIL.size()); + } template explicit nsTArray(const nsTArray_Impl& aOther) @@ -2705,6 +2702,47 @@ class nsTArray : public nsTArray_Impl { using base_type::SetCapacity; using base_type::SetLength; + template + MOZ_NONNULL_RETURN elem_type* AppendElements(const Item* aArray, + size_type aArrayLen) { + return this->template AppendElementsInternal(aArray, + aArrayLen); + } + + template + MOZ_NONNULL_RETURN elem_type* AppendElements(mozilla::Span aSpan) { + return this->template AppendElementsInternal( + aSpan.Elements(), aSpan.Length()); + } + + template + MOZ_NONNULL_RETURN elem_type* AppendElements( + const nsTArray_Impl& aArray) { + return this->template AppendElementsInternal( + aArray.Elements(), aArray.Length()); + } + + template + MOZ_NONNULL_RETURN elem_type* AppendElements( + nsTArray_Impl&& aArray) { + return this->template AppendElementsInternal( + std::move(aArray)); + } + + template + MOZ_NONNULL_RETURN elem_type* AppendElement(Item&& aItem) { + return this->template AppendElementInternal( + std::forward(aItem)); + } + + MOZ_NONNULL_RETURN elem_type* AppendElements(size_type aCount) { + return this->template AppendElementsInternal(aCount); + } + + MOZ_NONNULL_RETURN elem_type* AppendElement() { + return this->template AppendElementsInternal(1); + } + template MOZ_NONNULL_RETURN elem_type* InsertElementsAt(index_type aIndex, const Item* aArray, diff --git a/xpcom/string/nsReadableUtils.cpp b/xpcom/string/nsReadableUtils.cpp index 62aa3d12788a..1d6d1cdae199 100644 --- a/xpcom/string/nsReadableUtils.cpp +++ b/xpcom/string/nsReadableUtils.cpp @@ -209,23 +209,18 @@ void ToLowerCase(const nsACString& aSource, nsACString& aDest) { } } -bool ParseString(const nsACString& aSource, char aDelimiter, +void ParseString(const nsACString& aSource, char aDelimiter, nsTArray& aArray) { nsACString::const_iterator start, end; aSource.BeginReading(start); aSource.EndReading(end); - uint32_t oldLength = aArray.Length(); - for (;;) { nsACString::const_iterator delimiter = start; FindCharInReadable(aDelimiter, delimiter, end); if (delimiter != start) { - if (!aArray.AppendElement(Substring(start, delimiter))) { - aArray.RemoveElementsAt(oldLength, aArray.Length() - oldLength); - return false; - } + aArray.AppendElement(Substring(start, delimiter)); } if (delimiter == end) { @@ -236,8 +231,6 @@ bool ParseString(const nsACString& aSource, char aDelimiter, break; } } - - return true; } template diff --git a/xpcom/string/nsReadableUtils.h b/xpcom/string/nsReadableUtils.h index 6c392383e36e..e4a8b6f8cc69 100644 --- a/xpcom/string/nsReadableUtils.h +++ b/xpcom/string/nsReadableUtils.h @@ -401,7 +401,7 @@ char16_t* CopyUnicodeTo(const nsAString& aSource, uint32_t aSrcOffset, return true; } -bool ParseString(const nsACString& aAstring, char aDelimiter, +void ParseString(const nsACString& aSource, char aDelimiter, nsTArray& aArray); /** diff --git a/xpcom/tests/gtest/TestStrings.cpp b/xpcom/tests/gtest/TestStrings.cpp index a95941a5df1b..47cb78d18792 100644 --- a/xpcom/tests/gtest/TestStrings.cpp +++ b/xpcom/tests/gtest/TestStrings.cpp @@ -1287,7 +1287,7 @@ static void test_parse_string_helper(const char* str, char separator, int len, const char* s1, const char* s2) { nsCString data(str); nsTArray results; - EXPECT_TRUE(ParseString(data, separator, results)); + ParseString(data, separator, results); EXPECT_EQ(int(results.Length()), len); const char* strings[] = {s1, s2}; for (int i = 0; i < len; ++i) { diff --git a/xpcom/tests/gtest/TestTArray2.cpp b/xpcom/tests/gtest/TestTArray2.cpp index aa2b0000e153..60132849fe90 100644 --- a/xpcom/tests/gtest/TestTArray2.cpp +++ b/xpcom/tests/gtest/TestTArray2.cpp @@ -148,7 +148,7 @@ static bool test_basic_array(ElementType* data, size_t dataLen, for (i = 0; i < copy.Length(); ++i) { if (ary[i] != copy[i]) return false; } - if (!ary.AppendElements(copy)) return false; + ary.AppendElements(copy); size_t cap = ary.Capacity(); ary.RemoveElementsAt(copy.Length(), copy.Length()); ary.Compact(); diff --git a/xpfe/appshell/nsWindowMediator.cpp b/xpfe/appshell/nsWindowMediator.cpp index 32c958901d06..1e59688c471f 100644 --- a/xpfe/appshell/nsWindowMediator.cpp +++ b/xpfe/appshell/nsWindowMediator.cpp @@ -199,9 +199,8 @@ nsWindowMediator::GetZOrderAppWindowEnumerator(const char16_t* aWindowType, return NS_OK; } -int32_t nsWindowMediator::AddEnumerator( - nsAppShellWindowEnumerator* inEnumerator) { - return mEnumeratorList.AppendElement(inEnumerator) != nullptr; +void nsWindowMediator::AddEnumerator(nsAppShellWindowEnumerator* inEnumerator) { + mEnumeratorList.AppendElement(inEnumerator); } int32_t nsWindowMediator::RemoveEnumerator( diff --git a/xpfe/appshell/nsWindowMediator.h b/xpfe/appshell/nsWindowMediator.h index 32ea5f9be638..9b2c7506613e 100644 --- a/xpfe/appshell/nsWindowMediator.h +++ b/xpfe/appshell/nsWindowMediator.h @@ -47,7 +47,7 @@ class nsWindowMediator : public nsIWindowMediator, nsCOMPtr& outDOMWindow); private: - int32_t AddEnumerator(nsAppShellWindowEnumerator* inEnumerator); + void AddEnumerator(nsAppShellWindowEnumerator* inEnumerator); int32_t RemoveEnumerator(nsAppShellWindowEnumerator* inEnumerator); nsWindowInfo* MostRecentWindowInfo(const char16_t* inType, bool aSkipPrivateBrowsingOrClosed = false);