Skip to content

Commit

Permalink
Bug 1628715 - Part 7: Add MOZ_NONNULL_RETURN to infallible nsTArray::…
Browse files Browse the repository at this point in the history
…AppendElements. r=xpcom-reviewers,necko-reviewers,nika,valentin

Differential Revision: https://phabricator.services.mozilla.com/D70831
  • Loading branch information
sigiesec committed Apr 24, 2020
1 parent 2ffb8d0 commit 41e8ccb
Show file tree
Hide file tree
Showing 82 changed files with 477 additions and 378 deletions.
4 changes: 3 additions & 1 deletion accessible/base/EventQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 18 additions & 4 deletions accessible/base/NotificationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -234,8 +237,12 @@ class NotificationController final : public EventQueue,

RefPtr<Notification> notification =
new TNotification<Class, Args...>(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();
}
}

/**
Expand All @@ -249,8 +256,12 @@ class NotificationController final : public EventQueue,
Class* aInstance, typename TNotification<Class>::Callback aMethod) {
RefPtr<Notification> notification =
new TNotification<Class>(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 <class Class, class Arg>
Expand All @@ -259,7 +270,10 @@ class NotificationController final : public EventQueue,
Arg* aArg) {
RefPtr<Notification> notification =
new TNotification<Class, Arg>(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();
}
}
Expand Down
5 changes: 3 additions & 2 deletions accessible/generic/Accessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion accessible/generic/DocAccessible.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion docshell/base/nsDocShellEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
7 changes: 3 additions & 4 deletions dom/base/CustomElementRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
8 changes: 5 additions & 3 deletions dom/base/DOMStringList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
11 changes: 6 additions & 5 deletions dom/base/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions dom/base/nsAttrValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down
24 changes: 15 additions & 9 deletions dom/base/nsLineBreaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ static void SetupCapitalization(const char16_t* aWord, uint32_t aLength,
nsresult nsLineBreaker::FlushCurrentWord() {
uint32_t length = mCurrentWord.Length();
AutoTArray<uint8_t, 4000> 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<bool> capitalizationState;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -192,14 +193,17 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage,

AutoTArray<uint8_t, 4000> 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<bool> 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;
}
Expand Down Expand Up @@ -370,7 +374,9 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage,

AutoTArray<uint8_t, 4000> 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;
Expand Down
6 changes: 2 additions & 4 deletions dom/console/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2919,10 +2919,8 @@ bool Console::ArgumentData::Initialize(JSContext* aCx,
const Sequence<JS::Value>& 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;
Expand Down
23 changes: 11 additions & 12 deletions dom/html/HTMLFormControlsCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,21 @@ 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
if (notInElementsIdx == notInElementsLen) {
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.
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion dom/media/MediaCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion dom/media/MediaStreamTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ void MediaStreamTrack::NotifyEnabledChanged() {

bool MediaStreamTrack::AddPrincipalChangeObserver(
PrincipalChangeObserver<MediaStreamTrack>* 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(
Expand Down
6 changes: 3 additions & 3 deletions dom/media/platforms/agnostic/bytestreams/AnnexB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions dom/plugins/base/nsNPAPIPluginInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion dom/script/ScriptLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 41e8ccb

Please sign in to comment.