Bug 1662087 - Replace explicit error handling involving `mozilla::Result::isErr` with IDB_TRY/IDB_TRY_VAR in IDBObjectStore.cpp; r=dom-workers-and-storage-reviewers,sg

Differential Revision: https://phabricator.services.mozilla.com/D88830
This commit is contained in:
Jan Varga 2020-09-07 15:52:39 +00:00
Родитель 87245d7d42
Коммит 30a12fc766
1 изменённых файлов: 54 добавлений и 54 удалений

Просмотреть файл

@ -21,6 +21,7 @@
#include "IndexedDatabase.h"
#include "IndexedDatabaseInlines.h"
#include "IndexedDatabaseManager.h"
#include "IndexedDBCommon.h"
#include "KeyPath.h"
#include "ProfilerHelpers.h"
#include "ReportInternalError.h"
@ -30,6 +31,7 @@
#include "js/StructuredClone.h"
#include "mozilla/EndianUtils.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/File.h"
@ -837,63 +839,61 @@ RefPtr<IDBRequest> IDBObjectStore::AddOrPut(JSContext* aCx,
IDBDatabase* const database = mTransaction->Database();
for (auto& file : files) {
auto fileAddInfoOrErr = [&file,
database]() -> Result<FileAddInfo, nsresult> {
switch (file.Type()) {
case StructuredCloneFileBase::eBlob: {
MOZ_ASSERT(file.HasBlob());
MOZ_ASSERT(!file.HasMutableFile());
IDB_TRY_VAR(
auto fileAddInfo,
([&file, database]() -> Result<FileAddInfo, nsresult> {
switch (file.Type()) {
case StructuredCloneFileBase::eBlob: {
MOZ_ASSERT(file.HasBlob());
MOZ_ASSERT(!file.HasMutableFile());
PBackgroundIDBDatabaseFileChild* const fileActor =
database->GetOrCreateFileActorForBlob(file.MutableBlob());
if (NS_WARN_IF(!fileActor)) {
IDB_REPORT_INTERNAL_ERR();
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
PBackgroundIDBDatabaseFileChild* const fileActor =
database->GetOrCreateFileActorForBlob(file.MutableBlob());
if (NS_WARN_IF(!fileActor)) {
IDB_REPORT_INTERNAL_ERR();
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
return FileAddInfo{fileActor, StructuredCloneFileBase::eBlob};
}
case StructuredCloneFileBase::eMutableFile: {
MOZ_ASSERT(file.HasMutableFile());
MOZ_ASSERT(!file.HasBlob());
PBackgroundMutableFileChild* const mutableFileActor =
file.MutableFile().GetBackgroundActor();
if (NS_WARN_IF(!mutableFileActor)) {
IDB_REPORT_INTERNAL_ERR();
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
return FileAddInfo{mutableFileActor,
StructuredCloneFileBase::eMutableFile};
}
case StructuredCloneFileBase::eWasmBytecode:
case StructuredCloneFileBase::eWasmCompiled: {
MOZ_ASSERT(file.HasBlob());
MOZ_ASSERT(!file.HasMutableFile());
PBackgroundIDBDatabaseFileChild* const fileActor =
database->GetOrCreateFileActorForBlob(file.MutableBlob());
if (NS_WARN_IF(!fileActor)) {
IDB_REPORT_INTERNAL_ERR();
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
return FileAddInfo{fileActor, file.Type()};
}
default:
MOZ_CRASH("Should never get here!");
}
}()),
nullptr, [&aRv](auto& result) { aRv = result.unwrapErr(); });
return FileAddInfo{fileActor, StructuredCloneFileBase::eBlob};
}
case StructuredCloneFileBase::eMutableFile: {
MOZ_ASSERT(file.HasMutableFile());
MOZ_ASSERT(!file.HasBlob());
PBackgroundMutableFileChild* const mutableFileActor =
file.MutableFile().GetBackgroundActor();
if (NS_WARN_IF(!mutableFileActor)) {
IDB_REPORT_INTERNAL_ERR();
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
return FileAddInfo{mutableFileActor,
StructuredCloneFileBase::eMutableFile};
}
case StructuredCloneFileBase::eWasmBytecode:
case StructuredCloneFileBase::eWasmCompiled: {
MOZ_ASSERT(file.HasBlob());
MOZ_ASSERT(!file.HasMutableFile());
PBackgroundIDBDatabaseFileChild* const fileActor =
database->GetOrCreateFileActorForBlob(file.MutableBlob());
if (NS_WARN_IF(!fileActor)) {
IDB_REPORT_INTERNAL_ERR();
return Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
}
return FileAddInfo{fileActor, file.Type()};
}
default:
MOZ_CRASH("Should never get here!");
}
}();
if (fileAddInfoOrErr.isErr()) {
aRv = fileAddInfoOrErr.unwrapErr();
return nullptr;
}
fileAddInfos.AppendElement(fileAddInfoOrErr.unwrap());
fileAddInfos.AppendElement(std::move(fileAddInfo));
}
}