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, ...) \ #define CACHE_TRY_VAR_GLUE(accessFunction, ...) \
QM_TRY_VAR_META(mozilla::dom::cache, MOZ_UNIQUE_VAR(tryResult), \ QM_TRY_VAR_META(mozilla::dom::cache, MOZ_UNIQUE_VAR(tryResult), \
accessFunction, ##__VA_ARGS__) 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__) #define CACHE_TRY_INSPECT(...) CACHE_TRY_VAR_GLUE(inspect, __VA_ARGS__)
#ifdef DEBUG #ifdef DEBUG
# define CACHE_DEBUG_TRY_VAR(...) CACHE_TRY_VAR(__VA_ARGS__) # define CACHE_DEBUG_TRY_UNWRAP(...) CACHE_TRY_UNWRAP(__VA_ARGS__)
#else #else
# define CACHE_DEBUG_TRY_VAR(...) # define CACHE_DEBUG_TRY_UNWRAP(...)
#endif #endif
// Cache equivalents of QM_TRY_RETURN and QM_DEBUG_TRY_RETURN. // 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()); MOZ_ASSERT(!NS_IsMainThread());
int32_t schemaVersion; int32_t schemaVersion;
CACHE_TRY_VAR(schemaVersion, GetEffectiveSchemaVersion(aConn)); CACHE_TRY_UNWRAP(schemaVersion, GetEffectiveSchemaVersion(aConn));
if (schemaVersion == kLatestSchemaVersion) { if (schemaVersion == kLatestSchemaVersion) {
// We already have the correct schema version. Validate it matches // We already have the correct schema version. Validate it matches
@ -548,7 +548,7 @@ nsresult CreateOrMigrateSchema(mozIStorageConnection& aConn) {
return rv; return rv;
} }
CACHE_TRY_VAR(schemaVersion, GetEffectiveSchemaVersion(aConn)); CACHE_TRY_UNWRAP(schemaVersion, GetEffectiveSchemaVersion(aConn));
} }
nsresult rv = Validate(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 // anyway. These body IDs must be deleted one-by-one as content may
// still be referencing them invidivually. // still be referencing them invidivually.
AutoTArray<EntryId, 256> matches; AutoTArray<EntryId, 256> matches;
CACHE_TRY_VAR(matches, QueryAll(aConn, aCacheId)); CACHE_TRY_UNWRAP(matches, QueryAll(aConn, aCacheId));
AutoTArray<nsID, 16> deletedBodyIdList; AutoTArray<nsID, 16> deletedBodyIdList;
AutoTArray<IdCount, 16> deletedSecurityIdList; AutoTArray<IdCount, 16> deletedSecurityIdList;
@ -811,7 +811,7 @@ Result<nsTArray<nsID>, nsresult> GetKnownBodyIds(mozIStorageConnection& aConn) {
if (!isNull) { if (!isNull) {
nsID id; nsID id;
CACHE_TRY_VAR(id, ExtractId(*state, i)); CACHE_TRY_UNWRAP(id, ExtractId(*state, i));
idList.AppendElement(id); idList.AppendElement(id);
} }
@ -827,14 +827,14 @@ Result<Maybe<SavedResponse>, nsresult> CacheMatch(
MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(!NS_IsMainThread());
AutoTArray<EntryId, 1> matches; 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()) { if (matches.IsEmpty()) {
return Maybe<SavedResponse>(); return Maybe<SavedResponse>();
} }
SavedResponse response; SavedResponse response;
CACHE_TRY_VAR(response, ReadResponse(aConn, matches[0])); CACHE_TRY_UNWRAP(response, ReadResponse(aConn, matches[0]));
response.mCacheId = aCacheId; response.mCacheId = aCacheId;
@ -848,9 +848,9 @@ Result<nsTArray<SavedResponse>, nsresult> CacheMatchAll(
AutoTArray<EntryId, 256> matches; AutoTArray<EntryId, 256> matches;
if (aMaybeRequest.isNothing()) { if (aMaybeRequest.isNothing()) {
CACHE_TRY_VAR(matches, QueryAll(aConn, aCacheId)); CACHE_TRY_UNWRAP(matches, QueryAll(aConn, aCacheId));
} else { } else {
CACHE_TRY_VAR(matches, CACHE_TRY_UNWRAP(matches,
QueryCache(aConn, aCacheId, aMaybeRequest.ref(), aParams)); 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) // TODO: replace this with a bulk load using SQL IN clause (bug 1110458)
for (const auto match : matches) { for (const auto match : matches) {
SavedResponse savedResponse; SavedResponse savedResponse;
CACHE_TRY_VAR(savedResponse, ReadResponse(aConn, match)); CACHE_TRY_UNWRAP(savedResponse, ReadResponse(aConn, match));
savedResponse.mCacheId = aCacheId; savedResponse.mCacheId = aCacheId;
savedResponses.AppendElement(savedResponse); savedResponses.AppendElement(savedResponse);
@ -878,7 +878,7 @@ Result<DeletionInfo, nsresult> CachePut(mozIStorageConnection& aConn,
CacheQueryParams params(false, false, false, false, u""_ns); CacheQueryParams params(false, false, false, false, u""_ns);
AutoTArray<EntryId, 256> matches; 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; nsTArray<nsID> deletedBodyIdList;
AutoTArray<IdCount, 16> deletedSecurityIdList; AutoTArray<IdCount, 16> deletedSecurityIdList;
@ -911,7 +911,7 @@ Result<Maybe<DeletionInfo>, nsresult> CacheDelete(
MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(!NS_IsMainThread());
AutoTArray<EntryId, 256> matches; 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()) { if (matches.IsEmpty()) {
return Maybe<DeletionInfo>(); return Maybe<DeletionInfo>();
@ -941,9 +941,9 @@ Result<nsTArray<SavedRequest>, nsresult> CacheKeys(
AutoTArray<EntryId, 256> matches; AutoTArray<EntryId, 256> matches;
if (aMaybeRequest.isNothing()) { if (aMaybeRequest.isNothing()) {
CACHE_TRY_VAR(matches, QueryAll(aConn, aCacheId)); CACHE_TRY_UNWRAP(matches, QueryAll(aConn, aCacheId));
} else { } else {
CACHE_TRY_VAR(matches, CACHE_TRY_UNWRAP(matches,
QueryCache(aConn, aCacheId, aMaybeRequest.ref(), aParams)); 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) // TODO: replace this with a bulk load using SQL IN clause (bug 1110458)
for (const auto match : matches) { for (const auto match : matches) {
SavedRequest savedRequest; SavedRequest savedRequest;
CACHE_TRY_VAR(savedRequest, ReadRequest(aConn, match)); CACHE_TRY_UNWRAP(savedRequest, ReadRequest(aConn, match));
savedRequest.mCacheId = aCacheId; savedRequest.mCacheId = aCacheId;
savedRequests.AppendElement(savedRequest); savedRequests.AppendElement(savedRequest);
@ -971,7 +971,7 @@ Result<Maybe<SavedResponse>, nsresult> StorageMatch(
// and perform the match. // and perform the match.
if (!aParams.cacheName().EqualsLiteral("")) { if (!aParams.cacheName().EqualsLiteral("")) {
Maybe<CacheId> maybeCacheId; Maybe<CacheId> maybeCacheId;
CACHE_TRY_VAR(maybeCacheId, CACHE_TRY_UNWRAP(maybeCacheId,
StorageGetCacheId(aConn, aNamespace, aParams.cacheName())); StorageGetCacheId(aConn, aNamespace, aParams.cacheName()));
if (maybeCacheId.isNothing()) { if (maybeCacheId.isNothing()) {
return Maybe<SavedResponse>(); return Maybe<SavedResponse>();
@ -1011,7 +1011,7 @@ Result<Maybe<SavedResponse>, nsresult> StorageMatch(
// Now try to find a match in each cache in order // Now try to find a match in each cache in order
for (const auto cacheId : cacheIdList) { for (const auto cacheId : cacheIdList) {
Maybe<SavedResponse> matchedResponse; Maybe<SavedResponse> matchedResponse;
CACHE_TRY_VAR(matchedResponse, CACHE_TRY_UNWRAP(matchedResponse,
CacheMatch(aConn, cacheId, aRequest, aParams)); CacheMatch(aConn, cacheId, aRequest, aParams));
if (matchedResponse.isSome()) { if (matchedResponse.isSome()) {
@ -1036,7 +1036,7 @@ Result<Maybe<CacheId>, nsresult> StorageGetCacheId(mozIStorageConnection& aConn,
"ORDER BY rowid;"; "ORDER BY rowid;";
nsCOMPtr<mozIStorageStatement> state; 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); nsresult rv = state->BindInt32ByName("namespace"_ns, aNamespace);
if (NS_WARN_IF(NS_FAILED(rv))) { 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;"; const char* query = "DELETE FROM storage WHERE namespace=:namespace AND %s;";
nsCOMPtr<mozIStorageStatement> state; 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); nsresult rv = state->BindInt32ByName("namespace"_ns, aNamespace);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -1292,7 +1292,8 @@ Result<nsTArray<EntryId>, nsresult> QueryCache(mozIStorageConnection& aConn,
if (!aParams.ignoreVary() && varyCount > 0) { if (!aParams.ignoreVary() && varyCount > 0) {
bool matchedByVary = false; bool matchedByVary = false;
CACHE_TRY_VAR(matchedByVary, MatchByVaryHeader(aConn, aRequest, entryId)); CACHE_TRY_UNWRAP(matchedByVary,
MatchByVaryHeader(aConn, aRequest, entryId));
if (!matchedByVary) { if (!matchedByVary) {
continue; continue;
} }
@ -1516,7 +1517,7 @@ nsresult DeleteEntries(mozIStorageConnection& aConn,
if (!isNull) { if (!isNull) {
nsID id; nsID id;
CACHE_TRY_VAR(id, ExtractId(*state, i)); CACHE_TRY_UNWRAP(id, ExtractId(*state, i));
aDeletedBodyIdListOut.AppendElement(id); aDeletedBodyIdListOut.AppendElement(id);
} }
@ -1844,8 +1845,8 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
int32_t securityId = -1; int32_t securityId = -1;
if (!aResponse.channelInfo().securityInfo().IsEmpty()) { if (!aResponse.channelInfo().securityInfo().IsEmpty()) {
CACHE_TRY_VAR(securityId, CACHE_TRY_UNWRAP(
InsertSecurityInfo(aConn, *crypto, securityId, InsertSecurityInfo(aConn, *crypto,
aResponse.channelInfo().securityInfo())); aResponse.channelInfo().securityInfo()));
} }
@ -2265,7 +2266,7 @@ Result<SavedResponse, nsresult> ReadResponse(mozIStorageConnection& aConn,
savedResponse.mHasBodyId = !nullBody; savedResponse.mHasBodyId = !nullBody;
if (savedResponse.mHasBodyId) { if (savedResponse.mHasBodyId) {
CACHE_TRY_VAR(savedResponse.mBodyId, ExtractId(*state, 4)); CACHE_TRY_UNWRAP(savedResponse.mBodyId, ExtractId(*state, 4));
} }
nsAutoCString serializedInfo; nsAutoCString serializedInfo;
@ -2516,7 +2517,7 @@ Result<SavedRequest, nsresult> ReadRequest(mozIStorageConnection& aConn,
} }
savedRequest.mHasBodyId = !nullBody; savedRequest.mHasBodyId = !nullBody;
if (savedRequest.mHasBodyId) { if (savedRequest.mHasBodyId) {
CACHE_TRY_VAR(savedRequest.mBodyId, ExtractId(*state, 13)); CACHE_TRY_UNWRAP(savedRequest.mBodyId, ExtractId(*state, 13));
} }
rv = aConn.CreateStatement(nsLiteralCString("SELECT " rv = aConn.CreateStatement(nsLiteralCString("SELECT "
"name, " "name, "
@ -2815,7 +2816,7 @@ struct Expect {
nsresult Validate(mozIStorageConnection& aConn) { nsresult Validate(mozIStorageConnection& aConn) {
int32_t schemaVersion; int32_t schemaVersion;
CACHE_TRY_VAR(schemaVersion, GetEffectiveSchemaVersion(aConn)); CACHE_TRY_UNWRAP(schemaVersion, GetEffectiveSchemaVersion(aConn));
if (NS_WARN_IF(schemaVersion != kLatestSchemaVersion)) { if (NS_WARN_IF(schemaVersion != kLatestSchemaVersion)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -2973,7 +2974,7 @@ nsresult Migrate(mozIStorageConnection& aConn) {
MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(!NS_IsMainThread());
int32_t currentVersion = 0; int32_t currentVersion = 0;
CACHE_TRY_VAR(currentVersion, GetEffectiveSchemaVersion(aConn)); CACHE_TRY_UNWRAP(currentVersion, GetEffectiveSchemaVersion(aConn));
bool rewriteSchema = false; bool rewriteSchema = false;
@ -3000,7 +3001,7 @@ nsresult Migrate(mozIStorageConnection& aConn) {
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
int32_t lastVersion = currentVersion; int32_t lastVersion = currentVersion;
#endif #endif
CACHE_TRY_VAR(currentVersion, GetEffectiveSchemaVersion(aConn)); CACHE_TRY_UNWRAP(currentVersion, GetEffectiveSchemaVersion(aConn));
MOZ_DIAGNOSTIC_ASSERT(currentVersion > lastVersion); 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 // We don't need to add the aIncreaseSize or aDecreaseSize here, because
// it's already encompassed within the database. // it's already encompassed within the database.
CACHE_TRY_VAR(currentPaddingSize, db::FindOverallPaddingSize(*aConn)); CACHE_TRY_UNWRAP(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
} else { } else {
bool shouldRevise = false; bool shouldRevise = false;
if (aIncreaseSize > 0) { if (aIncreaseSize > 0) {
@ -900,7 +900,7 @@ nsresult LockedUpdateDirectoryPaddingFile(nsIFile* aBaseDir,
return rv; 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) // 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 // padding size in the QM. For now, only correct the padding size in
@ -912,7 +912,7 @@ nsresult LockedUpdateDirectoryPaddingFile(nsIFile* aBaseDir,
#ifdef DEBUG #ifdef DEBUG
int64_t lastPaddingSize = currentPaddingSize; int64_t lastPaddingSize = currentPaddingSize;
CACHE_TRY_VAR(currentPaddingSize, db::FindOverallPaddingSize(*aConn)); CACHE_TRY_UNWRAP(currentPaddingSize, db::FindOverallPaddingSize(*aConn));
MOZ_DIAGNOSTIC_ASSERT(currentPaddingSize == lastPaddingSize); MOZ_DIAGNOSTIC_ASSERT(currentPaddingSize == lastPaddingSize);
#endif // DEBUG #endif // DEBUG
@ -984,7 +984,7 @@ nsresult LockedDirectoryPaddingRestore(nsIFile* aBaseDir,
return rv; return rv;
} }
CACHE_TRY_VAR(*aPaddingSizeOut, db::FindOverallPaddingSize(*aConn)); CACHE_TRY_UNWRAP(*aPaddingSizeOut, db::FindOverallPaddingSize(*aConn));
MOZ_DIAGNOSTIC_ASSERT(*aPaddingSizeOut >= 0); MOZ_DIAGNOSTIC_ASSERT(*aPaddingSizeOut >= 0);
rv = LockedDirectoryPaddingWrite(aBaseDir, DirPaddingFile::FILE, rv = LockedDirectoryPaddingWrite(aBaseDir, DirPaddingFile::FILE,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -527,7 +527,8 @@ bool IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
return false; 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!"); MOZ_ASSERT(factory, "This should never fail for chrome!");

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

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

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

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

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

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

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

@ -540,7 +540,7 @@
accessFunction, ##__VA_ARGS__) 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 * 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 * 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 * 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| * result or a custom return value (if the third argument was passed). |target|
* must be an lvalue. * 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 * QM_TRY_INSPECT is similar to QM_TRY_VAR, but it does not unwrap a success
@ -559,7 +559,7 @@
* *
* should be preferred over * should be preferred over
* *
* QM_TRY_VAR(const auto target, DoSomething()) * QM_TRY_UNWRAP(const auto target, DoSomething())
* *
* as it avoids unnecessary moves/copies. * as it avoids unnecessary moves/copies.
*/ */
@ -570,9 +570,9 @@
* in non-debug builds. * in non-debug builds.
*/ */
#ifdef DEBUG #ifdef DEBUG
# define QM_DEBUG_TRY_VAR(...) QM_TRY_VAR(__VA_ARGS__) # define QM_DEBUG_TRY_UNWRAP(...) QM_TRY_UNWRAP(__VA_ARGS__)
#else #else
# define QM_DEBUG_TRY_VAR(...) # define QM_DEBUG_TRY_UNWRAP(...)
#endif #endif
// QM_TRY_RETURN_PROPAGATE_ERR, QM_TRY_RETURN_CUSTOM_RET_VAL, // 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); 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) TEST(QuotaCommon_TryInspect, ConstDecl)
{ {
QM_TRY_INSPECT(const int32_t& x, (Result<int32_t, nsresult>{42}), QM_VOID); 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); 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) TEST(QuotaCommon_TryInspect, NestingMadness_Success)
{ {
bool nestedTryInspectDidNotReturn = false; bool nestedTryInspectDidNotReturn = false;
@ -721,21 +699,57 @@ TEST(QuotaCommon_TryInspect, NestingMadness_Multiple_Failure2)
EXPECT_EQ(rv, NS_ERROR_FAILURE); 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; QM_TRY_UNWRAP(int32_t x, (Result<int32_t, nsresult>{42}), QM_VOID);
bool debugTryVarDidNotReturn = false;
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 = [ nsresult rv = [
#ifdef DEBUG #ifdef DEBUG
&debugTryVarBodyRan, &debugTryVarDidNotReturn &debugTryUnwrapBodyRan, &debugTryUnwrapDidNotReturn
#else #else
&debugTryVarDidNotReturn &debugTryUnwrapDidNotReturn
#endif #endif
]() -> nsresult { ]() -> nsresult {
QM_DEBUG_TRY_VAR(const auto x, QM_DEBUG_TRY_UNWRAP(
([&debugTryVarBodyRan]() -> Result<int32_t, nsresult> { const auto x, ([&debugTryUnwrapBodyRan]() -> Result<int32_t, nsresult> {
debugTryVarBodyRan = true; debugTryUnwrapBodyRan = true;
return 42; return 42;
}())); }()));
@ -743,35 +757,35 @@ TEST(QuotaCommon_DebugTryVar, Success)
EXPECT_EQ(x, 42); EXPECT_EQ(x, 42);
#endif #endif
debugTryVarDidNotReturn = true; debugTryUnwrapDidNotReturn = true;
return NS_OK; return NS_OK;
}(); }();
#ifdef DEBUG #ifdef DEBUG
EXPECT_TRUE(debugTryVarBodyRan); EXPECT_TRUE(debugTryUnwrapBodyRan);
#else #else
EXPECT_FALSE(debugTryVarBodyRan); EXPECT_FALSE(debugTryUnwrapBodyRan);
#endif #endif
EXPECT_TRUE(debugTryVarDidNotReturn); EXPECT_TRUE(debugTryUnwrapDidNotReturn);
EXPECT_EQ(rv, NS_OK); EXPECT_EQ(rv, NS_OK);
} }
TEST(QuotaCommon_DebugTryVar, Failure) TEST(QuotaCommon_DebugTryUnwrap, Failure)
{ {
bool debugTryVarBodyRan = false; bool debugTryUnwrapBodyRan = false;
bool debugTryVarDidNotReturn = false; bool debugTryUnwrapDidNotReturn = false;
nsresult rv = [ nsresult rv = [
#ifdef DEBUG #ifdef DEBUG
&debugTryVarBodyRan, &debugTryVarDidNotReturn &debugTryUnwrapBodyRan, &debugTryUnwrapDidNotReturn
#else #else
&debugTryVarDidNotReturn &debugTryUnwrapDidNotReturn
#endif #endif
]() -> nsresult { ]() -> nsresult {
QM_DEBUG_TRY_VAR(const auto x, QM_DEBUG_TRY_UNWRAP(
([&debugTryVarBodyRan]() -> Result<int32_t, nsresult> { const auto x, ([&debugTryUnwrapBodyRan]() -> Result<int32_t, nsresult> {
debugTryVarBodyRan = true; debugTryUnwrapBodyRan = true;
return Err(NS_ERROR_FAILURE); return Err(NS_ERROR_FAILURE);
}())); }()));
@ -779,18 +793,18 @@ TEST(QuotaCommon_DebugTryVar, Failure)
Unused << x; Unused << x;
#endif #endif
debugTryVarDidNotReturn = true; debugTryUnwrapDidNotReturn = true;
return NS_OK; return NS_OK;
}(); }();
#ifdef DEBUG #ifdef DEBUG
EXPECT_TRUE(debugTryVarBodyRan); EXPECT_TRUE(debugTryUnwrapBodyRan);
EXPECT_FALSE(debugTryVarDidNotReturn); EXPECT_FALSE(debugTryUnwrapDidNotReturn);
EXPECT_EQ(rv, NS_ERROR_FAILURE); EXPECT_EQ(rv, NS_ERROR_FAILURE);
#else #else
EXPECT_FALSE(debugTryVarBodyRan); EXPECT_FALSE(debugTryUnwrapBodyRan);
EXPECT_TRUE(debugTryVarDidNotReturn); EXPECT_TRUE(debugTryUnwrapDidNotReturn);
EXPECT_EQ(rv, NS_OK); EXPECT_EQ(rv, NS_OK);
#endif #endif
} }

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

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

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

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