From 2d8c4390b76accbfc15a5b71635c9d7931aaf7b0 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Fri, 24 Apr 2020 13:35:27 +0000 Subject: [PATCH] Bug 1628715 - Part 15: Replace MOZ_NONNULL_RETURN by returning NotNull. r=xpcom-reviewers,necko-reviewers,dragana,nika Differential Revision: https://phabricator.services.mozilla.com/D71300 --- docshell/base/BrowsingContext.cpp | 2 +- dom/base/Document.cpp | 4 +- dom/indexedDB/ActorsParent.cpp | 35 ++- dom/ipc/JSWindowActorService.cpp | 6 +- dom/vr/XRSession.cpp | 4 +- gfx/vr/ipc/VRManagerChild.cpp | 4 +- layout/generic/nsGridContainerFrame.cpp | 2 +- layout/printing/nsPrintJob.cpp | 4 +- layout/tables/nsCellMap.cpp | 17 +- mfbt/PodOperations.h | 9 + netwerk/base/nsFileStreams.cpp | 2 +- storage/StorageBaseStatementInternal.cpp | 2 +- storage/mozStorageBindingParams.cpp | 6 +- storage/mozStorageBindingParamsArray.cpp | 2 +- storage/mozStorageConnection.cpp | 2 +- toolkit/components/places/History.cpp | 3 +- toolkit/components/places/nsNavBookmarks.cpp | 2 +- .../components/places/nsNavHistoryQuery.cpp | 7 +- .../reputationservice/LoginReputation.cpp | 2 +- xpcom/ds/nsTArray.h | 214 ++++++++++-------- xpcom/tests/gtest/TestTArray2.cpp | 12 +- 21 files changed, 179 insertions(+), 162 deletions(-) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 0193a443839a..1e02bb12fffe 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -673,7 +673,7 @@ bool BrowsingContext::HasOpener() const { } void BrowsingContext::GetChildren(Children& aChildren) { - MOZ_ALWAYS_TRUE(aChildren.AppendElements(mChildren)); + aChildren.AppendElements(mChildren); } void BrowsingContext::GetWindowContexts( diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 4cf9ec89be17..f4323de2de36 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -12062,9 +12062,7 @@ nsresult Document::ScheduleFrameRequestCallback(FrameRequestCallback& aCallback, } int32_t newHandle = ++mFrameRequestCallbackCounter; - DebugOnly request = - mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle)); - NS_ASSERTION(request, "This is supposed to be infallible!"); + mFrameRequestCallbacks.AppendElement(FrameRequest(aCallback, newHandle)); UpdateFrameRequestCallbackSchedulingState(); *aHandle = newHandle; diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index a0a1bedc5c98..5419c094b9b8 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -10025,14 +10025,14 @@ struct CommonPopulateResponseHelper { } template - void FillKeys(Response* const aResponse) { + void FillKeys(Response& aResponse) { MOZ_ASSERT(!mPosition.IsUnset()); - aResponse->key() = std::move(mPosition); + aResponse.key() = std::move(mPosition); } template - static size_t GetKeySize(const Response* const aResponse) { - return aResponse->key().GetBuffer().Length(); + static size_t GetKeySize(const Response& aResponse) { + return aResponse.key().GetBuffer().Length(); } protected: @@ -10075,20 +10075,20 @@ struct IndexPopulateResponseHelper : CommonPopulateResponseHelper { } template - void FillKeys(Response* const aResponse) { + void FillKeys(Response& aResponse) { MOZ_ASSERT(!mLocaleAwarePosition.IsUnset()); MOZ_ASSERT(!mObjectStorePosition.IsUnset()); CommonPopulateResponseHelper::FillKeys(aResponse); - aResponse->sortKey() = std::move(mLocaleAwarePosition); - aResponse->objectKey() = std::move(mObjectStorePosition); + aResponse.sortKey() = std::move(mLocaleAwarePosition); + aResponse.objectKey() = std::move(mObjectStorePosition); } template - static size_t GetKeySize(const Response* const aResponse) { + static size_t GetKeySize(Response& aResponse) { return CommonPopulateResponseHelper::GetKeySize(aResponse) + - aResponse->sortKey().GetBuffer().Length() + - aResponse->objectKey().GetBuffer().Length(); + aResponse.sortKey().GetBuffer().Length() + + aResponse.objectKey().GetBuffer().Length(); } private: @@ -10102,12 +10102,11 @@ struct KeyPopulateResponseHelper { } template - static constexpr void MaybeFillCloneInfo(Response* const /*aResponse*/, + static constexpr void MaybeFillCloneInfo(Response& /*aResponse*/, FilesArray* const /*aFiles*/) {} template - static constexpr size_t MaybeGetCloneInfoSize( - const Response* const /*aResponse*/) { + static constexpr size_t MaybeGetCloneInfoSize(const Response& /*aResponse*/) { return 0; } }; @@ -10138,15 +10137,15 @@ struct ValuePopulateResponseHelper { } template - void MaybeFillCloneInfo(Response* const aResponse, FilesArray* const aFiles) { + void MaybeFillCloneInfo(Response& aResponse, FilesArray* const aFiles) { auto cloneInfo = mCloneInfo.release(); - aResponse->cloneInfo().data().data = cloneInfo.ReleaseData(); + aResponse.cloneInfo().data().data = cloneInfo.ReleaseData(); aFiles->AppendElement(cloneInfo.ReleaseFiles()); } template - static size_t MaybeGetCloneInfoSize(const Response* const aResponse) { - return aResponse->cloneInfo().data().data.Size(); + static size_t MaybeGetCloneInfoSize(const Response& aResponse) { + return aResponse.cloneInfo().data().data.Size(); } private: @@ -26744,7 +26743,7 @@ CursorOpBaseHelperBase::PopulateResponseFromStatement( } auto& responses = populateResponseHelper.GetTypedResponse(&mOp.mResponse); - auto* response = responses.AppendElement(); + auto& response = *responses.AppendElement(); populateResponseHelper.FillKeys(response); if constexpr (!CursorTypeTraits::IsKeyOnlyCursor) { diff --git a/dom/ipc/JSWindowActorService.cpp b/dom/ipc/JSWindowActorService.cpp index 0f1f203a99d0..3a653b2f13db 100644 --- a/dom/ipc/JSWindowActorService.cpp +++ b/dom/ipc/JSWindowActorService.cpp @@ -52,7 +52,7 @@ JSWindowActorProtocol::FromIPC(const JSWindowActorInfo& aInfo) { proto->mChild.mEvents.SetCapacity(aInfo.events().Length()); for (auto& ipc : aInfo.events()) { - auto* event = proto->mChild.mEvents.AppendElement(); + auto event = proto->mChild.mEvents.AppendElement(); event->mName.Assign(ipc.name()); event->mFlags.mCapture = ipc.capture(); event->mFlags.mInSystemGroup = ipc.systemGroup(); @@ -79,7 +79,7 @@ JSWindowActorInfo JSWindowActorProtocol::ToIPC() { info.events().SetCapacity(mChild.mEvents.Length()); for (auto& event : mChild.mEvents) { - auto* ipc = info.events().AppendElement(); + auto ipc = info.events().AppendElement(); ipc->name().Assign(event.mName); ipc->capture() = event.mFlags.mCapture; ipc->systemGroup() = event.mFlags.mInSystemGroup; @@ -312,7 +312,7 @@ extensions::MatchPatternSet* JSWindowActorProtocol::GetURIMatcher() { nsTArray patterns; patterns.SetCapacity(mMatches.Length()); for (nsString& s : mMatches) { - auto* entry = patterns.AppendElement(); + auto entry = patterns.AppendElement(); entry->SetAsString() = s; } diff --git a/dom/vr/XRSession.cpp b/dom/vr/XRSession.cpp index 835b750fa928..f70b67a4d93f 100644 --- a/dom/vr/XRSession.cpp +++ b/dom/vr/XRSession.cpp @@ -381,9 +381,7 @@ int32_t XRSession::RequestAnimationFrame(XRFrameRequestCallback& aCallback, int32_t handle = ++mFrameRequestCallbackCounter; - DebugOnly request = - mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, handle)); - NS_ASSERTION(request, "This is supposed to be infallible!"); + mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, handle)); return handle; } diff --git a/gfx/vr/ipc/VRManagerChild.cpp b/gfx/vr/ipc/VRManagerChild.cpp index 1dea74dd936c..8395f66a030c 100644 --- a/gfx/vr/ipc/VRManagerChild.cpp +++ b/gfx/vr/ipc/VRManagerChild.cpp @@ -389,9 +389,7 @@ nsresult VRManagerChild::ScheduleFrameRequestCallback( } int32_t newHandle = ++mFrameRequestCallbackCounter; - DebugOnly request = mFrameRequestCallbacks.AppendElement( - XRFrameRequest(aCallback, newHandle)); - NS_ASSERTION(request, "This is supposed to be infallible!"); + mFrameRequestCallbacks.AppendElement(XRFrameRequest(aCallback, newHandle)); *aHandle = newHandle; return NS_OK; diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index cb83894cbf54..f6f046964a33 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -2659,7 +2659,7 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::GridReflowInput { uint32_t offsetInOppositeAxis = aRangeInOppositeAxis.mStart; uint32_t gridEndInOppositeAxis = aRangeInOppositeAxis.Extent(); for (const auto& subgridItem : aItems) { - auto* newItem = aResult.AppendElement( + auto newItem = aResult.AppendElement( isOrthogonal ? subgridItem.Transpose() : subgridItem); if (MOZ_UNLIKELY(!isSameDirInAxis)) { newItem->ReverseDirection(aAxis, gridEndInAxis); diff --git a/layout/printing/nsPrintJob.cpp b/layout/printing/nsPrintJob.cpp index aa26076a1675..4c7ab0432247 100644 --- a/layout/printing/nsPrintJob.cpp +++ b/layout/printing/nsPrintJob.cpp @@ -783,9 +783,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview, aIsPrintPreview); NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE( - printData->mPrintDocList.AppendElement(printData->mPrintObject.get()), - NS_ERROR_OUT_OF_MEMORY); + printData->mPrintDocList.AppendElement(printData->mPrintObject.get()); printData->mIsParentAFrameSet = IsParentAFrameSet(docShell); printData->mPrintObject->mFrameType = diff --git a/layout/tables/nsCellMap.cpp b/layout/tables/nsCellMap.cpp index 448b5122556e..2de4edc7768e 100644 --- a/layout/tables/nsCellMap.cpp +++ b/layout/tables/nsCellMap.cpp @@ -1174,7 +1174,10 @@ bool nsCellMap::Grow(nsTableCellMap& aMap, int32_t aNumRows, uint32_t startRowIndex = (aRowIndex >= 0) ? aRowIndex : mRows.Length(); NS_ASSERTION(startRowIndex <= mRows.Length(), "Missing grow call inbetween"); - return mRows.InsertElementsAt(startRowIndex, aNumRows, numCols) != nullptr; + // XXX Change the return type of this function to void, or use a fallible + // operation. + mRows.InsertElementsAt(startRowIndex, aNumRows, numCols); + return true; } void nsCellMap::GrowRow(CellDataArray& aRow, int32_t aNumCols) @@ -1642,16 +1645,8 @@ void nsCellMap::ExpandWithCells(nsTableCellMap& aMap, if (insertionIndex > startColIndex) { insertionIndex = startColIndex; } - if (!row.InsertElementsAt(insertionIndex, - endColIndex - insertionIndex + 1, - (CellData*)nullptr) && - rowX == aRowIndex) { - // Failed to insert the slots, and this is the very first row. That - // means that we need to clean up |origData| before returning, since - // the cellmap doesn't own it yet. - DestroyCellData(origData); - return; - } + row.InsertElementsAt(insertionIndex, endColIndex - insertionIndex + 1, + (CellData*)nullptr); for (int32_t colX = startColIndex; colX <= endColIndex; colX++) { CellData* data = origData; diff --git a/mfbt/PodOperations.h b/mfbt/PodOperations.h index 433637c4f5ba..c76e1b2557c0 100644 --- a/mfbt/PodOperations.h +++ b/mfbt/PodOperations.h @@ -25,6 +25,9 @@ namespace mozilla { +template +class NotNull; + /** Set the contents of |aT| to 0. */ template static MOZ_ALWAYS_INLINE void PodZero(T* aT) { @@ -44,6 +47,12 @@ static MOZ_ALWAYS_INLINE void PodZero(T* aT, size_t aNElem) { } } +/** Set the contents of |aNElem| elements starting at |aT| to 0. */ +template +static MOZ_ALWAYS_INLINE void PodZero(NotNull aT, size_t aNElem) { + PodZero(aT.get(), aNElem); +} + /* * Arrays implicitly convert to pointers to their first element, which is * dangerous when combined with the above PodZero definitions. Adding an diff --git a/netwerk/base/nsFileStreams.cpp b/netwerk/base/nsFileStreams.cpp index 229efd0005bb..6c126ecf714d 100644 --- a/netwerk/base/nsFileStreams.cpp +++ b/netwerk/base/nsFileStreams.cpp @@ -571,7 +571,7 @@ void nsFileInputStream::SerializeInternal( FileHandleType fd = FileHandleType(PR_FileDesc2NativeHandle(mFD)); NS_ASSERTION(fd, "This should never be null!"); - DebugOnly dbgFD = aFileDescriptors.AppendElement(fd); + DebugOnly dbgFD = aFileDescriptors.AppendElement(fd); NS_ASSERTION(dbgFD->IsValid(), "Sending an invalid file descriptor!"); params.fileDescriptorIndex() = aFileDescriptors.Length() - 1; diff --git a/storage/StorageBaseStatementInternal.cpp b/storage/StorageBaseStatementInternal.cpp index 1d00700e550d..ebbd0eb03667 100644 --- a/storage/StorageBaseStatementInternal.cpp +++ b/storage/StorageBaseStatementInternal.cpp @@ -177,7 +177,7 @@ StorageBaseStatementInternal::ExecuteAsync( StatementData data; nsresult rv = getAsynchronousStatementData(data); NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(stmts.AppendElement(data), NS_ERROR_OUT_OF_MEMORY); + stmts.AppendElement(data); // Dispatch to the background return AsyncExecuteStatements::execute(stmts, mDBConnection, diff --git a/storage/mozStorageBindingParams.cpp b/storage/mozStorageBindingParams.cpp index 17d91a86af99..c816faa2b19e 100644 --- a/storage/mozStorageBindingParams.cpp +++ b/storage/mozStorageBindingParams.cpp @@ -317,8 +317,7 @@ BindingParams::BindByIndex(uint32_t aIndex, nsIVariant* aValue) { (void)mParameters.SetLength(aIndex); (void)mParameters.AppendElement(variant); } else { - NS_ENSURE_TRUE(mParameters.ReplaceElementAt(aIndex, variant), - NS_ERROR_OUT_OF_MEMORY); + mParameters.ReplaceElementAt(aIndex, variant); } return NS_OK; } @@ -335,8 +334,7 @@ AsyncBindingParams::BindByIndex(uint32_t aIndex, nsIVariant* aValue) { mParameters.SetLength(aIndex); mParameters.AppendElement(variant); } else { - NS_ENSURE_TRUE(mParameters.ReplaceElementAt(aIndex, variant), - NS_ERROR_OUT_OF_MEMORY); + mParameters.ReplaceElementAt(aIndex, variant); } return NS_OK; } diff --git a/storage/mozStorageBindingParamsArray.cpp b/storage/mozStorageBindingParamsArray.cpp index 66ea1aead629..1913d4473344 100644 --- a/storage/mozStorageBindingParamsArray.cpp +++ b/storage/mozStorageBindingParamsArray.cpp @@ -57,7 +57,7 @@ BindingParamsArray::AddParams(mozIStorageBindingParams* aParameters) { // Check to make sure that this set of parameters was created with us. if (params->getOwner() != this) return NS_ERROR_UNEXPECTED; - NS_ENSURE_TRUE(mArray.AppendElement(params), NS_ERROR_OUT_OF_MEMORY); + mArray.AppendElement(params); // Lock the parameters only after we've successfully added them. params->lock(); diff --git a/storage/mozStorageConnection.cpp b/storage/mozStorageConnection.cpp index 67f7d70538c4..85384755bb35 100644 --- a/storage/mozStorageConnection.cpp +++ b/storage/mozStorageConnection.cpp @@ -1866,7 +1866,7 @@ Connection::ExecuteAsync( "Statement must be from this database connection!"); // Now append it to our array. - NS_ENSURE_TRUE(stmts.AppendElement(data), NS_ERROR_OUT_OF_MEMORY); + stmts.AppendElement(data); } // Dispatch to the background diff --git a/toolkit/components/places/History.cpp b/toolkit/components/places/History.cpp index fc3fbb33ad42..1d01c098edb6 100644 --- a/toolkit/components/places/History.cpp +++ b/toolkit/components/places/History.cpp @@ -1855,8 +1855,7 @@ History::VisitURI(nsIWidget* aWidget, nsIURI* aURI, nsIURI* aLastVisitedURI, } nsTArray placeArray(1); - NS_ENSURE_TRUE(placeArray.AppendElement(VisitData(aURI, aLastVisitedURI)), - NS_ERROR_OUT_OF_MEMORY); + placeArray.AppendElement(VisitData(aURI, aLastVisitedURI)); VisitData& place = placeArray.ElementAt(0); NS_ENSURE_FALSE(place.spec.IsEmpty(), NS_ERROR_INVALID_ARG); diff --git a/toolkit/components/places/nsNavBookmarks.cpp b/toolkit/components/places/nsNavBookmarks.cpp index 3226c95e7a70..528cd7072f4e 100644 --- a/toolkit/components/places/nsNavBookmarks.cpp +++ b/toolkit/components/places/nsNavBookmarks.cpp @@ -1763,7 +1763,7 @@ nsresult nsNavBookmarks::GetBookmarksForURI( rv = stmt->GetInt32(6, &bookmark.syncStatus); NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(aBookmarks.AppendElement(bookmark), NS_ERROR_OUT_OF_MEMORY); + aBookmarks.AppendElement(bookmark); } return NS_OK; diff --git a/toolkit/components/places/nsNavHistoryQuery.cpp b/toolkit/components/places/nsNavHistoryQuery.cpp index 492aa6cac6ec..2c76cbbb4711 100644 --- a/toolkit/components/places/nsNavHistoryQuery.cpp +++ b/toolkit/components/places/nsNavHistoryQuery.cpp @@ -428,7 +428,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray& aTokens, // parent folders (guids) } else if (kvp.key.EqualsLiteral(QUERYKEY_PARENT)) { - NS_ENSURE_TRUE(parents.AppendElement(kvp.value), NS_ERROR_OUT_OF_MEMORY); + parents.AppendElement(kvp.value); // uri } else if (kvp.key.EqualsLiteral(QUERYKEY_URI)) { @@ -462,7 +462,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray& aTokens, NS_UnescapeURL(unescaped); // modifies input NS_ConvertUTF8toUTF16 tag(unescaped); if (!tags.Contains(tag)) { - NS_ENSURE_TRUE(tags.AppendElement(tag), NS_ERROR_OUT_OF_MEMORY); + tags.AppendElement(tag); } // not tags @@ -474,8 +474,7 @@ nsresult nsNavHistory::TokensToQuery(const nsTArray& aTokens, uint32_t transition = kvp.value.ToInteger(&rv); if (NS_SUCCEEDED(rv)) { if (!transitions.Contains(transition)) - NS_ENSURE_TRUE(transitions.AppendElement(transition), - NS_ERROR_OUT_OF_MEMORY); + transitions.AppendElement(transition); } else { NS_WARNING("Invalid Int32 transition value."); } diff --git a/toolkit/components/reputationservice/LoginReputation.cpp b/toolkit/components/reputationservice/LoginReputation.cpp index 367b9e2e60bd..f57c1ef21ba2 100644 --- a/toolkit/components/reputationservice/LoginReputation.cpp +++ b/toolkit/components/reputationservice/LoginReputation.cpp @@ -333,7 +333,7 @@ LoginReputationService::QueryReputation( // mQueryRequests is an array used to maintain the ownership of // |QueryRequest|. We ensure that |QueryRequest| is always valid until // Finish() is called or LoginReputationService is shutdown. - auto* request = + auto request = mQueryRequests.AppendElement(MakeUnique(aQuery, aCallback)); return QueryLoginWhitelist(request->get()); diff --git a/xpcom/ds/nsTArray.h b/xpcom/ds/nsTArray.h index 260cfaf48f68..a0b3f8b72cd8 100644 --- a/xpcom/ds/nsTArray.h +++ b/xpcom/ds/nsTArray.h @@ -26,6 +26,7 @@ #include "mozilla/FunctionTypeTraits.h" #include "mozilla/MathAlgorithms.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/NotNull.h" #include "mozilla/ReverseIterator.h" #include "mozilla/Span.h" #include "mozilla/TypeTraits.h" @@ -217,6 +218,10 @@ struct nsTArrayInfallibleAllocatorBase { MOZ_CRASH("infallible nsTArray should never convert false to ResultType"); } } + + template + static constexpr ResultType ConvertBoolToResultType( + const mozilla::NotNull& aValue) {} }; struct nsTArrayFallibleAllocator : nsTArrayFallibleAllocatorBase { @@ -1617,10 +1622,13 @@ class nsTArray_Impl // A variation on the ReplaceElementsAt method defined above. template - MOZ_NONNULL_RETURN elem_type* ReplaceElementAt(index_type aIndex, - const Item& aItem) { + mozilla::NotNull ReplaceElementAt(index_type aIndex, + const Item& aItem) { // This can never fail as the oldCount and newCount are the same. - return ReplaceElementsAtInternal(aIndex, 1, &aItem, 1); + // XXX(Bug 1631391) Still, we might better use a different implementation, + // which better exploits that the old and new count are the same. + return mozilla::WrapNotNullUnchecked( + ReplaceElementsAtInternal(aIndex, 1, &aItem, 1)); } // InsertElementsAt is ReplaceElementsAt with 0 elements to replace. @@ -1686,11 +1694,11 @@ class nsTArray_Impl // // would accomplish the same thing as long as T has the appropriate moving // operator=, but some types don't for various reasons. - elem_type* ReconstructElementAt(index_type aIndex) MOZ_NONNULL_RETURN { + mozilla::NotNull ReconstructElementAt(index_type aIndex) { elem_type* elem = &ElementAt(aIndex); elem_traits::Destruct(elem); elem_traits::Construct(elem); - return elem; + return mozilla::WrapNotNullUnchecked(elem); } // This method searches for the smallest index of an element that is strictly @@ -2712,141 +2720,159 @@ class nsTArray : public nsTArray_Impl { using base_type::SetLength; template - MOZ_NONNULL_RETURN elem_type* AppendElements(const Item* aArray, - size_type aArrayLen) { - return this->template AppendElementsInternal(aArray, - aArrayLen); + mozilla::NotNull AppendElements(const Item* aArray, + size_type aArrayLen) { + return mozilla::WrapNotNullUnchecked( + this->template AppendElementsInternal(aArray, + aArrayLen)); } template - MOZ_NONNULL_RETURN elem_type* AppendElements(mozilla::Span aSpan) { - return this->template AppendElementsInternal( - aSpan.Elements(), aSpan.Length()); + mozilla::NotNull AppendElements(mozilla::Span aSpan) { + return mozilla::WrapNotNullUnchecked( + this->template AppendElementsInternal(aSpan.Elements(), + aSpan.Length())); } template - MOZ_NONNULL_RETURN elem_type* AppendElements( + mozilla::NotNull AppendElements( const nsTArray_Impl& aArray) { - return this->template AppendElementsInternal( - aArray.Elements(), aArray.Length()); + return mozilla::WrapNotNullUnchecked( + this->template AppendElementsInternal( + aArray.Elements(), aArray.Length())); } template - MOZ_NONNULL_RETURN elem_type* AppendElements( + mozilla::NotNull AppendElements( nsTArray_Impl&& aArray) { - return this->template AppendElementsInternal( - std::move(aArray)); + return mozilla::WrapNotNullUnchecked( + this->template AppendElementsInternal( + std::move(aArray))); } template - MOZ_NONNULL_RETURN elem_type* AppendElement(Item&& aItem) { - return this->template AppendElementInternal( - std::forward(aItem)); + mozilla::NotNull AppendElement(Item&& aItem) { + return mozilla::WrapNotNullUnchecked( + this->template AppendElementInternal( + std::forward(aItem))); } - MOZ_NONNULL_RETURN elem_type* AppendElements(size_type aCount) { - return this->template AppendElementsInternal(aCount); + mozilla::NotNull AppendElements(size_type aCount) { + return mozilla::WrapNotNullUnchecked( + this->template AppendElementsInternal(aCount)); } - MOZ_NONNULL_RETURN elem_type* AppendElement() { - return this->template AppendElementsInternal(1); + mozilla::NotNull AppendElement() { + return mozilla::WrapNotNullUnchecked( + this->template AppendElementsInternal(1)); + } + + mozilla::NotNull InsertElementsAt(index_type aIndex, + size_type aCount) { + return mozilla::WrapNotNullUnchecked( + this->template InsertElementsAtInternal(aIndex, + aCount)); } template - MOZ_NONNULL_RETURN elem_type* InsertElementsAt(index_type aIndex, + mozilla::NotNull InsertElementsAt(index_type aIndex, + size_type aCount, + const Item& aItem) { + return mozilla::WrapNotNullUnchecked( + this->template InsertElementsAtInternal(aIndex, aCount, + aItem)); + } + + template + mozilla::NotNull InsertElementsAt(index_type aIndex, + const Item* aArray, + size_type aArrayLen) { + return mozilla::WrapNotNullUnchecked( + this->template ReplaceElementsAtInternal( + aIndex, 0, aArray, aArrayLen)); + } + + template + mozilla::NotNull InsertElementsAt( + index_type aIndex, const nsTArray_Impl& aArray) { + return mozilla::WrapNotNullUnchecked( + this->template ReplaceElementsAtInternal( + aIndex, 0, aArray.Elements(), aArray.Length())); + } + + template + mozilla::NotNull InsertElementsAt(index_type aIndex, + mozilla::Span aSpan) { + return mozilla::WrapNotNullUnchecked( + this->template ReplaceElementsAtInternal( + aIndex, 0, aSpan.Elements(), aSpan.Length())); + } + + mozilla::NotNull InsertElementAt(index_type aIndex) { + return mozilla::WrapNotNullUnchecked( + this->template InsertElementAtInternal(aIndex)); + } + + template + mozilla::NotNull InsertElementAt(index_type aIndex, + Item&& aItem) { + return mozilla::WrapNotNullUnchecked( + this->template InsertElementAtInternal( + aIndex, std::forward(aItem))); + } + + template + mozilla::NotNull ReplaceElementsAt(index_type aStart, + size_type aCount, const Item* aArray, size_type aArrayLen) { - return this->template ReplaceElementsAtInternal( - aIndex, 0, aArray, aArrayLen); - } - - template - MOZ_NONNULL_RETURN elem_type* InsertElementsAt( - index_type aIndex, const nsTArray_Impl& aArray) { - return this->template ReplaceElementsAtInternal( - aIndex, 0, aArray.Elements(), aArray.Length()); - } - - elem_type* InsertElementsAt(index_type aIndex, - size_type aCount) MOZ_NONNULL_RETURN { - return this->template InsertElementsAtInternal(aIndex, - aCount); + return mozilla::WrapNotNullUnchecked( + this->template ReplaceElementsAtInternal( + aStart, aCount, aArray, aArrayLen)); } template - MOZ_NONNULL_RETURN elem_type* InsertElementsAt(index_type aIndex, + mozilla::NotNull ReplaceElementsAt(index_type aStart, size_type aCount, - const Item& aItem) { - return this->template InsertElementsAtInternal( - aIndex, aCount, aItem); - } - - template - MOZ_NONNULL_RETURN elem_type* InsertElementsAt(index_type aIndex, - mozilla::Span aSpan) { - return this->template ReplaceElementsAtInternal( - aIndex, 0, aSpan.Elements(), aSpan.Length()); - } - - MOZ_NONNULL_RETURN elem_type* InsertElementAt(index_type aIndex) { - return this->template InsertElementAtInternal(aIndex); - } - - template - MOZ_NONNULL_RETURN elem_type* InsertElementAt(index_type aIndex, - Item&& aItem) { - return this->template InsertElementAtInternal( - aIndex, std::forward(aItem)); - } - - template - MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt(index_type aStart, - size_type aCount, - const Item* aArray, - size_type aArrayLen) { - return this->template ReplaceElementsAtInternal( - aStart, aCount, aArray, aArrayLen); - } - - template - MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt( - index_type aStart, size_type aCount, const nsTArray& aArray) { + const nsTArray& aArray) { return ReplaceElementsAt(aStart, aCount, aArray.Elements(), aArray.Length()); } template - MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt(index_type aStart, - size_type aCount, - mozilla::Span aSpan) { + mozilla::NotNull ReplaceElementsAt(index_type aStart, + size_type aCount, + mozilla::Span aSpan) { return ReplaceElementsAt(aStart, aCount, aSpan.Elements(), aSpan.Length()); } template - MOZ_NONNULL_RETURN elem_type* ReplaceElementsAt(index_type aStart, - size_type aCount, - const Item& aItem) { + mozilla::NotNull ReplaceElementsAt(index_type aStart, + size_type aCount, + const Item& aItem) { return ReplaceElementsAt(aStart, aCount, &aItem, 1); } template - MOZ_NONNULL_RETURN elem_type* InsertElementSorted(Item&& aItem, - const Comparator& aComp) { - return this->template InsertElementSortedInternal( - std::forward(aItem), aComp); + mozilla::NotNull InsertElementSorted(Item&& aItem, + const Comparator& aComp) { + return mozilla::WrapNotNullUnchecked( + this->template InsertElementSortedInternal( + std::forward(aItem), aComp)); } template - MOZ_NONNULL_RETURN elem_type* InsertElementSorted(Item&& aItem) { - return this->template InsertElementSortedInternal( - std::forward(aItem), nsDefaultComparator{}); + mozilla::NotNull InsertElementSorted(Item&& aItem) { + return mozilla::WrapNotNullUnchecked( + this->template InsertElementSortedInternal( + std::forward(aItem), nsDefaultComparator{})); } template - MOZ_NONNULL_RETURN typename base_type::elem_type* EmplaceBack( - Args&&... aArgs) { - return this->template EmplaceBackInternal( - std::forward(aArgs)...); + mozilla::NotNull EmplaceBack(Args&&... aArgs) { + return mozilla::WrapNotNullUnchecked( + this->template EmplaceBackInternal( + std::forward(aArgs)...)); } }; diff --git a/xpcom/tests/gtest/TestTArray2.cpp b/xpcom/tests/gtest/TestTArray2.cpp index 60132849fe90..b15a47740126 100644 --- a/xpcom/tests/gtest/TestTArray2.cpp +++ b/xpcom/tests/gtest/TestTArray2.cpp @@ -256,7 +256,7 @@ TEST(TArray, test_object_array) size_t i; for (i = 0; i < ArrayLength(kdata); ++i) { char x[] = {kdata[i], '\0'}; - ASSERT_TRUE(objArray.AppendElement(Object(x, i))); + objArray.AppendElement(Object(x, i)); } for (i = 0; i < ArrayLength(kdata); ++i) { ASSERT_EQ(objArray[i].Str()[0], kdata[i]); @@ -371,7 +371,7 @@ TEST(TArray, test_move_array) nsTArray countableArray; uint32_t i; for (i = 0; i < 4; ++i) { - ASSERT_TRUE(countableArray.AppendElement(Countable())); + countableArray.AppendElement(Countable()); } ASSERT_EQ(Countable::Count(), 8); @@ -417,7 +417,7 @@ TEST(TArray, test_move_array) nsTArray moveableArray; for (i = 0; i < 4; ++i) { - ASSERT_TRUE(moveableArray.AppendElement(Moveable())); + moveableArray.AppendElement(Moveable()); } ASSERT_EQ(Moveable::Count(), 4); @@ -463,7 +463,7 @@ TEST(TArray, test_move_array) AutoTArray moveableAutoArray; for (uint32_t i = 0; i < 4; ++i) { - ASSERT_TRUE(moveableAutoArray.AppendElement(Moveable())); + moveableAutoArray.AppendElement(Moveable()); } ASSERT_EQ(Moveable::Count(), 12); @@ -668,7 +668,7 @@ TEST(TArray, test_string_array) for (i = 0; i < ArrayLength(kdata); ++i) { nsCString str; str.Assign(kdata[i]); - ASSERT_TRUE(strArray.AppendElement(str)); + strArray.AppendElement(str); } for (i = 0; i < ArrayLength(kdata); ++i) { ASSERT_EQ(strArray[i].CharAt(0), kdata[i]); @@ -676,7 +676,7 @@ TEST(TArray, test_string_array) const char kextra[] = "foo bar"; size_t oldLen = strArray.Length(); - ASSERT_TRUE(strArray.AppendElement(kextra)); + strArray.AppendElement(kextra); strArray.RemoveElement(kextra); ASSERT_EQ(oldLen, strArray.Length());