Bug 1666219 - Renamed QM_TRY_VAR etc. to QM_TRY_UNWRAP etc. r=dom-workers-and-storage-reviewers,ttung,janv

Also change some left-over QM_TRY_VAR uses with const target declarations to
QM_TRY_INSPECT et al.

Differential Revision: https://phabricator.services.mozilla.com/D90873
This commit is contained in:
Simon Giesecke 2020-10-01 12:02:26 +00:00
Родитель 7f8f90331d
Коммит 4c5b983d6f
20 изменённых файлов: 528 добавлений и 484 удалений

6
dom/cache/CacheCommon.h поставляемый
Просмотреть файл

@ -24,13 +24,13 @@
#define CACHE_TRY_VAR_GLUE(accessFunction, ...) \
QM_TRY_VAR_META(mozilla::dom::cache, MOZ_UNIQUE_VAR(tryResult), \
accessFunction, ##__VA_ARGS__)
#define CACHE_TRY_VAR(...) CACHE_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define CACHE_TRY_UNWRAP(...) CACHE_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define CACHE_TRY_INSPECT(...) CACHE_TRY_VAR_GLUE(inspect, __VA_ARGS__)
#ifdef DEBUG
# define CACHE_DEBUG_TRY_VAR(...) CACHE_TRY_VAR(__VA_ARGS__)
# define CACHE_DEBUG_TRY_UNWRAP(...) CACHE_TRY_UNWRAP(__VA_ARGS__)
#else
# define CACHE_DEBUG_TRY_VAR(...)
# define CACHE_DEBUG_TRY_UNWRAP(...)
#endif
// Cache equivalents of QM_TRY_RETURN and QM_DEBUG_TRY_RETURN.

55
dom/cache/DBSchema.cpp поставляемый
Просмотреть файл

@ -459,7 +459,7 @@ nsresult CreateOrMigrateSchema(mozIStorageConnection& aConn) {
MOZ_ASSERT(!NS_IsMainThread());
int32_t schemaVersion;
CACHE_TRY_VAR(schemaVersion, GetEffectiveSchemaVersion(aConn));
CACHE_TRY_UNWRAP(schemaVersion, GetEffectiveSchemaVersion(aConn));
if (schemaVersion == kLatestSchemaVersion) {
// We already have the correct schema version. Validate it matches
@ -548,7 +548,7 @@ nsresult CreateOrMigrateSchema(mozIStorageConnection& aConn) {
return rv;
}
CACHE_TRY_VAR(schemaVersion, GetEffectiveSchemaVersion(aConn));
CACHE_TRY_UNWRAP(schemaVersion, GetEffectiveSchemaVersion(aConn));
}
nsresult rv = Validate(aConn);
@ -694,7 +694,7 @@ Result<DeletionInfo, nsresult> DeleteCacheId(mozIStorageConnection& aConn,
// anyway. These body IDs must be deleted one-by-one as content may
// still be referencing them invidivually.
AutoTArray<EntryId, 256> matches;
CACHE_TRY_VAR(matches, QueryAll(aConn, aCacheId));
CACHE_TRY_UNWRAP(matches, QueryAll(aConn, aCacheId));
AutoTArray<nsID, 16> deletedBodyIdList;
AutoTArray<IdCount, 16> deletedSecurityIdList;
@ -811,7 +811,7 @@ Result<nsTArray<nsID>, nsresult> GetKnownBodyIds(mozIStorageConnection& aConn) {
if (!isNull) {
nsID id;
CACHE_TRY_VAR(id, ExtractId(*state, i));
CACHE_TRY_UNWRAP(id, ExtractId(*state, i));
idList.AppendElement(id);
}
@ -827,14 +827,14 @@ Result<Maybe<SavedResponse>, nsresult> CacheMatch(
MOZ_ASSERT(!NS_IsMainThread());
AutoTArray<EntryId, 1> matches;
CACHE_TRY_VAR(matches, QueryCache(aConn, aCacheId, aRequest, aParams, 1));
CACHE_TRY_UNWRAP(matches, QueryCache(aConn, aCacheId, aRequest, aParams, 1));
if (matches.IsEmpty()) {
return Maybe<SavedResponse>();
}
SavedResponse response;
CACHE_TRY_VAR(response, ReadResponse(aConn, matches[0]));
CACHE_TRY_UNWRAP(response, ReadResponse(aConn, matches[0]));
response.mCacheId = aCacheId;
@ -848,9 +848,9 @@ Result<nsTArray<SavedResponse>, nsresult> CacheMatchAll(
AutoTArray<EntryId, 256> matches;
if (aMaybeRequest.isNothing()) {
CACHE_TRY_VAR(matches, QueryAll(aConn, aCacheId));
CACHE_TRY_UNWRAP(matches, QueryAll(aConn, aCacheId));
} else {
CACHE_TRY_VAR(matches,
CACHE_TRY_UNWRAP(matches,
QueryCache(aConn, aCacheId, aMaybeRequest.ref(), aParams));
}
@ -859,7 +859,7 @@ Result<nsTArray<SavedResponse>, nsresult> CacheMatchAll(
// TODO: replace this with a bulk load using SQL IN clause (bug 1110458)
for (const auto match : matches) {
SavedResponse savedResponse;
CACHE_TRY_VAR(savedResponse, ReadResponse(aConn, match));
CACHE_TRY_UNWRAP(savedResponse, ReadResponse(aConn, match));
savedResponse.mCacheId = aCacheId;
savedResponses.AppendElement(savedResponse);
@ -878,7 +878,7 @@ Result<DeletionInfo, nsresult> CachePut(mozIStorageConnection& aConn,
CacheQueryParams params(false, false, false, false, u""_ns);
AutoTArray<EntryId, 256> matches;
CACHE_TRY_VAR(matches, QueryCache(aConn, aCacheId, aRequest, params));
CACHE_TRY_UNWRAP(matches, QueryCache(aConn, aCacheId, aRequest, params));
nsTArray<nsID> deletedBodyIdList;
AutoTArray<IdCount, 16> deletedSecurityIdList;
@ -911,7 +911,7 @@ Result<Maybe<DeletionInfo>, nsresult> CacheDelete(
MOZ_ASSERT(!NS_IsMainThread());
AutoTArray<EntryId, 256> matches;
CACHE_TRY_VAR(matches, QueryCache(aConn, aCacheId, aRequest, aParams));
CACHE_TRY_UNWRAP(matches, QueryCache(aConn, aCacheId, aRequest, aParams));
if (matches.IsEmpty()) {
return Maybe<DeletionInfo>();
@ -941,9 +941,9 @@ Result<nsTArray<SavedRequest>, nsresult> CacheKeys(
AutoTArray<EntryId, 256> matches;
if (aMaybeRequest.isNothing()) {
CACHE_TRY_VAR(matches, QueryAll(aConn, aCacheId));
CACHE_TRY_UNWRAP(matches, QueryAll(aConn, aCacheId));
} else {
CACHE_TRY_VAR(matches,
CACHE_TRY_UNWRAP(matches,
QueryCache(aConn, aCacheId, aMaybeRequest.ref(), aParams));
}
@ -951,7 +951,7 @@ Result<nsTArray<SavedRequest>, nsresult> CacheKeys(
// TODO: replace this with a bulk load using SQL IN clause (bug 1110458)
for (const auto match : matches) {
SavedRequest savedRequest;
CACHE_TRY_VAR(savedRequest, ReadRequest(aConn, match));
CACHE_TRY_UNWRAP(savedRequest, ReadRequest(aConn, match));
savedRequest.mCacheId = aCacheId;
savedRequests.AppendElement(savedRequest);
@ -971,7 +971,7 @@ Result<Maybe<SavedResponse>, nsresult> StorageMatch(
// and perform the match.
if (!aParams.cacheName().EqualsLiteral("")) {
Maybe<CacheId> maybeCacheId;
CACHE_TRY_VAR(maybeCacheId,
CACHE_TRY_UNWRAP(maybeCacheId,
StorageGetCacheId(aConn, aNamespace, aParams.cacheName()));
if (maybeCacheId.isNothing()) {
return Maybe<SavedResponse>();
@ -1011,7 +1011,7 @@ Result<Maybe<SavedResponse>, nsresult> StorageMatch(
// Now try to find a match in each cache in order
for (const auto cacheId : cacheIdList) {
Maybe<SavedResponse> matchedResponse;
CACHE_TRY_VAR(matchedResponse,
CACHE_TRY_UNWRAP(matchedResponse,
CacheMatch(aConn, cacheId, aRequest, aParams));
if (matchedResponse.isSome()) {
@ -1036,7 +1036,7 @@ Result<Maybe<CacheId>, nsresult> StorageGetCacheId(mozIStorageConnection& aConn,
"ORDER BY rowid;";
nsCOMPtr<mozIStorageStatement> state;
CACHE_TRY_VAR(state, CreateAndBindKeyStatement(aConn, query, aKey));
CACHE_TRY_UNWRAP(state, CreateAndBindKeyStatement(aConn, query, aKey));
nsresult rv = state->BindInt32ByName("namespace"_ns, aNamespace);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -1108,7 +1108,7 @@ nsresult StorageForgetCache(mozIStorageConnection& aConn, Namespace aNamespace,
const char* query = "DELETE FROM storage WHERE namespace=:namespace AND %s;";
nsCOMPtr<mozIStorageStatement> state;
CACHE_TRY_VAR(state, CreateAndBindKeyStatement(aConn, query, aKey));
CACHE_TRY_UNWRAP(state, CreateAndBindKeyStatement(aConn, query, aKey));
nsresult rv = state->BindInt32ByName("namespace"_ns, aNamespace);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -1292,7 +1292,8 @@ Result<nsTArray<EntryId>, nsresult> QueryCache(mozIStorageConnection& aConn,
if (!aParams.ignoreVary() && varyCount > 0) {
bool matchedByVary = false;
CACHE_TRY_VAR(matchedByVary, MatchByVaryHeader(aConn, aRequest, entryId));
CACHE_TRY_UNWRAP(matchedByVary,
MatchByVaryHeader(aConn, aRequest, entryId));
if (!matchedByVary) {
continue;
}
@ -1516,7 +1517,7 @@ nsresult DeleteEntries(mozIStorageConnection& aConn,
if (!isNull) {
nsID id;
CACHE_TRY_VAR(id, ExtractId(*state, i));
CACHE_TRY_UNWRAP(id, ExtractId(*state, i));
aDeletedBodyIdListOut.AppendElement(id);
}
@ -1844,8 +1845,8 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
int32_t securityId = -1;
if (!aResponse.channelInfo().securityInfo().IsEmpty()) {
CACHE_TRY_VAR(securityId,
InsertSecurityInfo(aConn, *crypto,
CACHE_TRY_UNWRAP(
securityId, InsertSecurityInfo(aConn, *crypto,
aResponse.channelInfo().securityInfo()));
}
@ -2265,7 +2266,7 @@ Result<SavedResponse, nsresult> ReadResponse(mozIStorageConnection& aConn,
savedResponse.mHasBodyId = !nullBody;
if (savedResponse.mHasBodyId) {
CACHE_TRY_VAR(savedResponse.mBodyId, ExtractId(*state, 4));
CACHE_TRY_UNWRAP(savedResponse.mBodyId, ExtractId(*state, 4));
}
nsAutoCString serializedInfo;
@ -2516,7 +2517,7 @@ Result<SavedRequest, nsresult> ReadRequest(mozIStorageConnection& aConn,
}
savedRequest.mHasBodyId = !nullBody;
if (savedRequest.mHasBodyId) {
CACHE_TRY_VAR(savedRequest.mBodyId, ExtractId(*state, 13));
CACHE_TRY_UNWRAP(savedRequest.mBodyId, ExtractId(*state, 13));
}
rv = aConn.CreateStatement(nsLiteralCString("SELECT "
"name, "
@ -2815,7 +2816,7 @@ struct Expect {
nsresult Validate(mozIStorageConnection& aConn) {
int32_t schemaVersion;
CACHE_TRY_VAR(schemaVersion, GetEffectiveSchemaVersion(aConn));
CACHE_TRY_UNWRAP(schemaVersion, GetEffectiveSchemaVersion(aConn));
if (NS_WARN_IF(schemaVersion != kLatestSchemaVersion)) {
return NS_ERROR_FAILURE;
}
@ -2973,7 +2974,7 @@ nsresult Migrate(mozIStorageConnection& aConn) {
MOZ_ASSERT(!NS_IsMainThread());
int32_t currentVersion = 0;
CACHE_TRY_VAR(currentVersion, GetEffectiveSchemaVersion(aConn));
CACHE_TRY_UNWRAP(currentVersion, GetEffectiveSchemaVersion(aConn));
bool rewriteSchema = false;
@ -3000,7 +3001,7 @@ nsresult Migrate(mozIStorageConnection& aConn) {
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
int32_t lastVersion = currentVersion;
#endif
CACHE_TRY_VAR(currentVersion, GetEffectiveSchemaVersion(aConn));
CACHE_TRY_UNWRAP(currentVersion, GetEffectiveSchemaVersion(aConn));
MOZ_DIAGNOSTIC_ASSERT(currentVersion > lastVersion);
}

8
dom/cache/FileUtils.cpp поставляемый
Просмотреть файл

@ -871,7 +871,7 @@ nsresult LockedUpdateDirectoryPaddingFile(nsIFile* aBaseDir,
// We don't need to add the aIncreaseSize or aDecreaseSize here, because
// it's already encompassed within the database.
CACHE_TRY_VAR(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
CACHE_TRY_UNWRAP(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
} else {
bool shouldRevise = false;
if (aIncreaseSize > 0) {
@ -900,7 +900,7 @@ nsresult LockedUpdateDirectoryPaddingFile(nsIFile* aBaseDir,
return rv;
}
CACHE_TRY_VAR(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
CACHE_TRY_UNWRAP(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
// XXXtt: we should have an easy way to update (increase or recalulate)
// padding size in the QM. For now, only correct the padding size in
@ -912,7 +912,7 @@ nsresult LockedUpdateDirectoryPaddingFile(nsIFile* aBaseDir,
#ifdef DEBUG
int64_t lastPaddingSize = currentPaddingSize;
CACHE_TRY_VAR(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
CACHE_TRY_UNWRAP(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
MOZ_DIAGNOSTIC_ASSERT(currentPaddingSize == lastPaddingSize);
#endif // DEBUG
@ -984,7 +984,7 @@ nsresult LockedDirectoryPaddingRestore(nsIFile* aBaseDir,
return rv;
}
CACHE_TRY_VAR(*aPaddingSizeOut, db::FindOverallPaddingSize(*aConn));
CACHE_TRY_UNWRAP(*aPaddingSizeOut, db::FindOverallPaddingSize(*aConn));
MOZ_DIAGNOSTIC_ASSERT(*aPaddingSizeOut >= 0);
rv = LockedDirectoryPaddingWrite(aBaseDir, DirPaddingFile::FILE,

26
dom/cache/Manager.cpp поставляемый
Просмотреть файл

@ -102,12 +102,12 @@ class SetupAction final : public SyncDBAction {
// Clean up orphaned Cache objects
AutoTArray<CacheId, 8> orphanedCacheIdList;
CACHE_TRY_VAR(orphanedCacheIdList, db::FindOrphanedCacheIds(*aConn));
CACHE_TRY_UNWRAP(orphanedCacheIdList, db::FindOrphanedCacheIds(*aConn));
int64_t overallDeletedPaddingSize = 0;
for (uint32_t i = 0; i < orphanedCacheIdList.Length(); ++i) {
DeletionInfo deletionInfo;
CACHE_TRY_VAR(deletionInfo,
CACHE_TRY_UNWRAP(deletionInfo,
db::DeleteCacheId(*aConn, orphanedCacheIdList[i]));
rv = BodyDeleteFiles(aQuotaInfo, aDBDir,
@ -128,7 +128,7 @@ class SetupAction final : public SyncDBAction {
// Clean up orphaned body objects
AutoTArray<nsID, 64> knownBodyIdList;
CACHE_TRY_VAR(knownBodyIdList, db::GetKnownBodyIds(*aConn));
CACHE_TRY_UNWRAP(knownBodyIdList, db::GetKnownBodyIds(*aConn));
rv = BodyDeleteOrphanedFiles(aQuotaInfo, aDBDir, knownBodyIdList);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -489,7 +489,7 @@ class Manager::DeleteOrphanedCacheAction final : public SyncDBAction {
mozStorageTransaction trans(aConn, false,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
CACHE_TRY_VAR(mDeletionInfo, db::DeleteCacheId(*aConn, mCacheId));
CACHE_TRY_UNWRAP(mDeletionInfo, db::DeleteCacheId(*aConn, mCacheId));
nsresult rv = MaybeUpdatePaddingFile(
aDBDir, aConn, /* aIncreaceSize */ 0, mDeletionInfo.mDeletedPaddingSize,
@ -542,7 +542,7 @@ class Manager::CacheMatchAction final : public Manager::BaseAction {
const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override {
Maybe<SavedResponse> maybeResponse;
CACHE_TRY_VAR(
CACHE_TRY_UNWRAP(
maybeResponse,
db::CacheMatch(*aConn, mCacheId, mArgs.request(), mArgs.params()));
@ -612,7 +612,7 @@ class Manager::CacheMatchAllAction final : public Manager::BaseAction {
virtual nsresult RunSyncWithDBOnTarget(
const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override {
CACHE_TRY_VAR(mSavedResponses,
CACHE_TRY_UNWRAP(mSavedResponses,
db::CacheMatchAll(*aConn, mCacheId, mArgs.maybeRequest(),
mArgs.params()));
@ -1082,7 +1082,7 @@ class Manager::CacheDeleteAction final : public Manager::BaseAction {
mozIStorageConnection::TRANSACTION_IMMEDIATE);
Maybe<DeletionInfo> maybeDeletionInfo;
CACHE_TRY_VAR(
CACHE_TRY_UNWRAP(
maybeDeletionInfo,
db::CacheDelete(*aConn, mCacheId, mArgs.request(), mArgs.params()));
@ -1147,7 +1147,7 @@ class Manager::CacheKeysAction final : public Manager::BaseAction {
virtual nsresult RunSyncWithDBOnTarget(
const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override {
CACHE_TRY_VAR(
CACHE_TRY_UNWRAP(
mSavedRequests,
db::CacheKeys(*aConn, mCacheId, mArgs.maybeRequest(), mArgs.params()));
@ -1278,7 +1278,7 @@ class Manager::StorageHasAction final : public Manager::BaseAction {
const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override {
Maybe<CacheId> maybeCacheId;
CACHE_TRY_VAR(maybeCacheId,
CACHE_TRY_UNWRAP(maybeCacheId,
db::StorageGetCacheId(*aConn, mNamespace, mArgs.key()));
mCacheFound = maybeCacheId.isSome();
@ -1316,7 +1316,7 @@ class Manager::StorageOpenAction final : public Manager::BaseAction {
// Look for existing cache
Maybe<CacheId> maybeCacheId;
CACHE_TRY_VAR(maybeCacheId,
CACHE_TRY_UNWRAP(maybeCacheId,
db::StorageGetCacheId(*aConn, mNamespace, mArgs.key()));
if (maybeCacheId.isSome()) {
@ -1325,7 +1325,7 @@ class Manager::StorageOpenAction final : public Manager::BaseAction {
return NS_OK;
}
CACHE_TRY_VAR(mCacheId, db::CreateCacheId(*aConn));
CACHE_TRY_UNWRAP(mCacheId, db::CreateCacheId(*aConn));
nsresult rv =
db::StoragePutCache(*aConn, mNamespace, mArgs.key(), mCacheId);
@ -1374,7 +1374,7 @@ class Manager::StorageDeleteAction final : public Manager::BaseAction {
mozIStorageConnection::TRANSACTION_IMMEDIATE);
Maybe<CacheId> maybeCacheId;
CACHE_TRY_VAR(maybeCacheId,
CACHE_TRY_UNWRAP(maybeCacheId,
db::StorageGetCacheId(*aConn, mNamespace, mArgs.key()));
if (maybeCacheId.isNothing()) {
@ -1439,7 +1439,7 @@ class Manager::StorageKeysAction final : public Manager::BaseAction {
virtual nsresult RunSyncWithDBOnTarget(
const QuotaInfo& aQuotaInfo, nsIFile* aDBDir,
mozIStorageConnection* aConn) override {
CACHE_TRY_VAR(mKeys, db::StorageGetKeys(*aConn, mNamespace));
CACHE_TRY_UNWRAP(mKeys, db::StorageGetKeys(*aConn, mNamespace));
return NS_OK;
}

3
dom/cache/QuotaClient.cpp поставляемый
Просмотреть файл

@ -388,7 +388,8 @@ Result<UsageInfo, nsresult> CacheQuotaClient::GetUsageForOriginInternal(
QuotaManager* qm = QuotaManager::Get();
MOZ_DIAGNOSTIC_ASSERT(qm);
CACHE_TRY_VAR(auto dir, qm->GetDirectoryForOrigin(aPersistenceType, aOrigin));
CACHE_TRY_UNWRAP(auto dir,
qm->GetDirectoryForOrigin(aPersistenceType, aOrigin));
nsresult rv =
dir->Append(NS_LITERAL_STRING_FROM_CSTRING(DOMCACHE_DIRECTORY_NAME));

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

@ -784,8 +784,9 @@ class WorkerPermissionChallenge final : public Runnable {
return true;
}
IDB_TRY_VAR(auto principal,
mozilla::ipc::PrincipalInfoToPrincipal(mPrincipalInfo), true);
IDB_TRY_UNWRAP(auto principal,
mozilla::ipc::PrincipalInfoToPrincipal(mPrincipalInfo),
true);
if (XRE_IsParentProcess()) {
const nsCOMPtr<Element> ownerElement =
@ -1466,7 +1467,7 @@ mozilla::ipc::IPCResult BackgroundFactoryRequestChild::RecvPermissionChallenge(
return IPC_OK();
}
IDB_TRY_VAR(auto principal,
IDB_TRY_UNWRAP(auto principal,
mozilla::ipc::PrincipalInfoToPrincipal(aPrincipalInfo),
IPC_FAIL_NO_REASON(this));

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

@ -610,7 +610,7 @@ Result<nsCOMPtr<nsIFileURL>, nsresult> GetDatabaseFileURL(
? "&directoryLockId="_ns + IntCString(aDirectoryLockId)
: EmptyCString();
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
auto result, ([&mutator, &directoryLockIdClause] {
nsCOMPtr<nsIFileURL> result;
nsresult rv = NS_MutateURI(mutator)
@ -685,11 +685,11 @@ nsresult SetDefaultPragmas(mozIStorageConnection& aConnection) {
Result<nsCOMPtr<mozIStorageStatement>, nsresult>
CreateAndExecuteSingleStepStatement(mozIStorageConnection& aConnection,
const nsACString& aStatementString) {
IDB_TRY_VAR(auto stmt, MOZ_TO_RESULT_INVOKE_TYPED(
IDB_TRY_UNWRAP(auto stmt, MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, aStatementString));
IDB_TRY_VAR(const DebugOnly<bool> hasResult,
IDB_TRY_INSPECT(const DebugOnly<bool>& hasResult,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
MOZ_ASSERT(hasResult);
@ -809,7 +809,7 @@ OpenDatabaseAndHandleBusy(mozIStorageService& aStorageService,
using ConnectionType = Maybe<MovingNotNull<nsCOMPtr<mozIStorageConnection>>>;
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
auto connection,
StorageOpenTraits<FileOrURLType>::Open(aStorageService, aFileOrURL,
aTelemetryId)
@ -839,7 +839,7 @@ OpenDatabaseAndHandleBusy(mozIStorageService& aStorageService,
do {
PR_Sleep(PR_MillisecondsToInterval(100));
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
connection,
StorageOpenTraits<FileOrURLType>::Open(aStorageService, aFileOrURL,
aTelemetryId)
@ -906,7 +906,7 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
ToResultGet<nsCOMPtr<mozIStorageService>>(
MOZ_SELECT_OVERLOAD(do_GetService), MOZ_STORAGE_SERVICE_CONTRACTID));
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
auto connection,
OpenDatabaseAndHandleBusy(*storageService, *dbFileUrl, aTelemetryId)
.map([](auto connection) -> nsCOMPtr<mozIStorageConnection> {
@ -936,7 +936,7 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
IDB_TRY(aFMDirectory.Remove(true));
}
IDB_TRY_VAR(connection, OpenDatabaseAndHandleBusy(
IDB_TRY_UNWRAP(connection, OpenDatabaseAndHandleBusy(
*storageService, *dbFileUrl, aTelemetryId));
}
@ -1025,7 +1025,8 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
IDB_TRY(stmt->BindUTF8StringByIndex(1, aOrigin));
IDB_TRY(stmt->Execute());
} else {
IDB_TRY_VAR(vacuumNeeded, MaybeUpgradeSchema(*connection, schemaVersion,
IDB_TRY_UNWRAP(vacuumNeeded,
MaybeUpgradeSchema(*connection, schemaVersion,
aFMDirectory, aOrigin));
}
@ -1162,7 +1163,7 @@ GetStorageConnection(nsIFile& aDatabaseFile, const int64_t aDirectoryLockId,
return Err(rv);
}
IDB_TRY_VAR(nsCOMPtr<mozIStorageConnection> connection,
IDB_TRY_UNWRAP(nsCOMPtr<mozIStorageConnection> connection,
OpenDatabaseAndHandleBusy(*ss, *dbFileUrl, aTelemetryId));
rv = SetDefaultPragmas(*connection);
@ -5933,8 +5934,9 @@ Result<nsCOMPtr<nsIFile>, nsresult> CreateMarkerFile(
AssertIsOnIOThread();
MOZ_ASSERT(!aDatabaseNameBase.IsEmpty());
IDB_TRY_VAR(auto markerFile, MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<nsIFile>, aBaseDirectory, Clone));
IDB_TRY_UNWRAP(
auto markerFile,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, aBaseDirectory, Clone));
IDB_TRY(markerFile->Append(kIdbDeletionMarkerFilePrefix + aDatabaseNameBase));
@ -5969,7 +5971,7 @@ Result<mozilla::Ok, nsresult> DeleteFileManagerDirectory(
return mozilla::Ok{};
}
IDB_TRY_VAR(auto fileUsage, FileManager::GetUsage(&aFileManagerDirectory));
IDB_TRY_UNWRAP(auto fileUsage, FileManager::GetUsage(&aFileManagerDirectory));
uint64_t usageValue = fileUsage.GetValue().valueOr(0);
@ -6024,7 +6026,7 @@ nsresult RemoveDatabaseFilesAndDirectory(nsIFile& aBaseDirectory,
AUTO_PROFILER_LABEL("RemoveDatabaseFilesAndDirectory", DOM);
IDB_TRY_VAR(auto markerFile,
IDB_TRY_UNWRAP(auto markerFile,
CreateMarkerFile(aBaseDirectory, aDatabaseFilenameBase));
// The database file counts towards quota.
@ -6542,7 +6544,7 @@ struct ValuePopulateResponseHelper {
const ValueCursorBase& aCursor) {
constexpr auto offset = StatementHasIndexKeyBindings ? 2 : 0;
IDB_TRY_VAR(auto cloneInfo,
IDB_TRY_UNWRAP(auto cloneInfo,
GetStructuredCloneReadInfoFromStatement(
aStmt, 2 + offset, 1 + offset, *aCursor.mFileManager));
@ -7096,7 +7098,7 @@ DatabaseConnection::GetCachedStatement(const nsACString& aQuery) {
const auto extraInfo =
ScopedLogExtraInfo{ScopedLogExtraInfo::kTagQuery, aQuery};
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
stmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
**mStorageConnection, CreateStatement,
@ -7125,7 +7127,7 @@ DatabaseConnection::GetCachedStatement(const nsACString& aQuery) {
Result<DatabaseConnection::BorrowedStatement, nsresult>
DatabaseConnection::BorrowCachedStatement(const nsACString& aQuery) {
IDB_TRY_VAR(auto cachedStatement, GetCachedStatement(aQuery));
IDB_TRY_UNWRAP(auto cachedStatement, GetCachedStatement(aQuery));
return cachedStatement.Borrow();
}
@ -7401,8 +7403,8 @@ void DatabaseConnection::DoIdleProcessing(bool aNeedsCheckpoint) {
CachedStatement rollbackStmt;
CachedStatement beginStmt;
if (aNeedsCheckpoint || freelistCount) {
IDB_TRY_VAR(rollbackStmt, GetCachedStatement("ROLLBACK;"_ns), QM_VOID);
IDB_TRY_VAR(beginStmt, GetCachedStatement("BEGIN;"_ns), QM_VOID);
IDB_TRY_UNWRAP(rollbackStmt, GetCachedStatement("ROLLBACK;"_ns), QM_VOID);
IDB_TRY_UNWRAP(beginStmt, GetCachedStatement("BEGIN;"_ns), QM_VOID);
// Release the connection's normal transaction. It's possible that it could
// fail, but that isn't a problem here.
@ -7552,13 +7554,13 @@ nsresult DatabaseConnection::GetFreelistCount(CachedStatement& aCachedStatement,
nsresult rv;
if (!aCachedStatement) {
IDB_TRY_VAR(aCachedStatement,
IDB_TRY_UNWRAP(aCachedStatement,
GetCachedStatement("PRAGMA freelist_count;"_ns));
}
const auto borrowedStatement = aCachedStatement.Borrow();
IDB_TRY_VAR(const DebugOnly<bool> hasResult,
IDB_TRY_INSPECT(const DebugOnly<bool>& hasResult,
MOZ_TO_RESULT_INVOKE(&*borrowedStatement, ExecuteStep));
MOZ_ASSERT(hasResult);
@ -7664,7 +7666,7 @@ nsresult DatabaseConnection::GetFileSize(const nsAString& aPath,
MOZ_ASSERT(!aPath.IsEmpty());
MOZ_ASSERT(aResult);
IDB_TRY_VAR(auto file, QM_NewLocalFile(aPath));
IDB_TRY_UNWRAP(auto file, QM_NewLocalFile(aPath));
int64_t fileSize;
@ -8150,7 +8152,7 @@ nsresult DatabaseConnection::UpdateRefcountFunction::DatabaseUpdateFunction::
if (!mUpdateStatement) {
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_TRY_VAR(mUpdateStatement, connection->GetCachedStatement(
IDB_TRY_UNWRAP(mUpdateStatement, connection->GetCachedStatement(
"UPDATE file "
"SET refcount = refcount + :delta "
"WHERE id = :id"_ns));
@ -8185,7 +8187,7 @@ nsresult DatabaseConnection::UpdateRefcountFunction::DatabaseUpdateFunction::
if (!mSelectStatement) {
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_TRY_VAR(mSelectStatement,
IDB_TRY_UNWRAP(mSelectStatement,
connection->GetCachedStatement("SELECT id "
"FROM file "
"WHERE id = :id"_ns));
@ -8214,7 +8216,8 @@ nsresult DatabaseConnection::UpdateRefcountFunction::DatabaseUpdateFunction::
if (!mInsertStatement) {
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_TRY_VAR(mInsertStatement,
IDB_TRY_UNWRAP(
mInsertStatement,
connection->GetCachedStatement(
"INSERT INTO file (id, refcount) VALUES(:id, :delta)"_ns));
}
@ -8349,7 +8352,7 @@ ConnectionPool::GetOrCreateConnection(const Database& aDatabase) {
MOZ_ASSERT(!dbInfo->mDEBUGConnectionThread);
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
MovingNotNull<nsCOMPtr<mozIStorageConnection>> storageConnection,
GetStorageConnection(aDatabase.FilePath(), aDatabase.DirectoryLockId(),
aDatabase.TelemetryId()));
@ -10017,7 +10020,7 @@ nsresult Database::EnsureConnection() {
AUTO_PROFILER_LABEL("Database::EnsureConnection", DOM);
if (!mConnection || !mConnection->HasStorageConnection()) {
IDB_TRY_VAR(mConnection, gConnectionPool->GetOrCreateConnection(*this));
IDB_TRY_UNWRAP(mConnection, gConnectionPool->GetOrCreateConnection(*this));
}
AssertIsOnConnectionThread();
@ -10485,7 +10488,7 @@ Database::AllocPBackgroundIDBTransactionParent(
return nullptr;
}
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
auto objectStoreMetadatas,
TransformIntoNewArrayAbortOnErr(
aObjectStoreNames,
@ -12500,7 +12503,7 @@ void ValueCursorBase::ProcessFiles(CursorResponse& aResponse,
MOZ_ASSERT(serializedInfo->files().IsEmpty());
MOZ_ASSERT(this->mDatabase);
IDB_TRY_VAR(serializedInfo->files(),
IDB_TRY_UNWRAP(serializedInfo->files(),
SerializeStructuredCloneFiles((*this->mBackgroundParent),
this->mDatabase, files,
/* aForPreprocess */ false),
@ -12591,7 +12594,7 @@ mozilla::ipc::IPCResult Cursor<CursorType>::RecvContinue(
MOZ_ASSERT(!aCurrentKey.IsUnset());
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
auto position,
([&]() -> Result<CursorPosition<CursorType>, mozilla::ipc::IPCResult> {
if constexpr (IsIndexCursor) {
@ -12667,13 +12670,14 @@ nsresult FileManager::Init(nsIFile* aDirectory,
IDB_TRY(aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755));
}
IDB_TRY_VAR(auto path,
IDB_TRY_UNWRAP(auto path,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, aDirectory, GetPath));
mDirectoryPath.init(std::move(path));
}
IDB_TRY_VAR(auto journalDirectory,
IDB_TRY_INSPECT(
const auto& journalDirectory,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, aDirectory, Clone));
IDB_TRY(journalDirectory->Append(kJournalDirectoryName));
@ -12685,7 +12689,7 @@ nsresult FileManager::Init(nsIFile* aDirectory,
Unused << existsAsDirectory;
{
IDB_TRY_VAR(auto path, MOZ_TO_RESULT_INVOKE_TYPED(
IDB_TRY_UNWRAP(auto path, MOZ_TO_RESULT_INVOKE_TYPED(
nsString, journalDirectory, GetPath));
mJournalDirectoryPath.init(std::move(path));
@ -12795,7 +12799,8 @@ nsCOMPtr<nsIFile> FileManager::GetFileForId(nsIFile* aDirectory, int64_t aId) {
nsAutoString id;
id.AppendInt(aId);
IDB_TRY_VAR(auto file,
IDB_TRY_UNWRAP(
auto file,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, aDirectory, Clone),
nullptr);
@ -12886,7 +12891,7 @@ nsresult FileManager::InitDirectory(nsIFile& aDirectory, nsIFile& aDatabaseFile,
}));
if (hasJournals) {
IDB_TRY_VAR(const NotNull<nsCOMPtr<mozIStorageConnection>> connection,
IDB_TRY_UNWRAP(const NotNull<nsCOMPtr<mozIStorageConnection>> connection,
CreateStorageConnection(
aDatabaseFile, aDirectory, VoidString(), aOrigin,
/* aDirectoryLockId */ -1, aTelemetryId));
@ -12898,8 +12903,8 @@ nsresult FileManager::InitDirectory(nsIFile& aDirectory, nsIFile& aDatabaseFile,
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_TRY_VAR(
auto stmt,
IDB_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<mozIStorageStatement>, *connection, CreateStatement,
"SELECT name, (name IN (SELECT id FROM file)) FROM fs WHERE path = :path"_ns));
@ -13758,8 +13763,8 @@ nsresult QuotaClient::GetDirectory(PersistenceType aPersistenceType,
QuotaManager* const quotaManager = QuotaManager::Get();
NS_ASSERTION(quotaManager, "This should never fail!");
IDB_TRY_VAR(auto directory,
quotaManager->GetDirectoryForOrigin(aPersistenceType, aOrigin));
IDB_TRY_UNWRAP(auto directory, quotaManager->GetDirectoryForOrigin(
aPersistenceType, aOrigin));
MOZ_ASSERT(directory);
@ -14690,7 +14695,7 @@ void DatabaseMaintenance::PerformMaintenanceOnDatabase() {
const nsCOMPtr<nsIFile> databaseFile = GetFileForPath(mDatabasePath);
MOZ_ASSERT(databaseFile);
IDB_TRY_VAR(const NotNull<nsCOMPtr<mozIStorageConnection>> connection,
IDB_TRY_UNWRAP(const NotNull<nsCOMPtr<mozIStorageConnection>> connection,
GetStorageConnection(*databaseFile, mDirectoryLockId,
TelemetryIdForFile(databaseFile)),
QM_VOID);
@ -14801,7 +14806,7 @@ nsresult DatabaseMaintenance::CheckIntegrity(mozIStorageConnection& aConnection,
return rv;
}
IDB_TRY_VAR(foreignKeyError, MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
IDB_TRY_UNWRAP(foreignKeyError, MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
}
if (!foreignKeysWereEnabled) {
@ -15387,7 +15392,7 @@ nsresult DatabaseOperationBase::InsertIndexTableRows(
info.mUnique ? insertUniqueStmt : insertStmt;
if (!stmt) {
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
stmt,
aConnection->GetCachedStatement(
info.mUnique
@ -15477,7 +15482,7 @@ nsresult DatabaseOperationBase::DeleteIndexDataTableRows(
indexValue.mUnique ? deleteUniqueStmt : deleteStmt;
if (!stmt) {
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
stmt,
aConnection->GetCachedStatement(
indexValue.mUnique
@ -15546,12 +15551,12 @@ nsresult DatabaseOperationBase::DeleteObjectStoreDataTableRowsWithIndexes(
nsresult rv;
Key objectStoreKey;
IDB_TRY_VAR(
const auto selectStmt,
IDB_TRY_INSPECT(
const auto& selectStmt,
([singleRowOnly, &aConnection, &objectStoreKey, &aKeyRange]()
-> Result<DatabaseConnection::BorrowedStatement, nsresult> {
if (singleRowOnly) {
IDB_TRY_VAR(auto selectStmt,
IDB_TRY_UNWRAP(auto selectStmt,
aConnection->BorrowCachedStatement(
"SELECT index_data_values "
"FROM object_data "
@ -15570,7 +15575,8 @@ nsresult DatabaseOperationBase::DeleteObjectStoreDataTableRowsWithIndexes(
const auto keyRangeClause =
MaybeGetBindingClauseForKeyRange(aKeyRange, kColumnNameKey);
IDB_TRY_VAR(auto selectStmt,
IDB_TRY_UNWRAP(
auto selectStmt,
aConnection->BorrowCachedStatement(
"SELECT index_data_values, "_ns + kColumnNameKey +
" FROM object_data WHERE object_store_id = :"_ns +
@ -15607,7 +15613,7 @@ nsresult DatabaseOperationBase::DeleteObjectStoreDataTableRowsWithIndexes(
DeleteIndexDataTableRows(aConnection, objectStoreKey, indexValues));
if (!deleteStmt) {
IDB_TRY_VAR(deleteStmt,
IDB_TRY_UNWRAP(deleteStmt,
aConnection->GetCachedStatement(
"DELETE FROM object_data "
"WHERE object_store_id = :"_ns +
@ -15643,7 +15649,7 @@ nsresult DatabaseOperationBase::UpdateIndexValues(
AUTO_PROFILER_LABEL("DatabaseOperationBase::UpdateIndexValues", DOM);
IDB_TRY_VAR((auto [indexDataValues, indexDataValuesLength]),
IDB_TRY_UNWRAP((auto [indexDataValues, indexDataValuesLength]),
MakeCompressedIndexDataValues(aIndexValues));
MOZ_ASSERT(!indexDataValuesLength == !(indexDataValues.get()));
@ -15709,7 +15715,8 @@ nsresult DatabaseOperationBase::ObjectStoreHasIndexes(
return rv;
}
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
*aHasIndexes = hasResult;
return NS_OK;
@ -16571,7 +16578,7 @@ nsresult FactoryOp::OpenDirectory() {
QuotaManager* const quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
IDB_TRY_VAR(auto dbFile,
IDB_TRY_UNWRAP(auto dbFile,
quotaManager->GetDirectoryForOrigin(persistenceType, mOrigin));
nsresult rv =
@ -16918,9 +16925,10 @@ nsresult OpenDatabaseOp::DoDatabaseWork() {
return rv;
}
IDB_TRY_VAR(NotNull<nsCOMPtr<mozIStorageConnection>> connection,
CreateStorageConnection(*dbFile, *fmDirectory, databaseName,
mOrigin, mDirectoryLockId, mTelemetryId));
IDB_TRY_UNWRAP(
NotNull<nsCOMPtr<mozIStorageConnection>> connection,
CreateStorageConnection(*dbFile, *fmDirectory, databaseName, mOrigin,
mDirectoryLockId, mTelemetryId));
AutoSetProgressHandler asph;
rv = asph.Register(*connection, this);
@ -17006,7 +17014,8 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
return rv;
}
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
if (NS_WARN_IF(!hasResult)) {
return NS_ERROR_FILE_CORRUPTED;
@ -17293,7 +17302,7 @@ nsresult OpenDatabaseOp::UpdateLocaleAwareIndex(
writeStmt = nsCOMPtr<mozIStorageStatement>{}](
auto& readStmt) mutable -> mozilla::Result<mozilla::Ok, nsresult> {
if (!writeStmt) {
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
writeStmt,
MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection, CreateStatement,
@ -17700,20 +17709,20 @@ Result<DatabaseSpec, nsresult> OpenDatabaseOp::MetadataToSpec() const {
DatabaseSpec spec;
spec.metadata() = mMetadata->mCommonMetadata;
IDB_TRY_VAR(spec.objectStores(),
IDB_TRY_UNWRAP(
spec.objectStores(),
TransformIntoNewArrayAbortOnErr(
mMetadata->mObjectStores,
[](const auto& objectStoreEntry)
-> mozilla::Result<ObjectStoreSpec, nsresult> {
FullObjectStoreMetadata* metadata =
objectStoreEntry.GetData();
FullObjectStoreMetadata* metadata = objectStoreEntry.GetData();
MOZ_ASSERT(objectStoreEntry.GetKey());
MOZ_ASSERT(metadata);
ObjectStoreSpec objectStoreSpec;
objectStoreSpec.metadata() = metadata->mCommonMetadata;
IDB_TRY_VAR(auto indexes,
IDB_TRY_UNWRAP(auto indexes,
TransformIntoNewArray(
metadata->mIndexes,
[](const auto& indexEntry) {
@ -17939,7 +17948,7 @@ void DeleteDatabaseOp::LoadPreviousVersion(nsIFile& aDatabaseFile) {
return;
}
IDB_TRY_VAR(const NotNull<nsCOMPtr<mozIStorageConnection>> connection,
IDB_TRY_UNWRAP(const NotNull<nsCOMPtr<mozIStorageConnection>> connection,
OpenDatabaseAndHandleBusy(*ss, aDatabaseFile), QM_VOID);
#ifdef DEBUG
@ -17951,8 +17960,8 @@ void DeleteDatabaseOp::LoadPreviousVersion(nsIFile& aDatabaseFile) {
return;
}
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep),
QM_VOID);
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep), QM_VOID);
if (NS_WARN_IF(!hasResult)) {
return;
}
@ -17974,8 +17983,8 @@ void DeleteDatabaseOp::LoadPreviousVersion(nsIFile& aDatabaseFile) {
return;
}
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep),
QM_VOID);
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep), QM_VOID);
if (NS_WARN_IF(!hasResult)) {
return;
@ -18025,7 +18034,7 @@ nsresult DeleteDatabaseOp::DoDatabaseWork() {
QuotaManager* const quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
IDB_TRY_VAR(auto directory,
IDB_TRY_UNWRAP(auto directory,
quotaManager->GetDirectoryForOrigin(persistenceType, mOrigin));
nsresult rv =
@ -18642,7 +18651,8 @@ nsresult TransactionBase::CommitOp::WriteAutoIncrementCounts() {
if (!stmt) {
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_TRY_VAR(stmt, connection->GetCachedStatement(
IDB_TRY_UNWRAP(stmt,
connection->GetCachedStatement(
"UPDATE object_store "
"SET auto_increment = :auto_increment WHERE id "
"= :object_store_id;"_ns));
@ -18704,7 +18714,7 @@ void TransactionBase::CommitOp::AssertForeignKeyConsistency(
MOZ_ASSERT(mTransaction->GetMode() != IDBTransaction::Mode::ReadOnly);
{
IDB_DEBUG_TRY_VAR(
IDB_DEBUG_TRY_UNWRAP(
const auto pragmaStmt,
aConnection->BorrowCachedStatement("PRAGMA foreign_keys;"_ns), QM_VOID);
@ -18721,7 +18731,7 @@ void TransactionBase::CommitOp::AssertForeignKeyConsistency(
}
{
IDB_DEBUG_TRY_VAR(
IDB_DEBUG_TRY_UNWRAP(
const auto checkStmt,
aConnection->BorrowCachedStatement("PRAGMA foreign_key_check;"_ns),
QM_VOID);
@ -19109,7 +19119,7 @@ nsresult CreateObjectStoreOp::DoDatabaseWork(DatabaseConnection* aConnection) {
// have thrown an error long before now...
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_DEBUG_TRY_VAR(const auto stmt, aConnection->BorrowCachedStatement(
IDB_DEBUG_TRY_UNWRAP(const auto stmt, aConnection->BorrowCachedStatement(
"SELECT name "
"FROM object_store "
"WHERE name = :name;"_ns));
@ -19199,8 +19209,9 @@ nsresult DeleteObjectStoreOp::DoDatabaseWork(DatabaseConnection* aConnection) {
#ifdef DEBUG
{
// Make sure |mIsLastObjectStore| is telling the truth.
IDB_DEBUG_TRY_VAR(const auto stmt, aConnection->BorrowCachedStatement(
"SELECT id FROM object_store;"_ns));
IDB_DEBUG_TRY_UNWRAP(
const auto stmt,
aConnection->BorrowCachedStatement("SELECT id FROM object_store;"_ns));
bool foundThisObjectStore = false;
bool foundOtherObjectStore = false;
@ -19378,7 +19389,7 @@ nsresult RenameObjectStoreOp::DoDatabaseWork(DatabaseConnection* aConnection) {
// have thrown an error long before now...
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_DEBUG_TRY_VAR(const auto stmt,
IDB_DEBUG_TRY_UNWRAP(const auto stmt,
aConnection->BorrowCachedStatement(
"SELECT name "
"FROM object_store "
@ -19561,7 +19572,7 @@ nsresult CreateIndexOp::DoDatabaseWork(DatabaseConnection* aConnection) {
// we should have thrown an error long before now...
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_DEBUG_TRY_VAR(
IDB_DEBUG_TRY_UNWRAP(
const auto stmt,
aConnection->BorrowCachedStatement(
"SELECT name "
@ -19709,10 +19720,11 @@ CreateIndexOp::UpdateIndexDataValuesFunction::OnFunctionCall(
}
#endif
IDB_TRY_VAR(auto cloneInfo, GetStructuredCloneReadInfoFromValueArray(
aValues,
IDB_TRY_UNWRAP(auto cloneInfo,
GetStructuredCloneReadInfoFromValueArray(aValues,
/* aDataIndex */ 3,
/* aFileIdsIndex */ 2, *mOp->mFileManager));
/* aFileIdsIndex */ 2,
*mOp->mFileManager));
const IndexMetadata& metadata = mOp->mMetadata;
const IndexOrObjectStoreId& objectStoreId = mOp->mObjectStoreId;
@ -19779,7 +19791,7 @@ CreateIndexOp::UpdateIndexDataValuesFunction::OnFunctionCall(
return rv;
}
IDB_TRY_VAR(auto indexValues, ReadCompressedIndexDataValues(*aValues, 1));
IDB_TRY_UNWRAP(auto indexValues, ReadCompressedIndexDataValues(*aValues, 1));
const bool hadPreviousIndexValues = !indexValues.IsEmpty();
@ -19799,7 +19811,7 @@ CreateIndexOp::UpdateIndexDataValuesFunction::OnFunctionCall(
fallible));
}
IDB_TRY_VAR((auto [indexValuesBlob, indexValuesBlobLength]),
IDB_TRY_UNWRAP((auto [indexValuesBlob, indexValuesBlobLength]),
MakeCompressedIndexDataValues(indexValues));
MOZ_ASSERT(!indexValuesBlobLength == !(indexValuesBlob.get()));
@ -19938,7 +19950,7 @@ nsresult DeleteIndexOp::DoDatabaseWork(DatabaseConnection* aConnection) {
// Make sure |mIsLastIndex| is telling the truth.
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_DEBUG_TRY_VAR(const auto stmt,
IDB_DEBUG_TRY_UNWRAP(const auto stmt,
aConnection->BorrowCachedStatement(
"SELECT id "
"FROM object_store_index "
@ -19988,8 +20000,8 @@ nsresult DeleteIndexOp::DoDatabaseWork(DatabaseConnection* aConnection) {
// mozStorage warns that these statements trigger a sort operation but we
// don't care because this is a very rare call and we expect it to be slow.
// The cost of having an index on this field is too high.
IDB_TRY_VAR(
const auto selectStmt,
IDB_TRY_INSPECT(
const auto& selectStmt,
aConnection->BorrowCachedStatement(
mUnique
? (mIsLastIndex
@ -20101,7 +20113,7 @@ nsresult DeleteIndexOp::DoDatabaseWork(DatabaseConnection* aConnection) {
// Now delete the index row.
if (!deleteIndexRowStmt) {
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
deleteIndexRowStmt,
aConnection->GetCachedStatement(
mUnique ? "DELETE FROM unique_index_data "
@ -20192,7 +20204,7 @@ nsresult RenameIndexOp::DoDatabaseWork(DatabaseConnection* aConnection) {
// thrown an error long before now...
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
IDB_DEBUG_TRY_VAR(const auto stmt,
IDB_DEBUG_TRY_UNWRAP(const auto stmt,
aConnection->BorrowCachedStatement(
"SELECT name "
"FROM object_store_index "
@ -20489,7 +20501,7 @@ nsresult ObjectStoreAddOrPutRequestOp::RemoveOldIndexDataValues(
return rv;
}
IDB_TRY_VAR(const bool hasResult,
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(&*indexValuesStmt, ExecuteStep));
if (hasResult) {
@ -20544,7 +20556,7 @@ bool ObjectStoreAddOrPutRequestOp::Init(TransactionBase& aTransaction) {
mUniqueIndexTable.ref().MarkImmutable();
}
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
mStoredFileInfos,
TransformIntoNewArray(
mParams.fileAddInfos(),
@ -21016,8 +21028,9 @@ Result<T, nsresult> ObjectStoreGetRequestOp::ConvertResponse(
result.hasPreprocessInfo() = aInfo.HasPreprocessInfo();
}
IDB_TRY_VAR(result.files(), SerializeStructuredCloneFiles(
mBackgroundParent, mDatabase, aInfo.Files(),
IDB_TRY_UNWRAP(
result.files(),
SerializeStructuredCloneFiles(mBackgroundParent, mDatabase, aInfo.Files(),
std::is_same_v<T, PreprocessInfo>));
return result;
@ -21059,7 +21072,7 @@ nsresult ObjectStoreGetRequestOp::DoDatabaseWork(
IDB_TRY(CollectWhileHasResult(
*stmt,
[this](auto& stmt) mutable -> mozilla::Result<mozilla::Ok, nsresult> {
IDB_TRY_VAR(auto cloneInfo,
IDB_TRY_UNWRAP(auto cloneInfo,
GetStructuredCloneReadInfoFromStatement(
&stmt, 1, 0, mDatabase->GetFileManager()));
@ -21110,7 +21123,7 @@ ObjectStoreGetRequestOp::GetPreprocessParams() {
auto params = ObjectStoreGetPreprocessParams();
IDB_TRY_VAR(params.preprocessInfo(),
IDB_TRY_UNWRAP(params.preprocessInfo(),
ConvertResponse<PreprocessInfo>(std::move(mResponse[0])));
return PreprocessParams{std::move(params)};
@ -21125,7 +21138,7 @@ void ObjectStoreGetRequestOp::GetResponse(RequestResponse& aResponse,
*aResponseSize = 0;
if (!mResponse.IsEmpty()) {
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
aResponse.get_ObjectStoreGetAllResponse().cloneInfos(),
TransformIntoNewArrayAbortOnErr(
std::make_move_iterator(mResponse.begin()),
@ -21151,11 +21164,12 @@ void ObjectStoreGetRequestOp::GetResponse(RequestResponse& aResponse,
aResponse.get_ObjectStoreGetResponse().cloneInfo();
*aResponseSize += mResponse[0].Size();
IDB_TRY_VAR(serializedInfo,
IDB_TRY_UNWRAP(serializedInfo,
ConvertResponse<SerializedStructuredCloneReadInfo>(
std::move(mResponse[0])),
QM_VOID,
[&aResponse](auto& result) { aResponse = result.unwrapErr(); });
QM_VOID, [&aResponse](auto& result) {
aResponse = result.unwrapErr();
});
}
}
@ -21429,7 +21443,8 @@ nsresult ObjectStoreCountRequestOp::DoDatabaseWork(
}
}
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
if (NS_WARN_IF(!hasResult)) {
MOZ_ASSERT(false, "This should never be possible!");
@ -21581,7 +21596,7 @@ nsresult IndexGetRequestOp::DoDatabaseWork(DatabaseConnection* aConnection) {
IDB_TRY(CollectWhileHasResult(
*stmt,
[this](auto& stmt) mutable -> mozilla::Result<mozilla::Ok, nsresult> {
IDB_TRY_VAR(auto cloneInfo,
IDB_TRY_UNWRAP(auto cloneInfo,
GetStructuredCloneReadInfoFromStatement(
&stmt, 1, 0, mDatabase->GetFileManager()));
@ -21612,7 +21627,7 @@ void IndexGetRequestOp::GetResponse(RequestResponse& aResponse,
result.data().data = info.ReleaseData();
IDB_TRY_VAR(result.files(),
IDB_TRY_UNWRAP(result.files(),
SerializeStructuredCloneFiles(mBackgroundParent, mDatabase,
info.Files(), false));
@ -21624,12 +21639,12 @@ void IndexGetRequestOp::GetResponse(RequestResponse& aResponse,
*aResponseSize = 0;
if (!mResponse.IsEmpty()) {
IDB_TRY_VAR(aResponse.get_IndexGetAllResponse().cloneInfos(),
IDB_TRY_UNWRAP(aResponse.get_IndexGetAllResponse().cloneInfos(),
TransformIntoNewArrayAbortOnErr(
std::make_move_iterator(mResponse.begin()),
std::make_move_iterator(mResponse.end()),
[convertResponse,
&aResponseSize](StructuredCloneReadInfoParent&& info) {
[convertResponse, &aResponseSize](
StructuredCloneReadInfoParent&& info) {
*aResponseSize += info.Size();
return convertResponse(std::move(info));
},
@ -21650,8 +21665,8 @@ void IndexGetRequestOp::GetResponse(RequestResponse& aResponse,
aResponse.get_IndexGetResponse().cloneInfo();
*aResponseSize += mResponse[0].Size();
IDB_TRY_VAR(serializedInfo, convertResponse(std::move(mResponse[0])),
QM_VOID,
IDB_TRY_UNWRAP(
serializedInfo, convertResponse(std::move(mResponse[0])), QM_VOID,
[&aResponse](auto& result) { aResponse = result.unwrapErr(); });
}
}
@ -21788,7 +21803,8 @@ nsresult IndexCountRequestOp::DoDatabaseWork(DatabaseConnection* aConnection) {
}
}
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
if (NS_WARN_IF(!hasResult)) {
MOZ_ASSERT(false, "This should never be possible!");
@ -21955,8 +21971,8 @@ void CursorOpBaseHelperBase<CursorType>::PopulateExtraResponses(
// any remaining entries, and signal overall success. Probably, future
// attempts to access the same entry will fail as well, but it might never
// be accessed by the application.
IDB_TRY_VAR(
const auto responseSize,
IDB_TRY_INSPECT(
const auto& responseSize,
PopulateResponseFromStatement(aStmt, false, aOptPreviousSortKey),
extraCount, [](const auto&) {
// TODO: Maybe disable preloading for this cursor? The problem will
@ -22162,7 +22178,8 @@ void IndexOpenOpHelper<CursorType>::PrepareIndexKeyConditionClause(
template <IDBCursorType CursorType>
nsresult CommonOpenOpHelper<CursorType>::ProcessStatementSteps(
mozIStorageStatement* const aStmt) {
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(aStmt, ExecuteStep));
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(aStmt, ExecuteStep));
if (!hasResult) {
SetResponse(void_t{});
@ -22654,7 +22671,7 @@ nsresult Cursor<CursorType>::ContinueOp::DoDatabaseWork(
// TODO: Why do we query the records we don't need and skip them here, rather
// than using a OFFSET clause in the query?
for (uint32_t index = 0; index < advanceCount; index++) {
IDB_TRY_VAR(const bool hasResult,
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
if (!hasResult) {

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

@ -239,14 +239,15 @@ nsresult ReadCompressedIndexDataValuesFromBlob(
NS_ERROR_FILE_CORRUPTED, IDB_REPORT_INTERNAL_ERR_LAMBDA);
for (auto remainder = aBlobData; !remainder.IsEmpty();) {
IDB_TRY_VAR((const auto [indexId, unique, remainderAfterIndexId]),
IDB_TRY_INSPECT((const auto& [indexId, unique, remainderAfterIndexId]),
ReadCompressedIndexId(remainder));
IDB_TRY(OkIf(!remainderAfterIndexId.IsEmpty()), NS_ERROR_FILE_CORRUPTED,
IDB_REPORT_INTERNAL_ERR_LAMBDA);
// Read key buffer length.
IDB_TRY_VAR((const auto [keyBufferLength, remainderAfterKeyBufferLength]),
IDB_TRY_INSPECT(
(const auto& [keyBufferLength, remainderAfterKeyBufferLength]),
ReadCompressedNumber(remainderAfterIndexId));
IDB_TRY(OkIf(!remainderAfterKeyBufferLength.IsEmpty()),
@ -365,7 +366,8 @@ GetStructuredCloneReadInfoFromBlob(const uint8_t* aBlobData,
nsTArray<StructuredCloneFileParent> files;
if (!aFileIds.IsVoid()) {
IDB_TRY_VAR(files, DeserializeStructuredCloneFiles(aFileManager, aFileIds));
IDB_TRY_UNWRAP(files,
DeserializeStructuredCloneFiles(aFileManager, aFileIds));
}
return StructuredCloneReadInfoParent{std::move(data), std::move(files),
@ -382,7 +384,8 @@ GetStructuredCloneReadInfoFromExternalBlob(uint64_t aIntData,
nsTArray<StructuredCloneFileParent> files;
if (!aFileIds.IsVoid()) {
IDB_TRY_VAR(files, DeserializeStructuredCloneFiles(aFileManager, aFileIds));
IDB_TRY_UNWRAP(files,
DeserializeStructuredCloneFiles(aFileManager, aFileIds));
}
// Higher and lower 32 bits described
@ -419,8 +422,8 @@ GetStructuredCloneReadInfoFromExternalBlob(uint64_t aIntData,
do {
char buffer[kFileCopyBufferSize];
IDB_TRY_VAR(
const uint32_t numRead,
IDB_TRY_INSPECT(
const uint32_t& numRead,
MOZ_TO_RESULT_INVOKE(snappyInputStream, Read, buffer, sizeof(buffer)));
if (!numRead) {
@ -625,7 +628,8 @@ Result<IndexDataValuesAutoArray, nsresult> ReadCompressedIndexDataValues(
Result<std::tuple<IndexOrObjectStoreId, bool, Span<const uint8_t>>, nsresult>
ReadCompressedIndexId(const Span<const uint8_t> aData) {
IDB_TRY_VAR((const auto [indexId, remainder]), ReadCompressedNumber(aData));
IDB_TRY_INSPECT((const auto& [indexId, remainder]),
ReadCompressedNumber(aData));
MOZ_ASSERT(UINT64_MAX / 2 >= uint64_t(indexId), "Bad index id!");
@ -689,7 +693,7 @@ DeserializeStructuredCloneFiles(const FileManager& aFileManager,
const auto& token = tokenizer.nextToken();
MOZ_ASSERT(!token.IsEmpty());
IDB_TRY_VAR(auto structuredCloneFile,
IDB_TRY_UNWRAP(auto structuredCloneFile,
DeserializeStructuredCloneFile(aFileManager, token));
result.EmplaceBack(std::move(structuredCloneFile));

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

@ -883,7 +883,7 @@ nsresult IDBDatabase::GetQuotaInfo(nsACString& aOrigin,
return NS_OK;
case PrincipalInfo::TContentPrincipalInfo: {
IDB_TRY_VAR(auto principal, PrincipalInfoToPrincipal(*principalInfo));
IDB_TRY_UNWRAP(auto principal, PrincipalInfoToPrincipal(*principalInfo));
nsresult rv = QuotaManager::GetInfoFromPrincipal(principal, nullptr,
nullptr, &aOrigin);

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

@ -827,7 +827,7 @@ RefPtr<IDBRequest> IDBObjectStore::AddOrPut(JSContext* aCx,
commonParams.indexUpdateInfos() = std::move(updateInfos);
// Convert any blobs or mutable files into FileAddInfo.
IDB_TRY_VAR(
IDB_TRY_UNWRAP(
commonParams.fileAddInfos(),
TransformIntoNewArrayAbortOnErr(
cloneWriteInfo.mFiles,

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

@ -24,13 +24,13 @@
#define IDB_TRY_VAR_GLUE(accessFunction, ...) \
QM_TRY_VAR_META(mozilla::dom::indexedDB, MOZ_UNIQUE_VAR(tryResult), \
accessFunction, ##__VA_ARGS__)
#define IDB_TRY_VAR(...) IDB_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define IDB_TRY_UNWRAP(...) IDB_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define IDB_TRY_INSPECT(...) IDB_TRY_VAR_GLUE(inspect, __VA_ARGS__)
#ifdef DEBUG
# define IDB_DEBUG_TRY_VAR(...) IDB_TRY_VAR(__VA_ARGS__)
# define IDB_DEBUG_TRY_UNWRAP(...) IDB_TRY_UNWRAP(__VA_ARGS__)
#else
# define IDB_DEBUG_TRY_VAR(...)
# define IDB_DEBUG_TRY_UNWRAP(...)
#endif
// IndexedDB equivalents of QM_TRY_RETURN and QM_DEBUG_TRY_RETURN.

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

@ -527,7 +527,8 @@ bool IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
return false;
}
IDB_TRY_VAR(auto factory, IDBFactory::CreateForMainThreadJS(global), false);
IDB_TRY_UNWRAP(auto factory, IDBFactory::CreateForMainThreadJS(global),
false);
MOZ_ASSERT(factory, "This should never fail for chrome!");

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

@ -107,7 +107,8 @@ nsresult UpgradeSchemaFrom4To5(mozIStorageConnection& aConnection) {
{
mozStorageStatementScoper scoper(stmt);
IDB_TRY_VAR(const bool hasResults, MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
IDB_TRY_INSPECT(const bool& hasResults,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
if (NS_WARN_IF(!hasResults)) {
return NS_ERROR_FAILURE;
@ -1447,7 +1448,7 @@ UpgradeSchemaFrom17_0To18_0Helper::InsertIndexDataValuesFunction::
// Read out the previous value. It may be NULL, in which case we'll just end
// up with an empty array.
IDB_TRY_VAR(auto indexValues, ReadCompressedIndexDataValues(*aValues, 0));
IDB_TRY_UNWRAP(auto indexValues, ReadCompressedIndexDataValues(*aValues, 0));
IndexOrObjectStoreId indexId;
nsresult rv = aValues->GetInt64(1, &indexId);
@ -1475,7 +1476,7 @@ UpgradeSchemaFrom17_0To18_0Helper::InsertIndexDataValuesFunction::
}
// Compress the array.
IDB_TRY_VAR((auto [indexValuesBlob, indexValuesBlobLength]),
IDB_TRY_UNWRAP((auto [indexValuesBlob, indexValuesBlobLength]),
MakeCompressedIndexDataValues(indexValues));
// The compressed blob is the result of this function.
@ -2300,7 +2301,8 @@ nsresult UpgradeSchemaFrom19_0To20_0(nsIFile* aFMDirectory,
{
mozStorageStatementScoper scoper(stmt);
IDB_TRY_VAR(const bool hasResult, MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
IDB_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
if (NS_WARN_IF(!hasResult)) {
MOZ_ASSERT(false, "This should never be possible!");
@ -2412,7 +2414,7 @@ UpgradeIndexDataValuesFunction::ReadOldCompressedIDVFromBlob(
IndexDataValuesArray result;
for (auto remainder = aBlobData; !remainder.IsEmpty();) {
if (!nextIndexIdAlreadyRead) {
IDB_TRY_VAR((std::tie(indexId, unique, remainder)),
IDB_TRY_UNWRAP((std::tie(indexId, unique, remainder)),
ReadCompressedIndexId(remainder));
}
nextIndexIdAlreadyRead = false;
@ -2505,7 +2507,7 @@ UpgradeIndexDataValuesFunction::OnFunctionCall(
IDB_TRY_INSPECT(const auto& oldIdv,
ReadOldCompressedIDVFromBlob(Span(oldBlob, oldBlobLength)));
IDB_TRY_VAR((auto [newIdv, newIdvLength]),
IDB_TRY_UNWRAP((auto [newIdv, newIdvLength]),
MakeCompressedIndexDataValues(oldIdv));
nsCOMPtr<nsIVariant> result = new storage::AdoptedBlobVariant(
@ -2884,7 +2886,7 @@ UpgradeFileIdsFunction::OnFunctionCall(mozIStorageValueArray* aArguments,
return NS_ERROR_UNEXPECTED;
}
IDB_TRY_VAR(auto cloneInfo, GetStructuredCloneReadInfoFromValueArray(
IDB_TRY_UNWRAP(auto cloneInfo, GetStructuredCloneReadInfoFromValueArray(
aArguments, 1, 0, *mFileManager));
nsAutoString fileIds;
@ -2991,7 +2993,7 @@ Result<bool, nsresult> MaybeUpgradeSchema(mozIStorageConnection& aConnection,
});
}
IDB_TRY_VAR(schemaVersion,
IDB_TRY_UNWRAP(schemaVersion,
MOZ_TO_RESULT_INVOKE(aConnection, GetSchemaVersion));
}

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

@ -4257,7 +4257,7 @@ nsresult Connection::EnsureStorageConnection() {
MOZ_ASSERT(quotaManager);
if (!mDatabaseWasNotAvailable || mHasCreatedDatabase) {
LS_TRY_VAR(auto directoryEntry, quotaManager->GetDirectoryForOrigin(
LS_TRY_UNWRAP(auto directoryEntry, quotaManager->GetDirectoryForOrigin(
PERSISTENCE_TYPE_DEFAULT, mOrigin));
rv = directoryEntry->Append(
@ -7346,7 +7346,7 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
return rv;
}
} else {
LS_TRY_VAR(directoryEntry, quotaManager->GetDirectoryForOrigin(
LS_TRY_UNWRAP(directoryEntry, quotaManager->GetDirectoryForOrigin(
PERSISTENCE_TYPE_DEFAULT, mOrigin));
quotaManager->EnsureQuotaForOrigin(PERSISTENCE_TYPE_DEFAULT, mGroup,
@ -8797,7 +8797,7 @@ Result<UsageInfo, nsresult> QuotaClient::InitOrigin(
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
LS_TRY_VAR(auto directory,
LS_TRY_UNWRAP(auto directory,
quotaManager->GetDirectoryForOrigin(aPersistenceType, aOrigin));
MOZ_ASSERT(directory);

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

@ -203,13 +203,13 @@
#define LS_TRY_VAR_GLUE(accessFunction, ...) \
QM_TRY_VAR_META(mozilla::dom::localstorage, MOZ_UNIQUE_VAR(tryResult), \
accessFunction, ##__VA_ARGS__)
#define LS_TRY_VAR(...) LS_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define LS_TRY_UNWRAP(...) LS_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define LS_TRY_INSPECT(...) LS_TRY_VAR_GLUE(inspect, __VA_ARGS__)
#ifdef DEBUG
# define LS_DEBUG_TRY_VAR(...) LS_TRY_VAR(__VA_ARGS__)
# define LS_DEBUG_TRY_UNWRAP(...) LS_TRY_UNWRAP(__VA_ARGS__)
#else
# define LS_DEBUG_TRY_VAR(...)
# define LS_DEBUG_TRY_UNWRAP(...)
#endif
// LocalStorage equivalents of QM_TRY_RETURN and QM_DEBUG_TRY_RETURN.

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

@ -2517,7 +2517,7 @@ Result<nsCOMPtr<nsIOutputStream>, nsresult> GetOutputStream(
Result<nsCOMPtr<nsIBinaryOutputStream>, nsresult> GetBinaryOutputStream(
nsIFile& aFile, FileFlag aFileFlag) {
QM_TRY_VAR(auto outputStream, GetOutputStream(aFile, aFileFlag));
QM_TRY_UNWRAP(auto outputStream, GetOutputStream(aFile, aFileFlag));
QM_TRY(OkIf(outputStream), Err(NS_ERROR_UNEXPECTED));
@ -2572,12 +2572,12 @@ nsresult CreateDirectoryMetadata(nsIFile& aDirectory, int64_t aTimestamp,
MOZ_ASSERT(groupPrefix == originPrefix);
QM_TRY_VAR(auto file,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, aDirectory, Clone));
QM_TRY_UNWRAP(auto file, MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>,
aDirectory, Clone));
QM_TRY(file->Append(nsLiteralString(METADATA_TMP_FILE_NAME)));
QM_TRY_VAR(auto stream, GetBinaryOutputStream(*file, kTruncateFileFlag));
QM_TRY_UNWRAP(auto stream, GetBinaryOutputStream(*file, kTruncateFileFlag));
MOZ_ASSERT(stream);
@ -2605,12 +2605,12 @@ nsresult CreateDirectoryMetadata2(nsIFile& aDirectory, int64_t aTimestamp,
const nsACString& aOrigin) {
AssertIsOnIOThread();
QM_TRY_VAR(auto file,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, aDirectory, Clone));
QM_TRY_UNWRAP(auto file, MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>,
aDirectory, Clone));
QM_TRY(file->Append(nsLiteralString(METADATA_V2_TMP_FILE_NAME)));
QM_TRY_VAR(auto stream, GetBinaryOutputStream(*file, kTruncateFileFlag));
QM_TRY_UNWRAP(auto stream, GetBinaryOutputStream(*file, kTruncateFileFlag));
MOZ_ASSERT(stream);
@ -2649,8 +2649,8 @@ Result<nsCOMPtr<nsIBinaryInputStream>, nsresult> GetBinaryInputStream(
nsIFile& aDirectory, const nsAString& aFilename) {
MOZ_ASSERT(!NS_IsMainThread());
QM_TRY_VAR(auto file,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, aDirectory, Clone));
QM_TRY_UNWRAP(auto file, MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>,
aDirectory, Clone));
QM_TRY(file->Append(aFilename));
@ -4373,7 +4373,7 @@ nsresult QuotaManager::LoadQuota() {
}
if (accessed) {
QM_TRY_VAR(auto directory,
QM_TRY_UNWRAP(auto directory,
GetDirectoryForOrigin(persistenceType, origin));
bool exists;
@ -4656,8 +4656,8 @@ already_AddRefed<QuotaObject> QuotaManager::GetQuotaObject(
QM_TRY(aFile->GetPath(path), nullptr);
#ifdef DEBUG
QM_TRY_VAR(auto directory, GetDirectoryForOrigin(aPersistenceType, aOrigin),
nullptr);
QM_TRY_UNWRAP(auto directory,
GetDirectoryForOrigin(aPersistenceType, aOrigin), nullptr);
nsAutoString clientType;
bool ok = Client::TypeToText(aClientType, clientType, fallible);
@ -4829,7 +4829,8 @@ void QuotaManager::AbortOperationsForProcess(ContentParentId aContentParentId) {
Result<nsCOMPtr<nsIFile>, nsresult> QuotaManager::GetDirectoryForOrigin(
PersistenceType aPersistenceType, const nsACString& aASCIIOrigin) const {
QM_TRY_VAR(auto directory, QM_NewLocalFile(GetStoragePath(aPersistenceType)));
QM_TRY_UNWRAP(auto directory,
QM_NewLocalFile(GetStoragePath(aPersistenceType)));
nsAutoCString originSanitized(aASCIIOrigin);
SanitizeOriginString(originSanitized);
@ -4865,7 +4866,7 @@ nsresult QuotaManager::GetDirectoryMetadata2(
MOZ_ASSERT(aPersisted);
MOZ_ASSERT(mStorageConnection);
QM_TRY_VAR(auto binaryStream,
QM_TRY_UNWRAP(auto binaryStream,
GetBinaryInputStream(*aDirectory,
nsLiteralString(METADATA_V2_FILE_NAME)));
@ -4886,8 +4887,8 @@ nsresult QuotaManager::GetDirectoryMetadata2(
QM_TRY_INSPECT(const auto& suffix, MOZ_TO_RESULT_INVOKE_TYPED(
nsCString, binaryStream, ReadCString));
QM_TRY_VAR(auto group,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, binaryStream, ReadCString));
QM_TRY_UNWRAP(auto group, MOZ_TO_RESULT_INVOKE_TYPED(nsCString, binaryStream,
ReadCString));
QM_TRY_INSPECT(const auto& origin, MOZ_TO_RESULT_INVOKE_TYPED(
nsCString, binaryStream, ReadCString));
@ -4953,7 +4954,7 @@ nsresult QuotaManager::GetDirectoryMetadata2(nsIFile* aDirectory,
MOZ_ASSERT(aTimestamp != nullptr || aPersisted != nullptr);
MOZ_ASSERT(mStorageConnection);
QM_TRY_VAR(auto binaryStream,
QM_TRY_UNWRAP(auto binaryStream,
GetBinaryInputStream(*aDirectory,
nsLiteralString(METADATA_V2_FILE_NAME)));
@ -5512,7 +5513,7 @@ nsresult QuotaManager::UpgradeStorage(const int32_t aOldVersion,
MOZ_ASSERT(aConnection);
for (const PersistenceType persistenceType : kAllPersistenceTypes) {
QM_TRY_VAR(auto directory,
QM_TRY_UNWRAP(auto directory,
QM_NewLocalFile(GetStoragePath(persistenceType)));
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(directory, Exists));
@ -5527,7 +5528,7 @@ nsresult QuotaManager::UpgradeStorage(const int32_t aOldVersion,
}
{
QM_DEBUG_TRY_VAR(const int32_t storageVersion,
QM_DEBUG_TRY_UNWRAP(const int32_t storageVersion,
MOZ_TO_RESULT_INVOKE(aConnection, GetSchemaVersion));
MOZ_ASSERT(storageVersion == aOldVersion);
@ -5700,7 +5701,7 @@ nsresult QuotaManager::UpgradeStorageFrom2_2To2_3(
"VALUES (0)")));
{
QM_DEBUG_TRY_VAR(const int32_t storageVersion,
QM_DEBUG_TRY_UNWRAP(const int32_t storageVersion,
MOZ_TO_RESULT_INVOKE(aConnection, GetSchemaVersion));
MOZ_ASSERT(storageVersion == MakeStorageVersion(2, 2));
@ -6325,7 +6326,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
Initialization::Storage,
[&self = *this] { return static_cast<bool>(self.mStorageConnection); });
QM_TRY_VAR(auto storageFile, QM_NewLocalFile(mBasePath));
QM_TRY_UNWRAP(auto storageFile, QM_NewLocalFile(mBasePath));
QM_TRY(storageFile->Append(mStorageName + kSQLiteSuffix));
@ -6333,7 +6334,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
MOZ_TO_RESULT_INVOKE(storageFile, Exists));
if (!storageFileExists) {
QM_TRY_VAR(auto indexedDBDir, QM_NewLocalFile(mIndexedDBPath));
QM_TRY_UNWRAP(auto indexedDBDir, QM_NewLocalFile(mIndexedDBPath));
QM_TRY_INSPECT(const auto& indexedDBDirExists,
MOZ_TO_RESULT_INVOKE(indexedDBDir, Exists));
@ -6343,7 +6344,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
indexedDBDir));
}
QM_TRY_VAR(auto persistentStorageDir, QM_NewLocalFile(mStoragePath));
QM_TRY_UNWRAP(auto persistentStorageDir, QM_NewLocalFile(mStoragePath));
QM_TRY(persistentStorageDir->Append(
nsLiteralString(PERSISTENT_DIRECTORY_NAME)));
@ -6357,11 +6358,11 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
}
}
QM_TRY_VAR(auto ss, ToResultGet<nsCOMPtr<mozIStorageService>>(
QM_TRY_UNWRAP(auto ss, ToResultGet<nsCOMPtr<mozIStorageService>>(
MOZ_SELECT_OVERLOAD(do_GetService),
MOZ_STORAGE_SERVICE_CONTRACTID));
QM_TRY_VAR(auto connection,
QM_TRY_UNWRAP(auto connection,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, storageFile)
.orElse(ErrToOkOrErr<NS_ERROR_FILE_CORRUPTED, nullptr,
@ -6371,8 +6372,8 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
// Nuke the database file.
QM_TRY(storageFile->Remove(false));
QM_TRY_VAR(connection,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
QM_TRY_UNWRAP(connection, MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, storageFile));
}
@ -6380,7 +6381,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
QM_TRY(connection->ExecuteSimpleSQL("PRAGMA synchronous = EXTRA;"_ns));
// Check to make sure that the storage version is correct.
QM_TRY_VAR(auto storageVersion,
QM_TRY_UNWRAP(auto storageVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion));
// Hacky downgrade logic!
@ -6399,7 +6400,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
if (storageVersion < kStorageVersion) {
const bool newDatabase = !storageVersion;
QM_TRY_VAR(auto storageDir, QM_NewLocalFile(mStoragePath));
QM_TRY_UNWRAP(auto storageDir, QM_NewLocalFile(mStoragePath));
QM_TRY_INSPECT(const auto& storageDirExists,
MOZ_TO_RESULT_INVOKE(storageDir, Exists));
@ -6424,7 +6425,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
QM_TRY(CreateTables(connection));
{
QM_DEBUG_TRY_VAR(const auto storageVersion,
QM_DEBUG_TRY_UNWRAP(const auto storageVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion));
MOZ_ASSERT(storageVersion == kStorageVersion);
}
@ -6456,7 +6457,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
});
}
QM_TRY_VAR(storageVersion,
QM_TRY_UNWRAP(storageVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion));
}
@ -6467,7 +6468,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
}
if (CachedNextGenLocalStorageEnabled()) {
QM_TRY_VAR((auto [connection, newlyCreatedOrRecreated]),
QM_TRY_UNWRAP((auto [connection, newlyCreatedOrRecreated]),
CreateLocalStorageArchiveConnection());
uint32_t version = 0;
@ -6477,14 +6478,14 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
IsLocalStorageArchiveInitialized(*connection));
if (initialized) {
QM_TRY_VAR(version, LoadLocalStorageArchiveVersion(*connection));
QM_TRY_UNWRAP(version, LoadLocalStorageArchiveVersion(*connection));
}
}
if (version > kLocalStorageArchiveVersion) {
QM_TRY(DowngradeLocalStorageArchive(connection));
QM_TRY_VAR(version, LoadLocalStorageArchiveVersion(*connection));
QM_TRY_UNWRAP(version, LoadLocalStorageArchiveVersion(*connection));
MOZ_ASSERT(version == kLocalStorageArchiveVersion);
} else if (version != kLocalStorageArchiveVersion) {
@ -6512,7 +6513,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
});
}
QM_TRY_VAR(version, LoadLocalStorageArchiveVersion(*connection));
QM_TRY_UNWRAP(version, LoadLocalStorageArchiveVersion(*connection));
}
MOZ_ASSERT(version == kLocalStorageArchiveVersion);
@ -6524,7 +6525,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
bool cacheUsable = true;
QM_TRY_VAR(int32_t cacheVersion, LoadCacheVersion(*connection));
QM_TRY_UNWRAP(int32_t cacheVersion, LoadCacheVersion(*connection));
if (cacheVersion > kCacheVersion) {
cacheUsable = false;
@ -6555,7 +6556,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
if (insertStmt) {
MOZ_ALWAYS_SUCCEEDS(insertStmt->Reset());
} else {
QM_TRY_VAR(
QM_TRY_UNWRAP(
insertStmt,
MOZ_TO_RESULT_INVOKE_TYPED(
nsCOMPtr<mozIStorageStatement>, connection, CreateStatement,
@ -6586,7 +6587,7 @@ nsresult QuotaManager::EnsureStorageIsInitialized() {
});
}
QM_TRY_VAR(cacheVersion, LoadCacheVersion(*connection));
QM_TRY_UNWRAP(cacheVersion, LoadCacheVersion(*connection));
}
MOZ_ASSERT(cacheVersion == kCacheVersion);
@ -6757,7 +6758,7 @@ nsresult QuotaManager::EnsurePersistentOriginIsInitialized(
info.mPersistentOriginAttempted = true;
}
QM_TRY_VAR(auto directory,
QM_TRY_UNWRAP(auto directory,
GetDirectoryForOrigin(PERSISTENCE_TYPE_PERSISTENT, aOrigin));
if (mInitializedOrigins.Contains(aOrigin)) {
@ -6834,7 +6835,8 @@ nsresult QuotaManager::EnsureTemporaryOriginIsInitialized(
}
// Get directory for this origin and persistence type.
QM_TRY_VAR(auto directory, GetDirectoryForOrigin(aPersistenceType, aOrigin));
QM_TRY_UNWRAP(auto directory,
GetDirectoryForOrigin(aPersistenceType, aOrigin));
bool created;
rv = EnsureOriginDirectory(directory, &created);
@ -7626,8 +7628,8 @@ void QuotaManager::CheckTemporaryStorageLimits() {
void QuotaManager::DeleteFilesForOrigin(PersistenceType aPersistenceType,
const nsACString& aOrigin) {
QM_TRY_VAR(auto directory, GetDirectoryForOrigin(aPersistenceType, aOrigin),
QM_VOID);
QM_TRY_UNWRAP(auto directory,
GetDirectoryForOrigin(aPersistenceType, aOrigin), QM_VOID);
nsresult rv = directory->Remove(true);
if (rv != NS_ERROR_FILE_TARGET_DOES_NOT_EXIST &&
@ -8339,7 +8341,7 @@ nsresult SaveOriginAccessTimeOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
AUTO_PROFILER_LABEL("SaveOriginAccessTimeOp::DoDirectoryWork", OTHER);
QM_TRY_VAR(auto file,
QM_TRY_UNWRAP(auto file,
aQuotaManager.GetDirectoryForOrigin(mPersistenceType.Value(),
mOriginScope.GetOrigin()));
@ -8348,7 +8350,7 @@ nsresult SaveOriginAccessTimeOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
return rv;
}
QM_TRY_VAR(auto stream, GetBinaryOutputStream(*file, kUpdateFileFlag));
QM_TRY_UNWRAP(auto stream, GetBinaryOutputStream(*file, kUpdateFileFlag));
// The origin directory may not exist anymore.
if (stream) {
@ -8918,7 +8920,7 @@ Result<UsageInfo, nsresult> QuotaUsageRequestBase::GetUsageForOrigin(
const nsACString& aGroup, const nsACString& aOrigin) {
AssertIsOnIOThread();
QM_TRY_VAR(auto directory,
QM_TRY_UNWRAP(auto directory,
aQuotaManager.GetDirectoryForOrigin(aPersistenceType, aOrigin));
bool exists;
@ -9984,7 +9986,7 @@ nsresult PersistedOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
// If we get here, it means the origin hasn't been initialized yet.
// Try to get the persisted flag from directory metadata on disk.
QM_TRY_VAR(auto directory,
QM_TRY_UNWRAP(auto directory,
aQuotaManager.GetDirectoryForOrigin(mPersistenceType.Value(),
mOriginScope.GetOrigin()));
@ -10039,7 +10041,7 @@ nsresult PersistOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
// Update directory metadata on disk first. Then, create/update the originInfo
// if needed.
QM_TRY_VAR(auto directory,
QM_TRY_UNWRAP(auto directory,
aQuotaManager.GetDirectoryForOrigin(mPersistenceType.Value(),
mOriginScope.GetOrigin()));
@ -10090,7 +10092,7 @@ nsresult PersistOp::DoDirectoryWork(QuotaManager& aQuotaManager) {
return rv;
}
QM_TRY_VAR(auto stream, GetBinaryOutputStream(*file, kUpdateFileFlag));
QM_TRY_UNWRAP(auto stream, GetBinaryOutputStream(*file, kUpdateFileFlag));
MOZ_ASSERT(stream);
@ -10387,8 +10389,8 @@ nsresult StorageOperationBase::GetDirectoryMetadata(nsIFile* aDirectory,
AssertIsOnIOThread();
MOZ_ASSERT(aDirectory);
QM_TRY_VAR(
auto binaryStream,
QM_TRY_INSPECT(
const auto& binaryStream,
GetBinaryInputStream(*aDirectory, nsLiteralString(METADATA_FILE_NAME)));
QM_TRY_INSPECT(const uint64_t& timestamp,
@ -10419,7 +10421,7 @@ nsresult StorageOperationBase::GetDirectoryMetadata2(
AssertIsOnIOThread();
MOZ_ASSERT(aDirectory);
QM_TRY_VAR(auto binaryStream,
QM_TRY_UNWRAP(auto binaryStream,
GetBinaryInputStream(*aDirectory,
nsLiteralString(METADATA_V2_FILE_NAME)));
@ -11072,7 +11074,8 @@ void OriginParser::HandleTrailingSeparator() {
nsresult RepositoryOperationBase::ProcessRepository() {
AssertIsOnIOThread();
QM_DEBUG_TRY_VAR(const bool exists, MOZ_TO_RESULT_INVOKE(mDirectory, Exists));
QM_DEBUG_TRY_UNWRAP(const bool exists,
MOZ_TO_RESULT_INVOKE(mDirectory, Exists));
MOZ_ASSERT(exists);
QM_TRY(CollectEachFileEntry(
@ -11103,8 +11106,8 @@ nsresult RepositoryOperationBase::ProcessRepository() {
}
if (originProps.mType != OriginProps::eObsolete) {
QM_TRY_VAR(
const bool removed,
QM_TRY_INSPECT(
const bool& removed,
MOZ_TO_RESULT_INVOKE(self, PrepareOriginDirectory, originProps));
if (removed) {
return mozilla::Ok{};
@ -11152,8 +11155,8 @@ nsresult RepositoryOperationBase::MaybeUpgradeClients(
QM_TRY_INSPECT(const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, dir, GetLeafName));
QM_TRY_VAR(
const bool removed,
QM_TRY_INSPECT(
const bool& removed,
MOZ_TO_RESULT_INVOKE(self, PrepareClientDirectory, dir, leafName));
if (removed) {
return mozilla::Ok{};
@ -11401,7 +11404,7 @@ nsresult CreateOrUpgradeDirectoryMetadataHelper::ProcessOriginDirectory(
return rv;
}
QM_TRY_VAR(auto stream, GetBinaryOutputStream(*file, kAppendFileFlag));
QM_TRY_UNWRAP(auto stream, GetBinaryOutputStream(*file, kAppendFileFlag));
MOZ_ASSERT(stream);
@ -11480,7 +11483,7 @@ nsresult UpgradeStorageFrom1_0To2_0Helper::MaybeRemoveMorgueDirectory(
// working. So recover these profiles permanently by removing these corrupt
// directories as part of this upgrade.
QM_TRY_VAR(auto morgueDir,
QM_TRY_UNWRAP(auto morgueDir,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>,
aOriginProps.mDirectory, Clone));
@ -11564,7 +11567,7 @@ UpgradeStorageFrom1_0To2_0Helper::MaybeStripObsoleteOriginAttributes(
/* aPersisted */ false, aOriginProps.mSuffix,
aOriginProps.mGroup, aOriginProps.mOrigin));
QM_TRY_VAR(auto newFile,
QM_TRY_UNWRAP(auto newFile,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>,
aOriginProps.mDirectory, GetParent));

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

@ -540,7 +540,7 @@
accessFunction, ##__VA_ARGS__)
/**
* QM_TRY_VAR(target, expr[, customRetVal, cleanup]) is the C++ equivalent of
* QM_TRY_UNWRAP(target, expr[, customRetVal, cleanup]) is the C++ equivalent of
* Rust's `target = try!(expr);`. First, it evaluates expr, which must produce
* a Result value. On success, the result's success value is unwrapped and
* assigned to target. On error, it calls HandleError and an additional cleanup
@ -548,7 +548,7 @@
* result or a custom return value (if the third argument was passed). |target|
* must be an lvalue.
*/
#define QM_TRY_VAR(...) QM_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define QM_TRY_UNWRAP(...) QM_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
/**
* QM_TRY_INSPECT is similar to QM_TRY_VAR, but it does not unwrap a success
@ -559,7 +559,7 @@
*
* should be preferred over
*
* QM_TRY_VAR(const auto target, DoSomething())
* QM_TRY_UNWRAP(const auto target, DoSomething())
*
* as it avoids unnecessary moves/copies.
*/
@ -570,9 +570,9 @@
* in non-debug builds.
*/
#ifdef DEBUG
# define QM_DEBUG_TRY_VAR(...) QM_TRY_VAR(__VA_ARGS__)
# define QM_DEBUG_TRY_UNWRAP(...) QM_TRY_UNWRAP(__VA_ARGS__)
#else
# define QM_DEBUG_TRY_VAR(...)
# define QM_DEBUG_TRY_UNWRAP(...)
#endif
// QM_TRY_RETURN_PROPAGATE_ERR, QM_TRY_RETURN_CUSTOM_RET_VAL,

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

@ -507,15 +507,6 @@ TEST(QuotaCommon_TryInspect, Failure_WithCleanup_UnwrapErr)
EXPECT_EQ(rv, NS_ERROR_FAILURE);
}
TEST(QuotaCommon_TryVar, Decl)
{
QM_TRY_VAR(int32_t x, (Result<int32_t, nsresult>{42}), QM_VOID);
static_assert(std::is_same_v<decltype(x), int32_t>);
EXPECT_EQ(x, 42);
}
TEST(QuotaCommon_TryInspect, ConstDecl)
{
QM_TRY_INSPECT(const int32_t& x, (Result<int32_t, nsresult>{42}), QM_VOID);
@ -544,19 +535,6 @@ TEST(QuotaCommon_TryInspect, SameLine)
EXPECT_EQ(y, 42);
}
TEST(QuotaCommon_TryVar, ParenDecl)
{
QM_TRY_VAR((const auto [x, y]),
(Result<std::pair<int32_t, bool>, nsresult>{std::pair{42, true}}),
QM_VOID);
static_assert(std::is_same_v<decltype(x), const int32_t>);
static_assert(std::is_same_v<decltype(y), const bool>);
EXPECT_EQ(x, 42);
EXPECT_EQ(y, true);
}
TEST(QuotaCommon_TryInspect, NestingMadness_Success)
{
bool nestedTryInspectDidNotReturn = false;
@ -721,21 +699,57 @@ TEST(QuotaCommon_TryInspect, NestingMadness_Multiple_Failure2)
EXPECT_EQ(rv, NS_ERROR_FAILURE);
}
TEST(QuotaCommon_DebugTryVar, Success)
// We are not repeating all QM_TRY_INSPECT test cases for QM_TRY_UNWRAP, since
// they are largely based on the same implementation. We just add some where
// inspecting and unwrapping differ.
TEST(QuotaCommon_TryUnwrap, NonConstDecl)
{
bool debugTryVarBodyRan = false;
bool debugTryVarDidNotReturn = false;
QM_TRY_UNWRAP(int32_t x, (Result<int32_t, nsresult>{42}), QM_VOID);
static_assert(std::is_same_v<decltype(x), int32_t>);
EXPECT_EQ(x, 42);
}
TEST(QuotaCommon_TryUnwrap, RvalueDecl)
{
QM_TRY_UNWRAP(int32_t && x, (Result<int32_t, nsresult>{42}), QM_VOID);
static_assert(std::is_same_v<decltype(x), int32_t&&>);
EXPECT_EQ(x, 42);
}
TEST(QuotaCommon_TryUnwrap, ParenDecl)
{
QM_TRY_UNWRAP(
(auto&& [x, y]),
(Result<std::pair<int32_t, bool>, nsresult>{std::pair{42, true}}),
QM_VOID);
static_assert(std::is_same_v<decltype(x), int32_t>);
static_assert(std::is_same_v<decltype(y), bool>);
EXPECT_EQ(x, 42);
EXPECT_EQ(y, true);
}
TEST(QuotaCommon_DebugTryUnwrap, Success)
{
bool debugTryUnwrapBodyRan = false;
bool debugTryUnwrapDidNotReturn = false;
nsresult rv = [
#ifdef DEBUG
&debugTryVarBodyRan, &debugTryVarDidNotReturn
&debugTryUnwrapBodyRan, &debugTryUnwrapDidNotReturn
#else
&debugTryVarDidNotReturn
&debugTryUnwrapDidNotReturn
#endif
]() -> nsresult {
QM_DEBUG_TRY_VAR(const auto x,
([&debugTryVarBodyRan]() -> Result<int32_t, nsresult> {
debugTryVarBodyRan = true;
QM_DEBUG_TRY_UNWRAP(
const auto x, ([&debugTryUnwrapBodyRan]() -> Result<int32_t, nsresult> {
debugTryUnwrapBodyRan = true;
return 42;
}()));
@ -743,35 +757,35 @@ TEST(QuotaCommon_DebugTryVar, Success)
EXPECT_EQ(x, 42);
#endif
debugTryVarDidNotReturn = true;
debugTryUnwrapDidNotReturn = true;
return NS_OK;
}();
#ifdef DEBUG
EXPECT_TRUE(debugTryVarBodyRan);
EXPECT_TRUE(debugTryUnwrapBodyRan);
#else
EXPECT_FALSE(debugTryVarBodyRan);
EXPECT_FALSE(debugTryUnwrapBodyRan);
#endif
EXPECT_TRUE(debugTryVarDidNotReturn);
EXPECT_TRUE(debugTryUnwrapDidNotReturn);
EXPECT_EQ(rv, NS_OK);
}
TEST(QuotaCommon_DebugTryVar, Failure)
TEST(QuotaCommon_DebugTryUnwrap, Failure)
{
bool debugTryVarBodyRan = false;
bool debugTryVarDidNotReturn = false;
bool debugTryUnwrapBodyRan = false;
bool debugTryUnwrapDidNotReturn = false;
nsresult rv = [
#ifdef DEBUG
&debugTryVarBodyRan, &debugTryVarDidNotReturn
&debugTryUnwrapBodyRan, &debugTryUnwrapDidNotReturn
#else
&debugTryVarDidNotReturn
&debugTryUnwrapDidNotReturn
#endif
]() -> nsresult {
QM_DEBUG_TRY_VAR(const auto x,
([&debugTryVarBodyRan]() -> Result<int32_t, nsresult> {
debugTryVarBodyRan = true;
QM_DEBUG_TRY_UNWRAP(
const auto x, ([&debugTryUnwrapBodyRan]() -> Result<int32_t, nsresult> {
debugTryUnwrapBodyRan = true;
return Err(NS_ERROR_FAILURE);
}()));
@ -779,18 +793,18 @@ TEST(QuotaCommon_DebugTryVar, Failure)
Unused << x;
#endif
debugTryVarDidNotReturn = true;
debugTryUnwrapDidNotReturn = true;
return NS_OK;
}();
#ifdef DEBUG
EXPECT_TRUE(debugTryVarBodyRan);
EXPECT_FALSE(debugTryVarDidNotReturn);
EXPECT_TRUE(debugTryUnwrapBodyRan);
EXPECT_FALSE(debugTryUnwrapDidNotReturn);
EXPECT_EQ(rv, NS_ERROR_FAILURE);
#else
EXPECT_FALSE(debugTryVarBodyRan);
EXPECT_TRUE(debugTryVarDidNotReturn);
EXPECT_FALSE(debugTryUnwrapBodyRan);
EXPECT_TRUE(debugTryUnwrapDidNotReturn);
EXPECT_EQ(rv, NS_OK);
#endif
}

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

@ -1653,8 +1653,8 @@ Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
QuotaManager* quotaManager = QuotaManager::Get();
MOZ_ASSERT(quotaManager);
SDB_TRY_VAR(auto directory,
quotaManager->GetDirectoryForOrigin(aPersistenceType, aOrigin));
SDB_TRY_UNWRAP(auto directory, quotaManager->GetDirectoryForOrigin(
aPersistenceType, aOrigin));
MOZ_ASSERT(directory);

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

@ -24,13 +24,13 @@
#define SDB_TRY_VAR_GLUE(accessFunction, ...) \
QM_TRY_VAR_META(mozilla::dom::simpledb, MOZ_UNIQUE_VAR(tryResult), \
accessFunction, ##__VA_ARGS__)
#define SDB_TRY_VAR(...) SDB_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define SDB_TRY_UNWRAP(...) SDB_TRY_VAR_GLUE(unwrap, __VA_ARGS__)
#define SDB_TRY_INSPECT(...) SDB_TRY_VAR_GLUE(inspect, __VA_ARGS__)
#ifdef DEBUG
# define SDB_DEBUG_TRY_VAR(...) SDB_TRY_VAR(__VA_ARGS__)
# define SDB_DEBUG_TRY_UNWRAP(...) SDB_TRY_UNWRAP(__VA_ARGS__)
#else
# define SDB_DEBUG_TRY_VAR(...)
# define SDB_DEBUG_TRY_UNWRAP(...)
#endif
// SimpleDB equivalents of QM_TRY_RETURN and QM_DEBUG_TRY_RETURN.