Bug 968520 - Add mozilla::fallible to Fallible{Auto,}TArray::SetCapacity calls. r=froydnj

This commit is contained in:
Birunthan Mohanathas 2015-05-18 13:50:34 -07:00
parent 57b1194dc2
commit 1f8d7454e3
32 changed files with 60 additions and 56 deletions

View File

@ -760,7 +760,7 @@ nsDOMMutationObserver::HandleMutation()
mozilla::dom::Sequence<mozilla::dom::OwningNonNull<nsDOMMutationRecord> >
mutations;
if (mutations.SetCapacity(mPendingMutationCount)) {
if (mutations.SetCapacity(mPendingMutationCount, mozilla::fallible)) {
// We can't use TakeRecords easily here, because it deals with a
// different type of array, and we want to optimize out any extra copying.
nsRefPtr<nsDOMMutationRecord> current;

View File

@ -363,7 +363,7 @@ nsJSScriptTimeoutHandler::Init(nsGlobalWindow *aWindow, bool *aIsInterval,
uint32_t argCount = std::max(argc, 2u) - 2;
FallibleTArray<JS::Heap<JS::Value> > args;
if (!args.SetCapacity(argCount)) {
if (!args.SetCapacity(argCount, fallible)) {
// No need to drop here, since we already have a non-null mFunction
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -5602,7 +5602,7 @@ class CGArgumentConverter(CGThing):
rooterDecl +
dedent("""
if (${argc} > ${index}) {
if (!${declName}.SetCapacity(${argc} - ${index})) {
if (!${declName}.SetCapacity(${argc} - ${index}, mozilla::fallible)) {
JS_ReportOutOfMemory(cx);
return false;
}

View File

@ -1374,7 +1374,7 @@ nsDOMCameraControl::OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces
Sequence<OwningNonNull<DOMCameraDetectedFace> > faces;
uint32_t len = aFaces.Length();
if (faces.SetCapacity(len)) {
if (faces.SetCapacity(len, fallible)) {
for (uint32_t i = 0; i < len; ++i) {
*faces.AppendElement() =
new DOMCameraDetectedFace(static_cast<DOMMediaStream*>(this), aFaces[i]);

View File

@ -2716,7 +2716,8 @@ InsertIndexDataValuesFunction::OnFunctionCall(mozIStorageValueArray* aValues,
}
// Update the array with the new addition.
if (NS_WARN_IF(!indexValues.SetCapacity(indexValues.Length() + 1))) {
if (NS_WARN_IF(!indexValues.SetCapacity(indexValues.Length() + 1,
fallible))) {
IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_OUT_OF_MEMORY;
}
@ -8108,14 +8109,15 @@ ConvertBlobsToActors(PBackgroundParent* aBackgroundActor,
const uint32_t count = aFiles.Length();
if (NS_WARN_IF(!aActors.SetCapacity(count))) {
if (NS_WARN_IF(!aActors.SetCapacity(count, fallible))) {
return NS_ERROR_OUT_OF_MEMORY;
}
const bool collectFileInfos =
!BackgroundParent::IsOtherProcessActor(aBackgroundActor);
if (collectFileInfos && NS_WARN_IF(!aFileInfos.SetCapacity(count))) {
if (collectFileInfos &&
NS_WARN_IF(!aFileInfos.SetCapacity(count, fallible))) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -11579,7 +11581,7 @@ Database::Invalidate()
}
FallibleTArray<nsRefPtr<TransactionBase>> transactions;
if (NS_WARN_IF(!transactions.SetCapacity(count))) {
if (NS_WARN_IF(!transactions.SetCapacity(count, fallible))) {
return false;
}
@ -11927,7 +11929,7 @@ Database::AllocPBackgroundIDBTransactionParent(
}
FallibleTArray<nsRefPtr<FullObjectStoreMetadata>> fallibleObjectStores;
if (NS_WARN_IF(!fallibleObjectStores.SetCapacity(nameCount))) {
if (NS_WARN_IF(!fallibleObjectStores.SetCapacity(nameCount, fallible))) {
return nullptr;
}
@ -15956,7 +15958,7 @@ DatabaseOperationBase::IndexDataValuesFromUpdateInfos(
return NS_OK;
}
if (NS_WARN_IF(!aIndexValues.SetCapacity(count))) {
if (NS_WARN_IF(!aIndexValues.SetCapacity(count, fallible))) {
IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_OUT_OF_MEMORY;
}
@ -20390,7 +20392,7 @@ UpdateIndexDataValuesFunction::OnFunctionCall(mozIStorageValueArray* aValues,
const uint32_t updateInfoCount = updateInfos.Length();
if (NS_WARN_IF(!indexValues.SetCapacity(indexValues.Length() +
updateInfoCount))) {
updateInfoCount, fallible))) {
IDB_REPORT_INTERNAL_ERR();
return NS_ERROR_OUT_OF_MEMORY;
}
@ -21145,7 +21147,7 @@ ObjectStoreAddOrPutRequestOp::Init(TransactionBase* aTransaction)
if (!files.IsEmpty()) {
const uint32_t count = files.Length();
if (NS_WARN_IF(!mStoredFileInfos.SetCapacity(count))) {
if (NS_WARN_IF(!mStoredFileInfos.SetCapacity(count, fallible))) {
return false;
}

View File

@ -1206,7 +1206,7 @@ IDBObjectStore::AddOrPut(JSContext* aCx,
const uint32_t count = blobOrFileInfos.Length();
FallibleTArray<DatabaseFileOrMutableFileId> fileActorOrMutableFileIds;
if (NS_WARN_IF(!fileActorOrMutableFileIds.SetCapacity(count))) {
if (NS_WARN_IF(!fileActorOrMutableFileIds.SetCapacity(count, fallible))) {
aRv = NS_ERROR_OUT_OF_MEMORY;
return nullptr;
}

View File

@ -543,7 +543,7 @@ MediaRawData::EnsureCapacity(size_t aSize)
if (mData && mBuffer->Capacity() >= aSize + RAW_DATA_ALIGNMENT * 2) {
return true;
}
if (!mBuffer->SetCapacity(aSize + RAW_DATA_ALIGNMENT * 2)) {
if (!mBuffer->SetCapacity(aSize + RAW_DATA_ALIGNMENT * 2, fallible)) {
return false;
}
// Find alignment address.

View File

@ -348,10 +348,10 @@ MobileMessageCursorChild::DoNotifyResult(const nsTArray<MobileMessageData>& aDat
MOZ_ASSERT(length);
AutoFallibleTArray<nsISupports*, 1> autoArray;
NS_ENSURE_TRUE_VOID(autoArray.SetCapacity(length));
NS_ENSURE_TRUE_VOID(autoArray.SetCapacity(length, fallible));
AutoFallibleTArray<nsCOMPtr<nsISupports>, 1> messages;
NS_ENSURE_TRUE_VOID(messages.SetCapacity(length));
NS_ENSURE_TRUE_VOID(messages.SetCapacity(length, fallible));
for (uint32_t i = 0; i < length; i++) {
nsCOMPtr<nsISupports> message = CreateMessageFromMessageData(aDataArray[i]);
@ -369,10 +369,10 @@ MobileMessageCursorChild::DoNotifyResult(const nsTArray<ThreadData>& aDataArray)
MOZ_ASSERT(length);
AutoFallibleTArray<nsISupports*, 1> autoArray;
NS_ENSURE_TRUE_VOID(autoArray.SetCapacity(length));
NS_ENSURE_TRUE_VOID(autoArray.SetCapacity(length, fallible));
AutoFallibleTArray<nsCOMPtr<nsISupports>, 1> threads;
NS_ENSURE_TRUE_VOID(threads.SetCapacity(length));
NS_ENSURE_TRUE_VOID(threads.SetCapacity(length, fallible));
for (uint32_t i = 0; i < length; i++) {
nsCOMPtr<nsISupports> thread = new MobileMessageThread(aDataArray[i]);

View File

@ -780,7 +780,7 @@ nsSMILAnimationFunction::GetValues(const nsISMILAttr& aSMILAttr,
mValueNeedsReparsingEverySample = true;
}
if (!parseOk || !result.SetCapacity(2)) {
if (!parseOk || !result.SetCapacity(2, mozilla::fallible)) {
return NS_ERROR_FAILURE;
}

View File

@ -255,7 +255,7 @@ DOMSVGLengthList::InsertItemBefore(DOMSVGLength& newItem,
}
// Ensure we have enough memory so we can avoid complex error handling below:
if (!mItems.SetCapacity(mItems.Length() + 1) ||
if (!mItems.SetCapacity(mItems.Length() + 1, fallible) ||
!InternalList().SetCapacity(InternalList().Length() + 1)) {
error.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;

View File

@ -239,7 +239,7 @@ DOMSVGNumberList::InsertItemBefore(DOMSVGNumber& aItem,
nsRefPtr<DOMSVGNumber> domItem = aItem.HasOwner() ? aItem.Clone() : &aItem;
// Ensure we have enough memory so we can avoid complex error handling below:
if (!mItems.SetCapacity(mItems.Length() + 1) ||
if (!mItems.SetCapacity(mItems.Length() + 1, fallible) ||
!InternalList().SetCapacity(InternalList().Length() + 1)) {
error.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;

View File

@ -370,8 +370,9 @@ DOMSVGPathSegList::InsertItemBefore(DOMSVGPathSeg& aNewItem,
uint32_t argCount = SVGPathSegUtils::ArgCountForType(domItem->Type());
// Ensure we have enough memory so we can avoid complex error handling below:
if (!mItems.SetCapacity(mItems.Length() + 1) ||
!InternalList().mData.SetCapacity(InternalList().mData.Length() + 1 + argCount)) {
if (!mItems.SetCapacity(mItems.Length() + 1, fallible) ||
!InternalList().mData.SetCapacity(InternalList().mData.Length() + 1 + argCount,
fallible)) {
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}

View File

@ -306,7 +306,7 @@ DOMSVGPointList::InsertItemBefore(nsISVGPoint& aNewItem, uint32_t aIndex,
}
// Ensure we have enough memory so we can avoid complex error handling below:
if (!mItems.SetCapacity(mItems.Length() + 1) ||
if (!mItems.SetCapacity(mItems.Length() + 1, fallible) ||
!InternalList().SetCapacity(InternalList().Length() + 1)) {
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;

View File

@ -247,7 +247,7 @@ DOMSVGTransformList::InsertItemBefore(SVGTransform& newItem,
}
// Ensure we have enough memory so we can avoid complex error handling below:
if (!mItems.SetCapacity(mItems.Length() + 1) ||
if (!mItems.SetCapacity(mItems.Length() + 1, fallible) ||
!InternalList().SetCapacity(InternalList().Length() + 1)) {
error.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;

View File

@ -18,7 +18,7 @@ namespace mozilla {
nsresult
SVGLengthList::CopyFrom(const SVGLengthList& rhs)
{
if (!mLengths.SetCapacity(rhs.Length())) {
if (!mLengths.SetCapacity(rhs.Length(), fallible)) {
// Yes, we do want fallible alloc here
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -59,7 +59,7 @@ public:
bool operator==(const SVGLengthList& rhs) const;
bool SetCapacity(uint32_t size) {
return mLengths.SetCapacity(size);
return mLengths.SetCapacity(size, fallible);
}
void Compact() {

View File

@ -199,7 +199,7 @@ SVGMotionSMILType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const
MotionSegmentArray& dstArr = ExtractMotionSegmentArray(aDest);
// Ensure we have sufficient memory.
if (!dstArr.SetCapacity(srcArr.Length())) {
if (!dstArr.SetCapacity(srcArr.Length(), fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -17,7 +17,7 @@ namespace mozilla {
nsresult
SVGNumberList::CopyFrom(const SVGNumberList& rhs)
{
if (!mNumbers.SetCapacity(rhs.Length())) {
if (!mNumbers.SetCapacity(rhs.Length(), fallible)) {
// Yes, we do want fallible alloc here
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -60,7 +60,7 @@ public:
}
bool SetCapacity(uint32_t size) {
return mNumbers.SetCapacity(size);
return mNumbers.SetCapacity(size, fallible);
}
void Compact() {

View File

@ -34,7 +34,7 @@ static bool IsMoveto(uint16_t aSegType)
nsresult
SVGPathData::CopyFrom(const SVGPathData& rhs)
{
if (!mData.SetCapacity(rhs.mData.Length())) {
if (!mData.SetCapacity(rhs.mData.Length(), fallible)) {
// Yes, we do want fallible alloc here
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -135,7 +135,7 @@ public:
}
bool SetCapacity(uint32_t aSize) {
return mData.SetCapacity(aSize);
return mData.SetCapacity(aSize, fallible);
}
void Compact() {

View File

@ -68,7 +68,7 @@ public:
}
bool SetCapacity(uint32_t aSize) {
return mItems.SetCapacity(aSize);
return mItems.SetCapacity(aSize, fallible);
}
void Compact() {

View File

@ -16,7 +16,7 @@ namespace mozilla {
nsresult
SVGStringList::CopyFrom(const SVGStringList& rhs)
{
if (!mStrings.SetCapacity(rhs.Length())) {
if (!mStrings.SetCapacity(rhs.Length(), fallible)) {
// Yes, we do want fallible alloc here
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -56,7 +56,7 @@ public:
}
bool SetCapacity(uint32_t size) {
return mStrings.SetCapacity(size);
return mStrings.SetCapacity(size, fallible);
}
void Compact() {

View File

@ -43,7 +43,7 @@ SVGTransformList::CopyFrom(const SVGTransformList& rhs)
nsresult
SVGTransformList::CopyFrom(const nsTArray<nsSVGTransform>& aTransformArray)
{
if (!mItems.SetCapacity(aTransformArray.Length())) {
if (!mItems.SetCapacity(aTransformArray.Length(), fallible)) {
// Yes, we do want fallible alloc here
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -60,7 +60,7 @@ public:
}
bool SetCapacity(uint32_t size) {
return mItems.SetCapacity(size);
return mItems.SetCapacity(size, fallible);
}
void Compact() {

View File

@ -50,7 +50,7 @@ SVGTransformListSMILType::Assign(nsSMILValue& aDest,
TransformArray* dstTransforms = static_cast<TransformArray*>(aDest.mU.mPtr);
// Before we assign, ensure we have sufficient memory
bool result = dstTransforms->SetCapacity(srcTransforms->Length());
bool result = dstTransforms->SetCapacity(srcTransforms->Length(), fallible);
NS_ENSURE_TRUE(result,NS_ERROR_OUT_OF_MEMORY);
*dstTransforms = *srcTransforms;
@ -336,7 +336,7 @@ SVGTransformListSMILType::AppendTransforms(const SVGTransformList& aList,
TransformArray& transforms = *static_cast<TransformArray*>(aValue.mU.mPtr);
if (!transforms.SetCapacity(transforms.Length() + aList.Length()))
if (!transforms.SetCapacity(transforms.Length() + aList.Length(), fallible))
return false;
for (uint32_t i = 0; i < aList.Length(); ++i) {
@ -358,7 +358,7 @@ SVGTransformListSMILType::GetTransforms(const nsSMILValue& aValue,
*static_cast<const TransformArray*>(aValue.mU.mPtr);
aTransforms.Clear();
if (!aTransforms.SetCapacity(smilTransforms.Length()))
if (!aTransforms.SetCapacity(smilTransforms.Length(), fallible))
return false;
for (uint32_t i = 0; i < smilTransforms.Length(); ++i) {

View File

@ -45,8 +45,8 @@ nsConverterInputStream::Init(nsIInputStream* aStream,
mConverter = EncodingUtils::DecoderForEncoding(encoding);
// set up our buffers
if (!mByteData.SetCapacity(aBufferSize) ||
!mUnicharData.SetCapacity(aBufferSize)) {
if (!mByteData.SetCapacity(aBufferSize, mozilla::fallible) ||
!mUnicharData.SetCapacity(aBufferSize, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -520,7 +520,7 @@ struct ParamTraits<FallibleTArray<E> >
memcpy(elements, outdata, pickledLength);
} else {
if (!aResult->SetCapacity(length)) {
if (!aResult->SetCapacity(length, mozilla::fallible)) {
return false;
}

View File

@ -387,7 +387,7 @@ Dashboard::GetSockets(SocketData *aSocketData)
Sequence<mozilla::dom::SocketElement> &sockets = dict.mSockets.Value();
uint32_t length = socketData->mData.Length();
if (!sockets.SetCapacity(length)) {
if (!sockets.SetCapacity(length, fallible)) {
JS_ReportOutOfMemory(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
@ -457,7 +457,7 @@ Dashboard::GetHttpConnections(HttpData *aHttpData)
Sequence<HttpConnectionElement> &connections = dict.mConnections.Value();
uint32_t length = httpData->mData.Length();
if (!connections.SetCapacity(length)) {
if (!connections.SetCapacity(length, fallible)) {
JS_ReportOutOfMemory(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
@ -478,9 +478,10 @@ Dashboard::GetHttpConnections(HttpData *aHttpData)
Sequence<HttpConnInfo> &idle = connection.mIdle.Value();
Sequence<HalfOpenInfoDict> &halfOpens = connection.mHalfOpens.Value();
if (!active.SetCapacity(httpData->mData[i].active.Length()) ||
!idle.SetCapacity(httpData->mData[i].idle.Length()) ||
!halfOpens.SetCapacity(httpData->mData[i].halfOpens.Length())) {
if (!active.SetCapacity(httpData->mData[i].active.Length(), fallible) ||
!idle.SetCapacity(httpData->mData[i].idle.Length(), fallible) ||
!halfOpens.SetCapacity(httpData->mData[i].halfOpens.Length(),
fallible)) {
JS_ReportOutOfMemory(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
@ -619,7 +620,7 @@ Dashboard::GetWebSocketConnections(WebSocketRequest *aWsRequest)
mozilla::MutexAutoLock lock(mWs.lock);
uint32_t length = mWs.data.Length();
if (!websockets.SetCapacity(length)) {
if (!websockets.SetCapacity(length, fallible)) {
JS_ReportOutOfMemory(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
@ -692,7 +693,7 @@ Dashboard::GetDNSCacheEntries(DnsData *dnsData)
Sequence<mozilla::dom::DnsCacheEntry> &entries = dict.mEntries.Value();
uint32_t length = dnsData->mData.Length();
if (!entries.SetCapacity(length)) {
if (!entries.SetCapacity(length, fallible)) {
JS_ReportOutOfMemory(cx);
return NS_ERROR_OUT_OF_MEMORY;
}
@ -702,7 +703,7 @@ Dashboard::GetDNSCacheEntries(DnsData *dnsData)
entry.mHostaddr.Construct();
Sequence<nsString> &addrs = entry.mHostaddr.Value();
if (!addrs.SetCapacity(dnsData->mData[i].hostaddr.Length())) {
if (!addrs.SetCapacity(dnsData->mData[i].hostaddr.Length(), fallible)) {
JS_ReportOutOfMemory(cx);
return NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -704,7 +704,7 @@ ByteSliceRead(nsIInputStream* aInStream, FallibleTArray<uint32_t>* aData, uint32
rv = ReadTArray(aInStream, &slice4, count);
NS_ENSURE_SUCCESS(rv, rv);
if (!aData->SetCapacity(count)) {
if (!aData->SetCapacity(count, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -725,7 +725,7 @@ HashStore::ReadAddPrefixes()
nsresult rv = ByteSliceRead(mInputStream, &chunks, count);
NS_ENSURE_SUCCESS(rv, rv);
if (!mAddPrefixes.SetCapacity(count)) {
if (!mAddPrefixes.SetCapacity(count, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
for (uint32_t i = 0; i < count; i++) {
@ -754,7 +754,7 @@ HashStore::ReadSubPrefixes()
rv = ByteSliceRead(mInputStream, &prefixes, count);
NS_ENSURE_SUCCESS(rv, rv);
if (!mSubPrefixes.SetCapacity(count)) {
if (!mSubPrefixes.SetCapacity(count, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
for (uint32_t i = 0; i < count; i++) {

View File

@ -162,8 +162,8 @@ UTF8InputStream::UTF8InputStream() :
nsresult
UTF8InputStream::Init(nsIInputStream* aStream)
{
if (!mByteData.SetCapacity(STRING_BUFFER_SIZE) ||
!mUnicharData.SetCapacity(STRING_BUFFER_SIZE)) {
if (!mByteData.SetCapacity(STRING_BUFFER_SIZE, mozilla::fallible) ||
!mUnicharData.SetCapacity(STRING_BUFFER_SIZE, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
mInput = aStream;