Bug 1731969 - Rename ToResultInvoke member function overloads to ToResultInvokeMember; r=dom-storage-reviewers,jari

Differential Revision: https://phabricator.services.mozilla.com/D126328
This commit is contained in:
Jan Varga 2021-11-30 05:05:53 +00:00
parent 0115137758
commit a7f7389681
21 changed files with 1093 additions and 1022 deletions

View File

@ -35,7 +35,7 @@ namespace {
nsresult WipeDatabase(const CacheDirectoryMetadata& aDirectoryMetadata,
nsIFile& aDBFile) {
QM_TRY_INSPECT(const auto& dbDir, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_INSPECT(const auto& dbDir, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<nsIFile>, aDBFile, GetParent));
QM_TRY(MOZ_TO_RESULT(RemoveNsIFile(aDirectoryMetadata, aDBFile)));
@ -112,7 +112,8 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> DBAction::OpenConnection(
MOZ_ASSERT(!NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(aDirectoryMetadata.mDirectoryLockId >= 0);
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(aDBDir, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(aDBDir, Exists));
if (!exists) {
QM_TRY(OkIf(mMode == Create), Err(NS_ERROR_FILE_NOT_FOUND));
@ -154,9 +155,9 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
auto handler = MakeRefPtr<nsFileProtocolHandler>();
QM_TRY(MOZ_TO_RESULT(handler->Init()));
QM_TRY_INSPECT(const auto& mutator,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIURIMutator>, handler,
NewFileURIMutator, &aDBFile));
QM_TRY_INSPECT(const auto& mutator, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<nsIURIMutator>, handler,
NewFileURIMutator, &aDBFile));
const nsCString directoryLockIdClause =
aDirectoryMetadata.mDirectoryLockId >= 0
@ -179,9 +180,9 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
auto conn,
QM_OR_ELSE_WARN_IF(
// Expression.
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>,
storageService, OpenDatabaseWithFileURL,
dbFileUrl, ""_ns),
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, storageService,
OpenDatabaseWithFileURL, dbFileUrl, ""_ns),
// Predicate.
IsDatabaseCorruptionError,
// Fallback.
@ -194,21 +195,21 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> OpenDBConnection(
// can be deleted by QuotaManager at any time anyways.
QM_TRY(MOZ_TO_RESULT(WipeDatabase(aDirectoryMetadata, aDBFile)));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, storageService,
OpenDatabaseWithFileURL, dbFileUrl, ""_ns));
})));
// Check the schema to make sure it is not too old.
QM_TRY_INSPECT(const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE(conn, GetSchemaVersion));
MOZ_TO_RESULT_INVOKE_MEMBER(conn, GetSchemaVersion));
if (schemaVersion > 0 && schemaVersion < db::kFirstShippedSchemaVersion) {
// Close existing connection before wiping database.
conn = nullptr;
QM_TRY(MOZ_TO_RESULT(WipeDatabase(aDirectoryMetadata, aDBFile)));
QM_TRY_UNWRAP(conn, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_UNWRAP(conn, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, storageService,
OpenDatabaseWithFileURL, dbFileUrl, ""_ns));
}

383
dom/cache/DBSchema.cpp vendored
View File

@ -420,7 +420,7 @@ class MOZ_RAII AutoDisableForeignKeyChecking {
QM_VOID);
QM_TRY_INSPECT(const int32_t& mode,
MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0), QM_VOID);
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0), QM_VOID);
if (mode) {
QM_WARNONLY_TRY(MOZ_TO_RESULT(mConn->ExecuteSimpleSQL(
@ -457,8 +457,8 @@ nsresult IntegrityCheck(mozIStorageConnection& aConn) {
"SELECT COUNT(*) FROM pragma_integrity_check() "
"WHERE integrity_check != 'ok';"_ns));
QM_TRY_INSPECT(const auto& result,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, *stmt, GetString, 0));
QM_TRY_INSPECT(const auto& result, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, *stmt, GetString, 0));
nsresult rv;
const uint32_t count = result.ToInteger(&rv);
@ -593,7 +593,7 @@ nsresult InitializeConnection(mozIStorageConnection& aConn) {
aConn, "PRAGMA auto_vacuum;"_ns));
QM_TRY_INSPECT(const int32_t& mode,
MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0));
// integer value 2 is incremental mode
QM_TRY(OkIf(mode == 2), NS_ERROR_UNEXPECTED);
@ -616,7 +616,8 @@ Result<CacheId, nsresult> CreateCacheId(mozIStorageConnection& aConn) {
QM_TRY(OkIf(state), Err(NS_ERROR_UNEXPECTED));
QM_TRY_INSPECT(const CacheId& id, MOZ_TO_RESULT_INVOKE(state, GetInt64, 0));
QM_TRY_INSPECT(const CacheId& id,
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt64, 0));
return id;
}
@ -639,7 +640,7 @@ Result<DeletionInfo, nsresult> DeleteCacheId(mozIStorageConnection& aConn,
// Delete the remainder of the cache using cascade semantics.
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"DELETE FROM caches WHERE id=:id;"_ns));
@ -653,7 +654,7 @@ Result<DeletionInfo, nsresult> DeleteCacheId(mozIStorageConnection& aConn,
Result<AutoTArray<CacheId, 8>, nsresult> FindOrphanedCacheIds(
mozIStorageConnection& aConn) {
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT id FROM caches "
"WHERE id NOT IN (SELECT cache_id from storage);"_ns));
@ -661,13 +662,13 @@ Result<AutoTArray<CacheId, 8>, nsresult> FindOrphanedCacheIds(
QM_TRY_RETURN(
(quota::CollectElementsWhileHasResultTyped<AutoTArray<CacheId, 8>>(
*state, [](auto& stmt) {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 0));
})));
}
Result<int64_t, nsresult> FindOverallPaddingSize(mozIStorageConnection& aConn) {
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT response_padding_size FROM entries "
"WHERE response_padding_size IS NOT NULL;"_ns));
@ -677,7 +678,7 @@ Result<int64_t, nsresult> FindOverallPaddingSize(mozIStorageConnection& aConn) {
QM_TRY(quota::CollectWhileHasResult(
*state, [&overallPaddingSize](auto& stmt) -> Result<Ok, nsresult> {
QM_TRY_INSPECT(const int64_t& padding_size,
MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 0));
MOZ_DIAGNOSTIC_ASSERT(padding_size >= 0);
MOZ_DIAGNOSTIC_ASSERT(INT64_MAX - padding_size >= overallPaddingSize);
@ -694,7 +695,7 @@ Result<nsTArray<nsID>, nsresult> GetKnownBodyIds(mozIStorageConnection& aConn) {
QM_TRY_INSPECT(
const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT request_body_id, response_body_id FROM entries;"_ns));
@ -705,7 +706,7 @@ Result<nsTArray<nsID>, nsresult> GetKnownBodyIds(mozIStorageConnection& aConn) {
// extract 0 to 2 nsID structs per row
for (uint32_t i = 0; i < 2; ++i) {
QM_TRY_INSPECT(const bool& isNull,
MOZ_TO_RESULT_INVOKE(stmt, GetIsNull, i));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetIsNull, i));
if (!isNull) {
QM_TRY_INSPECT(const auto& id, ExtractId(stmt, i));
@ -863,7 +864,7 @@ Result<Maybe<SavedResponse>, nsresult> StorageMatch(
// Otherwise we need to get a list of all the cache IDs in this namespace.
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT cache_id FROM storage WHERE "
"namespace=:namespace ORDER BY rowid;"_ns));
@ -874,7 +875,7 @@ Result<Maybe<SavedResponse>, nsresult> StorageMatch(
const auto& cacheIdList,
(quota::CollectElementsWhileHasResultTyped<AutoTArray<CacheId, 32>>(
*state, [](auto& stmt) {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 0));
})));
// Now try to find a match in each cache in order
@ -909,13 +910,14 @@ Result<Maybe<CacheId>, nsresult> StorageGetCacheId(mozIStorageConnection& aConn,
QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("namespace"_ns, aNamespace)));
QM_TRY_INSPECT(const bool& hasMoreData,
MOZ_TO_RESULT_INVOKE(*state, ExecuteStep));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, ExecuteStep));
if (!hasMoreData) {
return Maybe<CacheId>();
}
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(*state, GetInt64, 0).map(Some<CacheId>));
QM_TRY_RETURN(
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt64, 0).map(Some<CacheId>));
}
nsresult StoragePutCache(mozIStorageConnection& aConn, Namespace aNamespace,
@ -923,7 +925,7 @@ nsresult StoragePutCache(mozIStorageConnection& aConn, Namespace aNamespace,
MOZ_ASSERT(!NS_IsMainThread());
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"INSERT INTO storage (namespace, key, cache_id) "
"VALUES (:namespace, :key, :cache_id);"_ns));
@ -962,7 +964,7 @@ Result<nsTArray<nsString>, nsresult> StorageGetKeys(
QM_TRY_INSPECT(
const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT key FROM storage WHERE namespace=:namespace ORDER BY rowid;"_ns));
@ -970,7 +972,7 @@ Result<nsTArray<nsString>, nsresult> StorageGetKeys(
QM_TRY_RETURN(quota::CollectElementsWhileHasResult(*state, [](auto& stmt) {
QM_TRY_RETURN(
MOZ_TO_RESULT_INVOKE_TYPED(nsString, stmt, GetBlobAsString, 0));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, stmt, GetBlobAsString, 0));
}));
}
@ -982,7 +984,7 @@ Result<EntryIds, nsresult> QueryAll(mozIStorageConnection& aConn,
QM_TRY_INSPECT(
const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT id FROM entries WHERE cache_id=:cache_id ORDER BY id;"_ns));
@ -990,7 +992,7 @@ Result<EntryIds, nsresult> QueryAll(mozIStorageConnection& aConn,
QM_TRY_RETURN((quota::CollectElementsWhileHasResultTyped<EntryIds>(
*state, [](auto& stmt) {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(stmt, GetInt32, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt32, 0));
})));
}
@ -1028,9 +1030,9 @@ Result<EntryIds, nsresult> QueryCache(mozIStorageConnection& aConn,
query.AppendLiteral("GROUP BY entries.id ORDER BY entries.id;");
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement, query));
QM_TRY_INSPECT(const auto& state, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn,
CreateStatement, query));
QM_TRY(MOZ_TO_RESULT(state->BindInt64ByName("cache_id"_ns, aCacheId)));
@ -1068,15 +1070,15 @@ Result<EntryIds, nsresult> QueryCache(mozIStorageConnection& aConn,
if (entryIdList.Length() == aMaxResults) {
return false;
}
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(state, ExecuteStep));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(state, ExecuteStep));
},
[&state, &entryIdList, ignoreVary = aParams.ignoreVary(), &aConn,
&aRequest]() -> Result<Ok, nsresult> {
QM_TRY_INSPECT(const EntryId& entryId,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 0));
QM_TRY_INSPECT(const int32_t& varyCount,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 1));
if (!ignoreVary && varyCount > 0) {
QM_TRY_INSPECT(const bool& matchedByVary,
@ -1104,19 +1106,19 @@ Result<bool, nsresult> MatchByVaryHeader(mozIStorageConnection& aConn,
([&aConn, entryId]() -> Result<AutoTArray<nsCString, 8>, nsresult> {
QM_TRY_INSPECT(
const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>, aConn,
CreateStatement,
"SELECT value FROM response_headers "
"WHERE name='vary' COLLATE NOCASE "
"AND entry_id=:entry_id;"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT value FROM response_headers "
"WHERE name='vary' COLLATE NOCASE "
"AND entry_id=:entry_id;"_ns));
QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, entryId)));
QM_TRY_RETURN((
quota::CollectElementsWhileHasResultTyped<AutoTArray<nsCString, 8>>(
*state, [](auto& stmt) {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(nsCString, stmt,
GetUTF8String, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, stmt, GetUTF8String, 0));
})));
}()));
@ -1124,7 +1126,7 @@ Result<bool, nsresult> MatchByVaryHeader(mozIStorageConnection& aConn,
MOZ_DIAGNOSTIC_ASSERT(!varyValues.IsEmpty());
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT name, value FROM request_headers "
"WHERE entry_id=:entry_id;"_ns));
@ -1136,12 +1138,12 @@ Result<bool, nsresult> MatchByVaryHeader(mozIStorageConnection& aConn,
QM_TRY(quota::CollectWhileHasResult(
*state, [&cachedHeaders](auto& stmt) -> Result<Ok, nsresult> {
QM_TRY_INSPECT(
const auto& name,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, stmt, GetUTF8String, 0));
QM_TRY_INSPECT(
const auto& value,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, stmt, GetUTF8String, 1));
QM_TRY_INSPECT(const auto& name,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCString, stmt,
GetUTF8String, 0));
QM_TRY_INSPECT(const auto& value,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCString, stmt,
GetUTF8String, 1));
ErrorResult errorResult;
@ -1250,9 +1252,9 @@ static nsresult DeleteEntriesInternal(
AppendListParamsToQuery(query, aEntryIdList, aPos, aLen);
query.AppendLiteral(")");
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement, query));
QM_TRY_INSPECT(const auto& state, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn,
CreateStatement, query));
QM_TRY(
MOZ_TO_RESULT(BindListParamsToQuery(*state, aEntryIdList, aPos, aLen)));
@ -1266,7 +1268,7 @@ static nsresult DeleteEntriesInternal(
// extract 0 to 2 nsID structs per row
for (uint32_t i = 0; i < 2; ++i) {
QM_TRY_INSPECT(const bool& isNull,
MOZ_TO_RESULT_INVOKE(stmt, GetIsNull, i));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetIsNull, i));
if (!isNull) {
QM_TRY_INSPECT(const auto& id, ExtractId(stmt, i));
@ -1277,11 +1279,11 @@ static nsresult DeleteEntriesInternal(
{ // and then a possible third entry for the security id
QM_TRY_INSPECT(const bool& isNull,
MOZ_TO_RESULT_INVOKE(stmt, GetIsNull, 2));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetIsNull, 2));
if (!isNull) {
QM_TRY_INSPECT(const int32_t& securityId,
MOZ_TO_RESULT_INVOKE(stmt, GetInt32, 2));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt32, 2));
// XXXtt: Consider using map for aDeletedSecuityIdListOut.
auto foundIt =
@ -1305,11 +1307,11 @@ static nsresult DeleteEntriesInternal(
{
// It's possible to have null padding size for non-opaque response
QM_TRY_INSPECT(const bool& isNull,
MOZ_TO_RESULT_INVOKE(stmt, GetIsNull, 3));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetIsNull, 3));
if (!isNull) {
QM_TRY_INSPECT(const int64_t& paddingSize,
MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 3));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 3));
MOZ_DIAGNOSTIC_ASSERT(paddingSize >= 0);
MOZ_DIAGNOSTIC_ASSERT(INT64_MAX - overallPaddingSize >=
@ -1330,9 +1332,9 @@ static nsresult DeleteEntriesInternal(
query.AppendLiteral(")");
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement, query));
QM_TRY_INSPECT(const auto& state, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn,
CreateStatement, query));
QM_TRY(
MOZ_TO_RESULT(BindListParamsToQuery(*state, aEntryIdList, aPos, aLen)));
@ -1392,14 +1394,14 @@ Result<int32_t, nsresult> InsertSecurityInfo(mozIStorageConnection& aConn,
if (selectStmt) {
// get the existing security blob id to return
QM_TRY_INSPECT(const int32_t& id,
MOZ_TO_RESULT_INVOKE(selectStmt, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(selectStmt, GetInt32, 0));
QM_TRY_INSPECT(const int32_t& refcount,
MOZ_TO_RESULT_INVOKE(selectStmt, GetInt32, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(selectStmt, GetInt32, 1));
// But first, update the refcount in the database.
QM_TRY_INSPECT(
const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"UPDATE security_info SET refcount=:refcount WHERE id=:id;"_ns));
@ -1413,7 +1415,7 @@ Result<int32_t, nsresult> InsertSecurityInfo(mozIStorageConnection& aConn,
// This is a new security info blob. Create a new row in the security table
// with an initial refcount of 1.
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"INSERT INTO security_info (hash, data, refcount) "
"VALUES (:hash, :data, 1);"_ns));
@ -1427,7 +1429,7 @@ Result<int32_t, nsresult> InsertSecurityInfo(mozIStorageConnection& aConn,
quota::CreateAndExecuteSingleStepStatement(
aConn, "SELECT last_insert_rowid()"_ns));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0));
}
}
@ -1445,7 +1447,7 @@ nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId,
return Ok{};
}));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0));
}()));
MOZ_DIAGNOSTIC_ASSERT(refcount >= aCount);
@ -1457,7 +1459,7 @@ nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId,
// just remove the entire row.
if (newCount == 0) {
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"DELETE FROM security_info WHERE id=:id;"_ns));
@ -1471,7 +1473,7 @@ nsresult DeleteSecurityInfo(mozIStorageConnection& aConn, int32_t aId,
// number of references to the security blob.
QM_TRY_INSPECT(
const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"UPDATE security_info SET refcount=:refcount WHERE id=:id;"_ns));
@ -1513,61 +1515,61 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement,
"INSERT INTO entries ("
"request_method, "
"request_url_no_query, "
"request_url_no_query_hash, "
"request_url_query, "
"request_url_query_hash, "
"request_url_fragment, "
"request_referrer, "
"request_referrer_policy, "
"request_headers_guard, "
"request_mode, "
"request_credentials, "
"request_contentpolicytype, "
"request_cache, "
"request_redirect, "
"request_integrity, "
"request_body_id, "
"response_type, "
"response_status, "
"response_status_text, "
"response_headers_guard, "
"response_body_id, "
"response_security_info_id, "
"response_principal_info, "
"response_padding_size, "
"cache_id "
") VALUES ("
":request_method, "
":request_url_no_query, "
":request_url_no_query_hash, "
":request_url_query, "
":request_url_query_hash, "
":request_url_fragment, "
":request_referrer, "
":request_referrer_policy, "
":request_headers_guard, "
":request_mode, "
":request_credentials, "
":request_contentpolicytype, "
":request_cache, "
":request_redirect, "
":request_integrity, "
":request_body_id, "
":response_type, "
":response_status, "
":response_status_text, "
":response_headers_guard, "
":response_body_id, "
":response_security_info_id, "
":response_principal_info, "
":response_padding_size, "
":cache_id "
");"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"INSERT INTO entries ("
"request_method, "
"request_url_no_query, "
"request_url_no_query_hash, "
"request_url_query, "
"request_url_query_hash, "
"request_url_fragment, "
"request_referrer, "
"request_referrer_policy, "
"request_headers_guard, "
"request_mode, "
"request_credentials, "
"request_contentpolicytype, "
"request_cache, "
"request_redirect, "
"request_integrity, "
"request_body_id, "
"response_type, "
"response_status, "
"response_status_text, "
"response_headers_guard, "
"response_body_id, "
"response_security_info_id, "
"response_principal_info, "
"response_padding_size, "
"cache_id "
") VALUES ("
":request_method, "
":request_url_no_query, "
":request_url_no_query_hash, "
":request_url_query, "
":request_url_query_hash, "
":request_url_fragment, "
":request_referrer, "
":request_referrer_policy, "
":request_headers_guard, "
":request_mode, "
":request_credentials, "
":request_contentpolicytype, "
":request_cache, "
":request_redirect, "
":request_integrity, "
":request_body_id, "
":response_type, "
":response_status, "
":response_status_text, "
":response_headers_guard, "
":response_body_id, "
":response_security_info_id, "
":response_principal_info, "
":response_padding_size, "
":cache_id "
");"_ns));
QM_TRY(MOZ_TO_RESULT(
state->BindUTF8StringByName("request_method"_ns, aRequest.method())));
@ -1687,18 +1689,18 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
QM_TRY(MOZ_TO_RESULT(state->Execute()));
}
QM_TRY_INSPECT(const int32_t& entryId,
([&aConn]() -> Result<int32_t, nsresult> {
QM_TRY_INSPECT(const auto& state,
quota::CreateAndExecuteSingleStepStatement(
aConn, "SELECT last_insert_rowid()"_ns));
QM_TRY_INSPECT(
const int32_t& entryId, ([&aConn]() -> Result<int32_t, nsresult> {
QM_TRY_INSPECT(const auto& state,
quota::CreateAndExecuteSingleStepStatement(
aConn, "SELECT last_insert_rowid()"_ns));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0));
}()));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0));
}()));
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"INSERT INTO request_headers ("
"name, "
@ -1721,7 +1723,7 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"INSERT INTO response_headers ("
"name, "
@ -1741,12 +1743,12 @@ nsresult InsertEntry(mozIStorageConnection& aConn, CacheId aCacheId,
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement,
"INSERT INTO response_url_list ("
"url, "
"entry_id "
") VALUES (:url, :entry_id)"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"INSERT INTO response_url_list ("
"url, "
"entry_id "
") VALUES (:url, :entry_id)"_ns));
for (const auto& responseUrl : aResponse.urlList()) {
QM_TRY(MOZ_TO_RESULT(state->BindUTF8StringByName("url"_ns, responseUrl)));
@ -1766,10 +1768,10 @@ Result<HeadersEntry, nsresult> GetHeadersEntryFromStatement(
mozIStorageStatement& aStmt) {
HeadersEntry header;
QM_TRY_UNWRAP(header.name(),
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, aStmt, GetUTF8String, 0));
QM_TRY_UNWRAP(header.value(),
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, aStmt, GetUTF8String, 1));
QM_TRY_UNWRAP(header.name(), MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, aStmt, GetUTF8String, 0));
QM_TRY_UNWRAP(header.value(), MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, aStmt, GetUTF8String, 1));
return header;
}
@ -1804,31 +1806,31 @@ Result<SavedResponse, nsresult> ReadResponse(mozIStorageConnection& aConn,
}));
QM_TRY_INSPECT(const int32_t& type,
MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0));
savedResponse.mValue.type() = static_cast<ResponseType>(type);
QM_TRY_INSPECT(const int32_t& status,
MOZ_TO_RESULT_INVOKE(*state, GetInt32, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 1));
savedResponse.mValue.status() = static_cast<uint32_t>(status);
QM_TRY(MOZ_TO_RESULT(
state->GetUTF8String(2, savedResponse.mValue.statusText())));
QM_TRY_INSPECT(const int32_t& guard,
MOZ_TO_RESULT_INVOKE(*state, GetInt32, 3));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 3));
savedResponse.mValue.headersGuard() = static_cast<HeadersGuardEnum>(guard);
QM_TRY_INSPECT(const bool& nullBody,
MOZ_TO_RESULT_INVOKE(*state, GetIsNull, 4));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetIsNull, 4));
savedResponse.mHasBodyId = !nullBody;
if (savedResponse.mHasBodyId) {
QM_TRY_UNWRAP(savedResponse.mBodyId, ExtractId(*state, 4));
}
QM_TRY_INSPECT(
const auto& serializedInfo,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoCString, *state, GetUTF8String, 5));
QM_TRY_INSPECT(const auto& serializedInfo,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsAutoCString, *state,
GetUTF8String, 5));
savedResponse.mValue.principalInfo() = Nothing();
if (!serializedInfo.IsEmpty()) {
@ -1877,7 +1879,7 @@ Result<SavedResponse, nsresult> ReadResponse(mozIStorageConnection& aConn,
}
QM_TRY_INSPECT(const bool& nullPadding,
MOZ_TO_RESULT_INVOKE(*state, GetIsNull, 6));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetIsNull, 6));
if (nullPadding) {
MOZ_DIAGNOSTIC_ASSERT(savedResponse.mValue.type() != ResponseType::Opaque);
@ -1885,7 +1887,7 @@ Result<SavedResponse, nsresult> ReadResponse(mozIStorageConnection& aConn,
} else {
MOZ_DIAGNOSTIC_ASSERT(savedResponse.mValue.type() == ResponseType::Opaque);
QM_TRY_INSPECT(const int64_t& paddingSize,
MOZ_TO_RESULT_INVOKE(*state, GetInt64, 6));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt64, 6));
MOZ_DIAGNOSTIC_ASSERT(paddingSize >= 0);
savedResponse.mValue.paddingSize() = paddingSize;
@ -1896,13 +1898,13 @@ Result<SavedResponse, nsresult> ReadResponse(mozIStorageConnection& aConn,
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement,
"SELECT "
"name, "
"value "
"FROM response_headers "
"WHERE entry_id=:entry_id;"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT "
"name, "
"value "
"FROM response_headers "
"WHERE entry_id=:entry_id;"_ns));
QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, aEntryId)));
@ -1913,19 +1915,19 @@ Result<SavedResponse, nsresult> ReadResponse(mozIStorageConnection& aConn,
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement,
"SELECT "
"url "
"FROM response_url_list "
"WHERE entry_id=:entry_id;"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT "
"url "
"FROM response_url_list "
"WHERE entry_id=:entry_id;"_ns));
QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, aEntryId)));
QM_TRY_UNWRAP(savedResponse.mValue.urlList(),
quota::CollectElementsWhileHasResult(
*state, [](auto& stmt) -> Result<nsCString, nsresult> {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, stmt, GetUTF8String, 0));
}));
}
@ -1979,40 +1981,41 @@ Result<SavedRequest, nsresult> ReadRequest(mozIStorageConnection& aConn,
QM_TRY(MOZ_TO_RESULT(state->GetString(4, savedRequest.mValue.referrer())));
QM_TRY_INSPECT(const int32_t& referrerPolicy,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 5));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 5));
savedRequest.mValue.referrerPolicy() =
static_cast<ReferrerPolicy>(referrerPolicy);
QM_TRY_INSPECT(const int32_t& guard,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 6));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 6));
savedRequest.mValue.headersGuard() = static_cast<HeadersGuardEnum>(guard);
QM_TRY_INSPECT(const int32_t& mode, MOZ_TO_RESULT_INVOKE(state, GetInt32, 7));
QM_TRY_INSPECT(const int32_t& mode,
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 7));
savedRequest.mValue.mode() = static_cast<RequestMode>(mode);
QM_TRY_INSPECT(const int32_t& credentials,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 8));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 8));
savedRequest.mValue.credentials() =
static_cast<RequestCredentials>(credentials);
QM_TRY_INSPECT(const int32_t& requestContentPolicyType,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 9));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 9));
savedRequest.mValue.contentPolicyType() =
static_cast<nsContentPolicyType>(requestContentPolicyType);
QM_TRY_INSPECT(const int32_t& requestCache,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 10));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 10));
savedRequest.mValue.requestCache() = static_cast<RequestCache>(requestCache);
QM_TRY_INSPECT(const int32_t& requestRedirect,
MOZ_TO_RESULT_INVOKE(state, GetInt32, 11));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetInt32, 11));
savedRequest.mValue.requestRedirect() =
static_cast<RequestRedirect>(requestRedirect);
QM_TRY(MOZ_TO_RESULT(state->GetString(12, savedRequest.mValue.integrity())));
QM_TRY_INSPECT(const bool& nullBody,
MOZ_TO_RESULT_INVOKE(state, GetIsNull, 13));
MOZ_TO_RESULT_INVOKE_MEMBER(state, GetIsNull, 13));
savedRequest.mHasBodyId = !nullBody;
if (savedRequest.mHasBodyId) {
QM_TRY_UNWRAP(savedRequest.mBodyId, ExtractId(*state, 13));
@ -2020,13 +2023,13 @@ Result<SavedRequest, nsresult> ReadRequest(mozIStorageConnection& aConn,
{
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConn, CreateStatement,
"SELECT "
"name, "
"value "
"FROM request_headers "
"WHERE entry_id=:entry_id;"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT "
"name, "
"value "
"FROM request_headers "
"WHERE entry_id=:entry_id;"_ns));
QM_TRY(MOZ_TO_RESULT(state->BindInt32ByName("entry_id"_ns, aEntryId)));
@ -2085,9 +2088,9 @@ nsresult BindId(mozIStorageStatement& aState, const nsACString& aName,
Result<nsID, nsresult> ExtractId(mozIStorageStatement& aState, uint32_t aPos) {
MOZ_ASSERT(!NS_IsMainThread());
QM_TRY_INSPECT(
const auto& idString,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoCString, aState, GetUTF8String, aPos));
QM_TRY_INSPECT(const auto& idString,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsAutoCString, aState,
GetUTF8String, aPos));
nsID id;
QM_TRY(OkIf(id.Parse(idString.get())), Err(NS_ERROR_UNEXPECTED));
@ -2110,7 +2113,7 @@ CreateAndBindKeyStatement(mozIStorageConnection& aConn,
QM_TRY_UNWRAP(
auto state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
nsPrintfCString(aQueryFormat,
aKey.IsEmpty() ? "key IS NULL" : "key=:key")));
@ -2144,7 +2147,7 @@ nsresult IncrementalVacuum(mozIStorageConnection& aConn) {
aConn, "PRAGMA freelist_count;"_ns));
QM_TRY_INSPECT(const int32_t& freePages,
MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0));
// We have a relatively small page size, so we want to be careful to avoid
// fragmentation. We already use a growth incremental which will cause
@ -2177,7 +2180,7 @@ nsresult IncrementalVacuum(mozIStorageConnection& aConn) {
aConn, "PRAGMA freelist_count;"_ns));
QM_TRY_INSPECT(const int32_t& freePages,
MOZ_TO_RESULT_INVOKE(*state, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*state, GetInt32, 0));
MOZ_ASSERT(freePages <= kMaxFreePages);
}
@ -2194,7 +2197,7 @@ namespace {
Result<int32_t, nsresult> GetEffectiveSchemaVersion(
mozIStorageConnection& aConn) {
QM_TRY_INSPECT(const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE(aConn, GetSchemaVersion));
MOZ_TO_RESULT_INVOKE_MEMBER(aConn, GetSchemaVersion));
if (schemaVersion == kHackyDowngradeSchemaVersion) {
// This is the special case. Check for the existence of the
@ -2262,21 +2265,21 @@ nsresult Validate(mozIStorageConnection& aConn) {
// Read the schema from the sqlite_master table and compare.
QM_TRY_INSPECT(const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"SELECT name, type, sql FROM sqlite_master;"_ns));
QM_TRY(quota::CollectWhileHasResult(
*state, [&expects](auto& stmt) -> Result<Ok, nsresult> {
QM_TRY_INSPECT(
const auto& name,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoCString, stmt, GetUTF8String, 0));
QM_TRY_INSPECT(
const auto& type,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoCString, stmt, GetUTF8String, 1));
QM_TRY_INSPECT(
const auto& sql,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoCString, stmt, GetUTF8String, 2));
QM_TRY_INSPECT(const auto& name,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsAutoCString, stmt,
GetUTF8String, 0));
QM_TRY_INSPECT(const auto& type,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsAutoCString, stmt,
GetUTF8String, 1));
QM_TRY_INSPECT(const auto& sql,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsAutoCString, stmt,
GetUTF8String, 2));
bool foundMatch = false;
for (const auto& expect : expects) {
@ -2359,7 +2362,7 @@ nsresult RewriteEntriesSchema(mozIStorageConnection& aConn) {
QM_TRY_INSPECT(
const auto& state,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConn, CreateStatement,
"UPDATE sqlite_master SET sql=:sql WHERE name='entries'"_ns));

View File

@ -145,7 +145,7 @@ Result<std::pair<nsID, nsCOMPtr<nsISupports>>, nsresult> BodyStartWriteStream(
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(*finalFile, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(*finalFile, Exists));
QM_TRY(OkIf(!exists), Err(NS_ERROR_FILE_ALREADY_EXISTS));
}
@ -495,7 +495,7 @@ bool MarkerFileExists(const CacheDirectoryMetadata& aDirectoryMetadata) {
QM_TRY_INSPECT(const auto& marker, GetMarkerFileHandle(aDirectoryMetadata),
false);
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(marker, Exists), false);
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(marker, Exists), false);
}
nsresult RemoveNsIFileRecursively(
@ -550,7 +550,7 @@ nsresult RemoveNsIFile(const Maybe<CacheDirectoryMetadata>& aDirectoryMetadata,
const auto& maybeFileSize,
QM_OR_ELSE_WARN_IF(
// Expression.
MOZ_TO_RESULT_INVOKE(aFile, GetFileSize).map(Some<int64_t>),
MOZ_TO_RESULT_INVOKE_MEMBER(aFile, GetFileSize).map(Some<int64_t>),
// Predicate.
IsFileNotFoundError,
// Fallback.
@ -601,7 +601,7 @@ bool DirectoryPaddingFileExists(nsIFile& aBaseDir,
: nsLiteralString(PADDING_FILE_NAME)),
false);
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(file, Exists), false);
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(file, Exists), false);
}
Result<int64_t, nsresult> DirectoryPaddingGet(nsIFile& aBaseDir) {
@ -620,10 +620,8 @@ Result<int64_t, nsresult> DirectoryPaddingGet(nsIFile& aBaseDir) {
const nsCOMPtr<nsIObjectInputStream> objectStream =
NS_NewObjectInputStream(bufferedStream);
QM_TRY_RETURN(
MOZ_TO_RESULT_INVOKE(objectStream, Read64).map([](const uint64_t val) {
return int64_t(val);
}));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(objectStream, Read64)
.map([](const uint64_t val) { return int64_t(val); }));
}
nsresult DirectoryPaddingInit(nsIFile& aBaseDir) {

View File

@ -82,7 +82,7 @@ Result<UsageInfo, nsresult> GetBodyUsage(nsIFile& aMorgueDir,
Unused << leafName;
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(bodyFile, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(bodyFile, GetFileSize));
MOZ_DIAGNOSTIC_ASSERT(fileSize >= 0);
// FIXME: Separate file usage and database usage in OriginInfo so that
// the workaround for treating body file size as database usage can be
@ -134,7 +134,8 @@ Result<int64_t, nsresult> GetPaddingSizeFromDB(
#ifdef DEBUG
{
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(aDBFile, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(aDBFile, Exists));
MOZ_ASSERT(exists);
}
#endif
@ -260,9 +261,9 @@ Result<UsageInfo, nsresult> CacheQuotaClient::InitOrigin(
*dir, aCanceled,
[&aCanceled](
const nsCOMPtr<nsIFile>& file) -> Result<UsageInfo, nsresult> {
QM_TRY_INSPECT(
const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoString, file, GetLeafName));
QM_TRY_INSPECT(const auto& leafName,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsAutoString, file,
GetLeafName));
QM_TRY_INSPECT(const auto& dirEntryKind, GetDirEntryKind(*file));
@ -287,8 +288,9 @@ Result<UsageInfo, nsresult> CacheQuotaClient::InitOrigin(
if (leafName.Equals(kCachesSQLiteFilename) ||
leafName.EqualsLiteral("caches.sqlite-wal")) {
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(file, GetFileSize));
QM_TRY_INSPECT(
const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE_MEMBER(file, GetFileSize));
MOZ_DIAGNOSTIC_ASSERT(fileSize >= 0);
return UsageInfo{DatabaseUsageType(Some(fileSize))};

View File

@ -600,7 +600,7 @@ Result<nsCOMPtr<nsIFileURL>, nsresult> GetDatabaseFileURL(
MOZ_SELECT_OVERLOAD(do_QueryInterface),
protocolHandler));
QM_TRY_INSPECT(const auto& mutator, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_INSPECT(const auto& mutator, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<nsIURIMutator>, fileHandler,
NewFileURIMutator, &aDatabaseFile));
@ -707,7 +707,7 @@ nsresult SetJournalMode(mozIStorageConnection& aConnection) {
QM_TRY_INSPECT(
const auto& journalMode,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, *stmt, GetUTF8String, 0));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCString, *stmt, GetUTF8String, 0));
if (journalMode.Equals(journalModeWAL)) {
// WAL mode successfully enabled. Maybe set limits on its size here.
@ -735,7 +735,7 @@ Result<MovingNotNull<nsCOMPtr<mozIStorageConnection>>, nsresult> OpenDatabase(
: nsAutoCString();
QM_TRY_UNWRAP(auto connection,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, aStorageService,
OpenDatabaseWithFileURL, &aFileURL, telemetryFilename));
@ -809,11 +809,12 @@ OpenDatabaseAndHandleBusy(mozIStorageService& aStorageService,
// it doesn't exist. Returns an error if it exists, but is not a directory, or
// any other error occurs.
Result<bool, nsresult> ExistsAsDirectory(nsIFile& aDirectory) {
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(aDirectory, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(aDirectory, Exists));
if (exists) {
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(aDirectory, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(aDirectory, IsDirectory));
QM_TRY(OkIf(isDirectory), Err(NS_ERROR_FAILURE));
}
@ -889,7 +890,7 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
// Check to make sure that the database schema is correct.
QM_TRY_INSPECT(const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion));
MOZ_TO_RESULT_INVOKE_MEMBER(connection, GetSchemaVersion));
// Unknown schema will fail origin initialization too.
QM_TRY(OkIf(schemaVersion || !aName.IsVoid()),
@ -918,7 +919,7 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
}
// We have to set the auto_vacuum mode before opening a transaction.
QM_TRY((MOZ_TO_RESULT_INVOKE(
QM_TRY((MOZ_TO_RESULT_INVOKE_MEMBER(
connection, ExecuteSimpleSQL,
#ifdef IDB_MOBILE
// Turn on full auto_vacuum mode to reclaim disk space on
@ -955,9 +956,10 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
#ifdef DEBUG
{
QM_TRY_INSPECT(const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion),
QM_ASSERT_UNREACHABLE);
QM_TRY_INSPECT(
const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE_MEMBER(connection, GetSchemaVersion),
QM_ASSERT_UNREACHABLE);
MOZ_ASSERT(schemaVersion == kSQLiteSchemaVersion);
}
#endif
@ -966,10 +968,10 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
// locally in the same function.
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>, connection,
CreateStatement,
"INSERT INTO database (name, origin) "
"VALUES (:name, :origin)"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection, CreateStatement,
"INSERT INTO database (name, origin) "
"VALUES (:name, :origin)"_ns));
QM_TRY(MOZ_TO_RESULT(stmt->BindStringByIndex(0, aName)));
QM_TRY(MOZ_TO_RESULT(stmt->BindUTF8StringByIndex(1, aOrigin)));
@ -979,7 +981,7 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
aFMDirectory, aOrigin));
}
QM_TRY(MOZ_TO_RESULT_INVOKE(transaction, Commit)
QM_TRY(MOZ_TO_RESULT_INVOKE_MEMBER(transaction, Commit)
.mapErr(mapNoDeviceSpaceError));
#ifdef DEBUG
@ -1004,7 +1006,7 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
*connection, "PRAGMA page_size;"_ns));
QM_TRY_INSPECT(const int32_t& pageSize,
MOZ_TO_RESULT_INVOKE(*stmt, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt32, 0));
MOZ_ASSERT(pageSize >= 512 && pageSize <= 65536);
if (kSQLitePageSizeOverride != uint32_t(pageSize)) {
@ -1016,9 +1018,9 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
CreateAndExecuteSingleStepStatement(
*connection, "PRAGMA journal_mode;"_ns));
QM_TRY_INSPECT(
const auto& journalMode,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, *stmt, GetUTF8String, 0));
QM_TRY_INSPECT(const auto& journalMode,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCString, *stmt,
GetUTF8String, 0));
if (journalMode.EqualsLiteral("delete")) {
// Successfully set to rollback journal mode so changing the page size
@ -1048,7 +1050,7 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
}
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(aDBFile, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(aDBFile, GetFileSize));
MOZ_ASSERT(fileSize > 0);
PRTime vacuumTime = PR_Now();
@ -1058,11 +1060,11 @@ CreateStorageConnection(nsIFile& aDBFile, nsIFile& aFMDirectory,
// locally in the same function.
QM_TRY_INSPECT(
const auto& vacuumTimeStmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>, connection,
CreateStatement,
"UPDATE database "
"SET last_vacuum_time = :time"
", last_vacuum_size = :size;"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<mozIStorageStatement>,
connection, CreateStatement,
"UPDATE database "
"SET last_vacuum_time = :time"
", last_vacuum_size = :size;"_ns));
QM_TRY(MOZ_TO_RESULT(vacuumTimeStmt->BindInt64ByIndex(0, vacuumTime)));
QM_TRY(MOZ_TO_RESULT(vacuumTimeStmt->BindInt64ByIndex(1, fileSize)));
@ -1094,7 +1096,7 @@ GetStorageConnection(nsIFile& aDatabaseFile, const int64_t aDirectoryLockId,
AUTO_PROFILER_LABEL("GetStorageConnection", DOM);
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(aDatabaseFile, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(aDatabaseFile, Exists));
QM_TRY(OkIf(exists), Err(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR),
IDB_REPORT_INTERNAL_ERR_LAMBDA);
@ -5546,7 +5548,7 @@ class EncryptedFileBlobImpl final : public FileBlobImpl {
MOZ_ASSERT(inputStream);
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(inputStream, Available), 0,
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(inputStream, Available), 0,
[&aRv](const nsresult rv) { aRv = rv; });
}
@ -5746,7 +5748,7 @@ nsresult DeleteFile(nsIFile& aFile, QuotaManager* const aQuotaManager,
const Maybe<int64_t>& fileSize,
QM_OR_ELSE_LOG_VERBOSE_IF(
// Expression.
MOZ_TO_RESULT_INVOKE(aFile, GetFileSize)
MOZ_TO_RESULT_INVOKE_MEMBER(aFile, GetFileSize)
.map([](const int64_t val) { return Some(val); }),
// Predicate.
isIgnorableError,
@ -5939,7 +5941,8 @@ Result<Ok, nsresult> DeleteFileManagerDirectory(
aOriginMetadata, Idempotency::Yes)));
}));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(aFileManagerDirectory, Remove, false));
QM_TRY_RETURN(
MOZ_TO_RESULT_INVOKE_MEMBER(aFileManagerDirectory, Remove, false));
}
// Idempotently delete all the parts of an IndexedDB database including its
@ -5993,11 +5996,12 @@ nsresult RemoveDatabaseFilesAndDirectory(nsIFile& aBaseDirectory,
CloneFileAndAppend(aBaseDirectory, aDatabaseFilenameBase +
kFileManagerDirectoryNameSuffix));
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(fmDirectory, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(fmDirectory, Exists));
if (exists) {
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(fmDirectory, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(fmDirectory, IsDirectory));
QM_TRY(OkIf(isDirectory), NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
@ -7320,12 +7324,12 @@ Result<uint32_t, nsresult> DatabaseConnection::GetFreelistCount(
const auto borrowedStatement = aCachedStatement.Borrow();
QM_TRY_UNWRAP(const DebugOnly<bool> hasResult,
MOZ_TO_RESULT_INVOKE(&*borrowedStatement, ExecuteStep));
MOZ_TO_RESULT_INVOKE_MEMBER(&*borrowedStatement, ExecuteStep));
MOZ_ASSERT(hasResult);
QM_TRY_INSPECT(const int32_t& freelistCount,
MOZ_TO_RESULT_INVOKE(*borrowedStatement, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*borrowedStatement, GetInt32, 0));
MOZ_ASSERT(freelistCount >= 0);
@ -7406,10 +7410,10 @@ Result<int64_t, nsresult> DatabaseConnection::GetFileSize(
MOZ_ASSERT(!aPath.IsEmpty());
QM_TRY_INSPECT(const auto& file, QM_NewLocalFile(aPath));
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(file, Exists));
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE_MEMBER(file, Exists));
if (exists) {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(file, GetFileSize));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(file, GetFileSize));
}
return 0;
@ -7535,9 +7539,10 @@ nsresult DatabaseConnection::UpdateRefcountFunction::WillCommit() {
QM_TRY(MOZ_TO_RESULT(borrowedUpdateStatement->Execute()));
}
QM_TRY_INSPECT(const int32_t& rows,
MOZ_TO_RESULT_INVOKE(mConnection->MutableStorageConnection(),
GetAffectedRows));
QM_TRY_INSPECT(
const int32_t& rows,
MOZ_TO_RESULT_INVOKE_MEMBER(mConnection->MutableStorageConnection(),
GetAffectedRows));
if (rows > 0) {
QM_TRY_INSPECT(
@ -7677,13 +7682,13 @@ nsresult DatabaseConnection::UpdateRefcountFunction::ProcessValue(
"DatabaseConnection::UpdateRefcountFunction::ProcessValue", DOM);
QM_TRY_INSPECT(const int32_t& type,
MOZ_TO_RESULT_INVOKE(aValues, GetTypeOfIndex, aIndex));
MOZ_TO_RESULT_INVOKE_MEMBER(aValues, GetTypeOfIndex, aIndex));
if (type == mozIStorageValueArray::VALUE_TYPE_NULL) {
return NS_OK;
}
QM_TRY_INSPECT(const auto& ids, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_INSPECT(const auto& ids, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, aValues, GetString, aIndex));
QM_TRY_INSPECT(const auto& files,
@ -7775,17 +7780,17 @@ DatabaseConnection::UpdateRefcountFunction::OnFunctionCall(
#ifdef DEBUG
{
QM_TRY_INSPECT(const uint32_t& numEntries,
MOZ_TO_RESULT_INVOKE(aValues, GetNumEntries),
MOZ_TO_RESULT_INVOKE_MEMBER(aValues, GetNumEntries),
QM_ASSERT_UNREACHABLE);
MOZ_ASSERT(numEntries == 2);
QM_TRY_INSPECT(const int32_t& type1,
MOZ_TO_RESULT_INVOKE(aValues, GetTypeOfIndex, 0),
MOZ_TO_RESULT_INVOKE_MEMBER(aValues, GetTypeOfIndex, 0),
QM_ASSERT_UNREACHABLE);
QM_TRY_INSPECT(const int32_t& type2,
MOZ_TO_RESULT_INVOKE(aValues, GetTypeOfIndex, 1),
MOZ_TO_RESULT_INVOKE_MEMBER(aValues, GetTypeOfIndex, 1),
QM_ASSERT_UNREACHABLE);
MOZ_ASSERT(!(type1 == mozIStorageValueArray::VALUE_TYPE_NULL &&
@ -12219,8 +12224,8 @@ nsresult DatabaseFileManager::Init(nsIFile* aDirectory,
QM_TRY(MOZ_TO_RESULT(aDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755)));
}
QM_TRY_UNWRAP(auto path,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, aDirectory, GetPath));
QM_TRY_UNWRAP(auto path, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, aDirectory, GetPath));
mDirectoryPath.init(std::move(path));
}
@ -12235,23 +12240,23 @@ nsresult DatabaseFileManager::Init(nsIFile* aDirectory,
Unused << existsAsDirectory;
{
QM_TRY_UNWRAP(auto path, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_UNWRAP(auto path, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, journalDirectory, GetPath));
mJournalDirectoryPath.init(std::move(path));
}
QM_TRY_INSPECT(const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, "SELECT id, refcount FROM file"_ns));
QM_TRY(
CollectWhileHasResult(*stmt, [this](auto& stmt) -> Result<Ok, nsresult> {
QM_TRY_INSPECT(const int64_t& id,
MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 0));
QM_TRY_INSPECT(const int32_t& dbRefCnt,
MOZ_TO_RESULT_INVOKE(stmt, GetInt32, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt32, 1));
// We put a raw pointer into the hash table, so the memory refcount will
// be 0, but the dbRefCnt is non-zero, which will keep the
@ -12311,11 +12316,12 @@ nsCOMPtr<nsIFile> DatabaseFileManager::EnsureJournalDirectory() {
QM_TRY(OkIf(journalDirectory), nullptr);
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(journalDirectory, Exists), nullptr);
MOZ_TO_RESULT_INVOKE_MEMBER(journalDirectory, Exists),
nullptr);
if (exists) {
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(journalDirectory, IsDirectory),
MOZ_TO_RESULT_INVOKE_MEMBER(journalDirectory, IsDirectory),
nullptr);
QM_TRY(OkIf(isDirectory), nullptr);
@ -12365,14 +12371,14 @@ nsresult DatabaseFileManager::InitDirectory(nsIFile& aDirectory,
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(aDirectory, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(aDirectory, Exists));
if (!exists) {
return NS_OK;
}
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(aDirectory, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(aDirectory, IsDirectory));
QM_TRY(OkIf(isDirectory), NS_ERROR_FAILURE);
}
@ -12380,11 +12386,11 @@ nsresult DatabaseFileManager::InitDirectory(nsIFile& aDirectory,
CloneFileAndAppend(aDirectory, kJournalDirectoryName));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(journalDirectory, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(journalDirectory, Exists));
if (exists) {
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(journalDirectory, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(journalDirectory, IsDirectory));
QM_TRY(OkIf(isDirectory), NS_ERROR_FAILURE);
bool hasJournals = false;
@ -12394,7 +12400,7 @@ nsresult DatabaseFileManager::InitDirectory(nsIFile& aDirectory,
[&hasJournals](const nsCOMPtr<nsIFile>& file) -> Result<Ok, nsresult> {
QM_TRY_INSPECT(
const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, file, GetLeafName));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, file, GetLeafName));
nsresult rv;
leafName.ToInteger64(&rv);
@ -12424,13 +12430,13 @@ nsresult DatabaseFileManager::InitDirectory(nsIFile& aDirectory,
// locally in the same function.
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, *connection, CreateStatement,
"SELECT name, (name IN (SELECT id FROM file)) FROM fs WHERE path = :path"_ns));
QM_TRY_INSPECT(
const auto& path,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, journalDirectory, GetPath));
QM_TRY_INSPECT(const auto& path,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, journalDirectory, GetPath));
QM_TRY(MOZ_TO_RESULT(stmt->BindStringByIndex(0, path)));
@ -12499,7 +12505,7 @@ Result<FileUsageType, nsresult> DatabaseFileManager::GetUsage(
QM_TRY_INSPECT(const auto& thisUsage,
QM_OR_ELSE_WARN_IF(
// Expression.
MOZ_TO_RESULT_INVOKE(file, GetFileSize)
MOZ_TO_RESULT_INVOKE_MEMBER(file, GetFileSize)
.map([](const int64_t fileSize) {
return FileUsageType(Some(uint64_t(fileSize)));
}),
@ -12719,7 +12725,7 @@ nsresult QuotaClient::UpgradeStorageFrom1_0To2_0(nsIFile* aDirectory) {
CloneFileAndAppend(*aDirectory, subdirNameWithSuffix));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(subdirWithSuffix, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(subdirWithSuffix, Exists));
if (exists) {
IDB_WARNING("Deleting old %s files directory!",
@ -12754,7 +12760,7 @@ nsresult QuotaClient::UpgradeStorageFrom2_1To2_2(nsIFile* aDirectory) {
case nsIFileKind::ExistsAsFile: {
QM_TRY_INSPECT(
const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, file, GetLeafName));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, file, GetLeafName));
// It's reported that files ending with ".tmp" somehow live in the
// indexedDB directories in Bug 1503883. Such files shouldn't exist
@ -12784,10 +12790,10 @@ Result<UsageInfo, nsresult> QuotaClient::InitOrigin(
const AtomicBool& aCanceled) {
AssertIsOnIOThread();
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(this, GetUsageForOriginInternal,
aPersistenceType, aOriginMetadata,
aCanceled,
/* aInitializing*/ true));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(this, GetUsageForOriginInternal,
aPersistenceType, aOriginMetadata,
aCanceled,
/* aInitializing*/ true));
}
nsresult QuotaClient::InitOriginWithoutTracking(
@ -12804,10 +12810,10 @@ Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
const AtomicBool& aCanceled) {
AssertIsOnIOThread();
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(this, GetUsageForOriginInternal,
aPersistenceType, aOriginMetadata,
aCanceled,
/* aInitializing*/ false));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(this, GetUsageForOriginInternal,
aPersistenceType, aOriginMetadata,
aCanceled,
/* aInitializing*/ false));
}
nsresult QuotaClient::GetUsageForOriginInternal(
@ -12920,7 +12926,7 @@ nsresult QuotaClient::GetUsageForOriginInternal(
if (aUsageInfo) {
{
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(databaseFile, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(databaseFile, GetFileSize));
MOZ_ASSERT(fileSize >= 0);
@ -12939,7 +12945,7 @@ nsresult QuotaClient::GetUsageForOriginInternal(
QM_TRY_INSPECT(const int64_t& walFileSize,
QM_OR_ELSE_LOG_VERBOSE_IF(
// Expression.
MOZ_TO_RESULT_INVOKE(walFile, GetFileSize),
MOZ_TO_RESULT_INVOKE_MEMBER(walFile, GetFileSize),
// Predicate.
([](const nsresult rv) {
return rv == NS_ERROR_FILE_NOT_FOUND ||
@ -13186,8 +13192,8 @@ QuotaClient::GetDatabaseFilenames(nsIFile& aDirectory,
QM_TRY(CollectEachFileAtomicCancelable(
aDirectory, aCanceled,
[&result](const nsCOMPtr<nsIFile>& file) -> Result<Ok, nsresult> {
QM_TRY_INSPECT(const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, file, GetLeafName));
QM_TRY_INSPECT(const auto& leafName, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, file, GetLeafName));
QM_TRY_INSPECT(const auto& dirEntryKind, GetDirEntryKind(*file));
@ -13579,7 +13585,7 @@ nsresult Maintenance::DirectoryWork() {
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(storageDir, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(storageDir, Exists));
// XXX No warning here?
if (!exists) {
@ -13589,7 +13595,7 @@ nsresult Maintenance::DirectoryWork() {
{
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(storageDir, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(storageDir, IsDirectory));
QM_TRY(OkIf(isDirectory), NS_ERROR_FAILURE);
}
@ -13635,14 +13641,14 @@ nsresult Maintenance::DirectoryWork() {
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(persistenceDir, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(persistenceDir, Exists));
if (!exists) {
continue;
}
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(persistenceDir, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(persistenceDir, IsDirectory));
if (NS_WARN_IF(!isDirectory)) {
continue;
@ -13706,14 +13712,14 @@ nsresult Maintenance::DirectoryWork() {
CloneFileAndAppend(*originDir, idbDirName));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(idbDir, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(idbDir, Exists));
if (!exists) {
return Ok{};
}
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(idbDir, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(idbDir, IsDirectory));
QM_TRY(OkIf(isDirectory), Ok{});
@ -13731,7 +13737,7 @@ nsresult Maintenance::DirectoryWork() {
}
QM_TRY_UNWRAP(auto idbFilePath,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, idbDirFile, GetPath));
if (!StringEndsWith(idbFilePath, kSQLiteSuffix)) {
@ -14103,8 +14109,8 @@ nsresult DatabaseMaintenance::CheckIntegrity(mozIStorageConnection& aConnection,
CreateAndExecuteSingleStepStatement(
aConnection, "PRAGMA integrity_check(1);"_ns));
QM_TRY_INSPECT(const auto& result,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, *stmt, GetString, 0));
QM_TRY_INSPECT(const auto& result, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, *stmt, GetString, 0));
QM_TRY(OkIf(result.EqualsLiteral("ok")), NS_OK,
[&aOk](const auto) { *aOk = false; });
@ -14112,15 +14118,15 @@ nsresult DatabaseMaintenance::CheckIntegrity(mozIStorageConnection& aConnection,
// Now enable and check for foreign key constraints.
{
QM_TRY_INSPECT(const int32_t& foreignKeysWereEnabled,
([&aConnection]() -> Result<int32_t, nsresult> {
QM_TRY_INSPECT(
const auto& stmt,
QM_TRY_INSPECT(
const int32_t& foreignKeysWereEnabled,
([&aConnection]() -> Result<int32_t, nsresult> {
QM_TRY_INSPECT(const auto& stmt,
CreateAndExecuteSingleStepStatement(
aConnection, "PRAGMA foreign_keys;"_ns));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(*stmt, GetInt32, 0));
}()));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt32, 0));
}()));
if (!foreignKeysWereEnabled) {
QM_TRY(MOZ_TO_RESULT(
@ -14161,7 +14167,7 @@ nsresult DatabaseMaintenance::DetermineMaintenanceAction(
}
QM_TRY_INSPECT(const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE(aConnection, GetSchemaVersion));
MOZ_TO_RESULT_INVOKE_MEMBER(aConnection, GetSchemaVersion));
// Don't do anything if the schema version is less than 18; before that
// version no databases had |auto_vacuum == INCREMENTAL| set and we didn't
@ -14186,10 +14192,10 @@ nsresult DatabaseMaintenance::DetermineMaintenanceAction(
"FROM database;"_ns));
QM_TRY_INSPECT(const PRTime& lastVacuumTime,
MOZ_TO_RESULT_INVOKE(*stmt, GetInt64, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt64, 0));
QM_TRY_INSPECT(const int64_t& lastVacuumSize,
MOZ_TO_RESULT_INVOKE(*stmt, GetInt64, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt64, 1));
NS_ASSERTION(lastVacuumSize > 0,
"Thy last vacuum size shall be greater than zero, less than "
@ -14230,7 +14236,7 @@ nsresult DatabaseMaintenance::DetermineMaintenanceAction(
"AND __ts1__.rowid = __ts2__.rowid + 1;"_ns));
QM_TRY_INSPECT(const int32_t& percentUnordered,
MOZ_TO_RESULT_INVOKE(*stmt, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt32, 0));
MOZ_ASSERT(percentUnordered >= 0);
MOZ_ASSERT(percentUnordered <= 100);
@ -14243,7 +14249,7 @@ nsresult DatabaseMaintenance::DetermineMaintenanceAction(
// Don't try a full vacuum if the file hasn't grown by 10%.
QM_TRY_INSPECT(const int64_t& currentFileSize,
MOZ_TO_RESULT_INVOKE(aDatabaseFile, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(aDatabaseFile, GetFileSize));
if (currentFileSize <= lastVacuumSize ||
(((currentFileSize - lastVacuumSize) * 100 / currentFileSize) <
@ -14258,7 +14264,7 @@ nsresult DatabaseMaintenance::DetermineMaintenanceAction(
aConnection, "PRAGMA freelist_count;"_ns));
QM_TRY_INSPECT(const int32_t& freelistCount,
MOZ_TO_RESULT_INVOKE(*stmt, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt32, 0));
MOZ_ASSERT(freelistCount >= 0);
@ -14279,7 +14285,7 @@ nsresult DatabaseMaintenance::DetermineMaintenanceAction(
"SELECT SUM(unused) * 100.0 / SUM(pgsize) FROM __temp_stats__;"_ns));
QM_TRY_INSPECT(const int32_t& percentUnused,
MOZ_TO_RESULT_INVOKE(*stmt, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt32, 0));
MOZ_ASSERT(percentUnused >= 0);
MOZ_ASSERT(percentUnused <= 100);
@ -14326,13 +14332,13 @@ void DatabaseMaintenance::FullVacuum(mozIStorageConnection& aConnection,
MOZ_ASSERT(vacuumTime > 0);
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(aDatabaseFile, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(aDatabaseFile, GetFileSize));
MOZ_ASSERT(fileSize > 0);
// The parameter names are not used, parameters are bound by index only
// locally in the same function.
QM_TRY_INSPECT(const auto& stmt, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_INSPECT(const auto& stmt, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>,
aConnection, CreateStatement,
"UPDATE database "
@ -14986,9 +14992,9 @@ nsresult DatabaseOperationBase::AutoSetProgressHandler::Register(
QM_TRY_UNWRAP(
const DebugOnly oldProgressHandler,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageProgressHandler>,
aConnection, SetProgressHandler,
kStorageProgressGranularity, aDatabaseOp));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageProgressHandler>, aConnection, SetProgressHandler,
kStorageProgressGranularity, aDatabaseOp));
MOZ_ASSERT(!oldProgressHandler.inspect());
@ -15781,23 +15787,23 @@ nsresult FactoryOp::FinishOpen() {
// Need to get database file path before opening the directory.
// XXX: For what reason?
QM_TRY_UNWRAP(
mDatabaseFilePath,
([this, quotaManager,
persistenceType]() -> mozilla::Result<nsString, nsresult> {
QM_TRY_INSPECT(const auto& dbFile,
quotaManager->GetDirectoryForOrigin(
persistenceType, mOriginMetadata.mOrigin));
QM_TRY_UNWRAP(mDatabaseFilePath,
([this, quotaManager,
persistenceType]() -> mozilla::Result<nsString, nsresult> {
QM_TRY_INSPECT(const auto& dbFile,
quotaManager->GetDirectoryForOrigin(
persistenceType, mOriginMetadata.mOrigin));
QM_TRY(MOZ_TO_RESULT(dbFile->Append(
NS_LITERAL_STRING_FROM_CSTRING(IDB_DIRECTORY_NAME))));
QM_TRY(MOZ_TO_RESULT(dbFile->Append(
NS_LITERAL_STRING_FROM_CSTRING(IDB_DIRECTORY_NAME))));
QM_TRY(MOZ_TO_RESULT(dbFile->Append(
GetDatabaseFilenameBase(mCommonParams.metadata().name()) +
kSQLiteSuffix)));
QM_TRY(MOZ_TO_RESULT(dbFile->Append(
GetDatabaseFilenameBase(mCommonParams.metadata().name()) +
kSQLiteSuffix)));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(nsString, dbFile, GetPath));
}()));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, dbFile, GetPath));
}()));
// Open directory
RefPtr<DirectoryLock> directoryLock = quotaManager->CreateDirectoryLock(
@ -16045,7 +16051,7 @@ nsresult OpenDatabaseOp::DoDatabaseWork() {
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(dbDirectory, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(dbDirectory, Exists));
if (!exists) {
QM_TRY(MOZ_TO_RESULT(dbDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755)));
@ -16065,7 +16071,8 @@ nsresult OpenDatabaseOp::DoDatabaseWork() {
CloneFileAndAppend(*dbDirectory, kIdbDeletionMarkerFilePrefix +
databaseFilenameBase));
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(markerFile, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(markerFile, Exists));
if (exists) {
// Delete the database and directroy since they should be deleted in
@ -16085,8 +16092,9 @@ nsresult OpenDatabaseOp::DoDatabaseWork() {
#ifdef DEBUG
{
QM_TRY_INSPECT(const auto& databaseFilePath,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, dbFile, GetPath));
QM_TRY_INSPECT(
const auto& databaseFilePath,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, dbFile, GetPath));
MOZ_ASSERT(databaseFilePath == mDatabaseFilePath);
}
@ -16194,13 +16202,13 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
QM_TRY(OkIf(stmt), NS_ERROR_FILE_CORRUPTED);
QM_TRY_INSPECT(const auto& databaseName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, stmt, GetString, 0));
QM_TRY_INSPECT(const auto& databaseName, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, stmt, GetString, 0));
QM_TRY(OkIf(mCommonParams.metadata().name() == databaseName),
NS_ERROR_FILE_CORRUPTED);
QM_TRY_INSPECT(const auto& origin, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_INSPECT(const auto& origin, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, stmt, GetUTF8String, 1));
// We can't just compare these strings directly. See bug 1339081 comment 69.
@ -16209,7 +16217,7 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
NS_ERROR_FILE_CORRUPTED);
QM_TRY_INSPECT(const int64_t& version,
MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 2));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 2));
mMetadata->mCommonMetadata.version() = uint64_t(version);
}
@ -16223,7 +16231,7 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
// Load object store names and ids.
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection, CreateStatement,
"SELECT id, auto_increment, name, key_path "
"FROM object_store"_ns));
@ -16237,7 +16245,7 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
usedNames = Maybe<nsTHashSet<nsString>>{}](
auto& stmt) mutable -> mozilla::Result<Ok, nsresult> {
QM_TRY_INSPECT(const IndexOrObjectStoreId& objectStoreId,
MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 0));
if (!usedIds) {
usedIds.emplace();
@ -16267,8 +16275,9 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
commonMetadata.id() = objectStoreId;
commonMetadata.name() = std::move(name);
QM_TRY_INSPECT(const int32_t& columnType,
MOZ_TO_RESULT_INVOKE(stmt, GetTypeOfIndex, 3));
QM_TRY_INSPECT(
const int32_t& columnType,
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetTypeOfIndex, 3));
if (columnType == mozIStorageStatement::VALUE_TYPE_NULL) {
commonMetadata.keyPath() = KeyPath(0);
@ -16285,7 +16294,7 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
}
QM_TRY_INSPECT(const int64_t& nextAutoIncrementId,
MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 1));
commonMetadata.autoIncrement() = !!nextAutoIncrementId;
@ -16313,13 +16322,13 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
// Load index information
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConnection, CreateStatement,
"SELECT "
"id, object_store_id, name, key_path, "
"unique_index, multientry, "
"locale, is_auto_locale "
"FROM object_store_index"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection, CreateStatement,
"SELECT "
"id, object_store_id, name, key_path, "
"unique_index, multientry, "
"locale, is_auto_locale "
"FROM object_store_index"_ns));
IndexOrObjectStoreId lastIndexId = 0;
@ -16330,7 +16339,7 @@ nsresult OpenDatabaseOp::LoadDatabaseInformation(
usedNames = Maybe<nsTHashSet<nsString>>{}](
auto& stmt) mutable -> mozilla::Result<Ok, nsresult> {
QM_TRY_INSPECT(const IndexOrObjectStoreId& objectStoreId,
MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 1));
// XXX Why does this return NS_ERROR_OUT_OF_MEMORY if we don't
// know the object store id?
@ -16462,10 +16471,10 @@ nsresult OpenDatabaseOp::UpdateLocaleAwareIndex(
const nsCString readQuery = "SELECT value, object_data_key FROM "_ns +
indexTable + " WHERE index_id = :index_id"_ns;
QM_TRY_INSPECT(
const auto& readStmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, readQuery));
QM_TRY_INSPECT(const auto& readStmt,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, readQuery));
QM_TRY(MOZ_TO_RESULT(readStmt->BindInt64ByIndex(0, aIndexMetadata.id())));
@ -16477,7 +16486,7 @@ nsresult OpenDatabaseOp::UpdateLocaleAwareIndex(
if (!writeStmt) {
QM_TRY_UNWRAP(
writeStmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection, CreateStatement,
"UPDATE "_ns + indexTable + "SET value_locale = :"_ns +
kStmtParamNameValueLocale + " WHERE index_id = :"_ns +
@ -16516,10 +16525,10 @@ nsresult OpenDatabaseOp::UpdateLocaleAwareIndex(
"UPDATE object_store_index SET "
"locale = :locale WHERE id = :id"_ns;
QM_TRY_INSPECT(
const auto& metaStmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, metaQuery));
QM_TRY_INSPECT(const auto& metaStmt,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, metaQuery));
QM_TRY(MOZ_TO_RESULT(
metaStmt->BindStringByIndex(0, NS_ConvertASCIItoUTF16(aLocale))));
@ -17224,8 +17233,8 @@ nsresult DeleteDatabaseOp::DoDatabaseWork() {
QM_TRY(MOZ_TO_RESULT(
directory->Append(NS_LITERAL_STRING_FROM_CSTRING(IDB_DIRECTORY_NAME))));
QM_TRY_UNWRAP(mDatabaseDirectoryPath,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, directory, GetPath));
QM_TRY_UNWRAP(mDatabaseDirectoryPath, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, directory, GetPath));
mDatabaseFilenameBase = GetDatabaseFilenameBase(databaseName);
@ -17235,14 +17244,16 @@ nsresult DeleteDatabaseOp::DoDatabaseWork() {
#ifdef DEBUG
{
QM_TRY_INSPECT(const auto& databaseFilePath,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, dbFile, GetPath));
QM_TRY_INSPECT(
const auto& databaseFilePath,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, dbFile, GetPath));
MOZ_ASSERT(databaseFilePath == mDatabaseFilePath);
}
#endif
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(dbFile, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(dbFile, Exists));
if (exists) {
// Parts of this function may fail but that shouldn't prevent us from
@ -18782,7 +18793,7 @@ CreateIndexOp::UpdateIndexDataValuesFunction::OnFunctionCall(
// No changes needed, just return the original value.
QM_TRY_INSPECT(const int32_t& valueType,
MOZ_TO_RESULT_INVOKE(aValues, GetTypeOfIndex, 1));
MOZ_TO_RESULT_INVOKE_MEMBER(aValues, GetTypeOfIndex, 1));
MOZ_ASSERT(valueType == mozIStorageValueArray::VALUE_TYPE_NULL ||
valueType == mozIStorageValueArray::VALUE_TYPE_BLOB);
@ -21042,7 +21053,7 @@ template <IDBCursorType CursorType>
nsresult CommonOpenOpHelper<CursorType>::ProcessStatementSteps(
mozIStorageStatement* const aStmt) {
QM_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(aStmt, ExecuteStep));
MOZ_TO_RESULT_INVOKE_MEMBER(aStmt, ExecuteStep));
if (!hasResult) {
SetResponse(void_t{});
@ -21496,7 +21507,7 @@ nsresult Cursor<CursorType>::ContinueOp::DoDatabaseWork(
// than using a OFFSET clause in the query?
for (uint32_t index = 0; index < advanceCount; index++) {
QM_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(&*stmt, ExecuteStep));
MOZ_TO_RESULT_INVOKE_MEMBER(&*stmt, ExecuteStep));
if (!hasResult) {
mResponse = void_t();
@ -21676,7 +21687,8 @@ nsresult FileHelper::CreateFileFromStream(nsIFile& aFile, nsIFile& aJournalFile,
const Maybe<CipherKey>& aMaybeKey) {
MOZ_ASSERT(!IsOnBackgroundThread());
QM_TRY_INSPECT(const auto& exists, MOZ_TO_RESULT_INVOKE(aFile, Exists));
QM_TRY_INSPECT(const auto& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(aFile, Exists));
// DOM blobs that are being stored in IDB are cached by calling
// IDBDatabase::GetOrCreateFileActorForBlob. So if the same DOM blob is stored
@ -21691,17 +21703,18 @@ nsresult FileHelper::CreateFileFromStream(nsIFile& aFile, nsIFile& aJournalFile,
// to just delete the orphaned file and start from scratch.
// This corner case is partially simulated in test_file_copy_failure.js
if (exists) {
QM_TRY_INSPECT(const auto& isFile, MOZ_TO_RESULT_INVOKE(aFile, IsFile));
QM_TRY_INSPECT(const auto& isFile,
MOZ_TO_RESULT_INVOKE_MEMBER(aFile, IsFile));
QM_TRY(OkIf(isFile), NS_ERROR_FAILURE);
QM_TRY_INSPECT(const auto& journalExists,
MOZ_TO_RESULT_INVOKE(aJournalFile, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(aJournalFile, Exists));
QM_TRY(OkIf(journalExists), NS_ERROR_FAILURE);
QM_TRY_INSPECT(const auto& journalIsFile,
MOZ_TO_RESULT_INVOKE(aJournalFile, IsFile));
MOZ_TO_RESULT_INVOKE_MEMBER(aJournalFile, IsFile));
QM_TRY(OkIf(journalIsFile), NS_ERROR_FAILURE);

View File

@ -314,8 +314,9 @@ nsresult ReadCompressedIndexDataValuesFromSource(
MOZ_ASSERT(aOutIndexValues);
MOZ_ASSERT(aOutIndexValues->IsEmpty());
QM_TRY_INSPECT(const int32_t& columnType,
MOZ_TO_RESULT_INVOKE(aSource, GetTypeOfIndex, aColumnIndex));
QM_TRY_INSPECT(
const int32_t& columnType,
MOZ_TO_RESULT_INVOKE_MEMBER(aSource, GetTypeOfIndex, aColumnIndex));
switch (columnType) {
case mozIStorageStatement::VALUE_TYPE_NULL:
@ -455,23 +456,25 @@ GetStructuredCloneReadInfoFromSource(T* aSource, uint32_t aDataIndex,
MOZ_ASSERT(!IsOnBackgroundThread());
MOZ_ASSERT(aSource);
QM_TRY_INSPECT(const int32_t& columnType,
MOZ_TO_RESULT_INVOKE(aSource, GetTypeOfIndex, aDataIndex));
QM_TRY_INSPECT(
const int32_t& columnType,
MOZ_TO_RESULT_INVOKE_MEMBER(aSource, GetTypeOfIndex, aDataIndex));
QM_TRY_INSPECT(const bool& isNull,
MOZ_TO_RESULT_INVOKE(aSource, GetIsNull, aFileIdsIndex));
QM_TRY_INSPECT(const bool& isNull, MOZ_TO_RESULT_INVOKE_MEMBER(
aSource, GetIsNull, aFileIdsIndex));
QM_TRY_INSPECT(const nsString& fileIds, ([aSource, aFileIdsIndex, isNull] {
return isNull ? Result<nsString, nsresult>{VoidString()}
: MOZ_TO_RESULT_INVOKE_TYPED(nsString, aSource,
GetString,
aFileIdsIndex);
: MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, aSource, GetString,
aFileIdsIndex);
}()));
switch (columnType) {
case mozIStorageStatement::VALUE_TYPE_INTEGER: {
QM_TRY_INSPECT(const int64_t& intData,
MOZ_TO_RESULT_INVOKE(aSource, GetInt64, aDataIndex));
QM_TRY_INSPECT(
const int64_t& intData,
MOZ_TO_RESULT_INVOKE_MEMBER(aSource, GetInt64, aDataIndex));
uint64_t uintData;
memcpy(&uintData, &intData, sizeof(uint64_t));

View File

@ -25,7 +25,8 @@ Result<Ok, nsresult> DatabaseFileManager::TraverseFiles(
UnknownDirEntryOp&& aUnknownDirEntryOp) {
quota::AssertIsOnIOThread();
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(aDirectory, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(aDirectory, Exists));
if (!exists) {
return Ok{};
@ -41,7 +42,7 @@ Result<Ok, nsresult> DatabaseFileManager::TraverseFiles(
case quota::nsIFileKind::ExistsAsDirectory: {
QM_TRY_INSPECT(
const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, file, GetLeafName));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, file, GetLeafName));
if (leafName.Equals(kJournalDirectoryName)) {
QM_TRY(std::forward<KnownDirEntryOp>(aKnownDirEntryOp)(
@ -61,7 +62,7 @@ Result<Ok, nsresult> DatabaseFileManager::TraverseFiles(
case quota::nsIFileKind::ExistsAsFile: {
QM_TRY_INSPECT(
const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, file, GetLeafName));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, file, GetLeafName));
nsresult rv;
leafName.ToInteger64(&rv);

View File

@ -23,8 +23,8 @@ nsresult SnappyUncompressStructuredCloneData(
QM_TRY(CollectEach(
[&snappyInputStream = *snappyInputStream, &buffer] {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(snappyInputStream, Read, buffer,
sizeof(buffer)));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(snappyInputStream, Read,
buffer, sizeof(buffer)));
},
[&aStructuredCloneData,
&buffer](const uint32_t& numRead) -> Result<Ok, nsresult> {

View File

@ -64,9 +64,10 @@ PermissionRequestBase::GetCurrentPermission(nsIPrincipal& aPrincipal) {
const nsCOMPtr<nsIPermissionManager> permMan = GetPermissionManager();
QM_TRY(OkIf(permMan), Err(NS_ERROR_FAILURE));
QM_TRY_INSPECT(const uint32_t& intPermission,
MOZ_TO_RESULT_INVOKE(permMan, TestExactPermissionFromPrincipal,
&aPrincipal, kPermissionString));
QM_TRY_INSPECT(
const uint32_t& intPermission,
MOZ_TO_RESULT_INVOKE_MEMBER(permMan, TestExactPermissionFromPrincipal,
&aPrincipal, kPermissionString));
const PermissionValue permission =
PermissionValueForIntPermission(intPermission);

View File

@ -110,7 +110,7 @@ nsresult UpgradeSchemaFrom4To5(mozIStorageConnection& aConnection) {
mozStorageStatementScoper scoper(stmt);
QM_TRY_INSPECT(const bool& hasResults,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, ExecuteStep));
if (NS_WARN_IF(!hasResults)) {
return NS_ERROR_FAILURE;
@ -2310,7 +2310,7 @@ nsresult UpgradeSchemaFrom19_0To20_0(nsIFile* aFMDirectory,
mozStorageStatementScoper scoper(stmt);
QM_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(stmt, ExecuteStep));
MOZ_TO_RESULT_INVOKE_MEMBER(stmt, ExecuteStep));
if (NS_WARN_IF(!hasResult)) {
MOZ_ASSERT(false, "This should never be possible!");
@ -3008,7 +3008,7 @@ Result<bool, nsresult> MaybeUpgradeSchema(mozIStorageConnection& aConnection,
}
QM_TRY_UNWRAP(schemaVersion,
MOZ_TO_RESULT_INVOKE(aConnection, GetSchemaVersion));
MOZ_TO_RESULT_INVOKE_MEMBER(aConnection, GetSchemaVersion));
}
MOZ_ASSERT(schemaVersion == kSQLiteSchemaVersion);

View File

@ -480,8 +480,9 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
auto connection,
OrElseIf(
// Expression.
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>,
storageService, OpenDatabase, &aDBFile),
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<mozIStorageConnection>,
storageService, OpenDatabase,
&aDBFile),
// Predicate.
IsDatabaseCorruptionError,
// Fallback.
@ -513,7 +514,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
// Nuke the database file.
QM_TRY(MOZ_TO_RESULT(aDBFile.Remove(false)));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, storageService, OpenDatabase,
&aDBFile));
})));
@ -523,7 +524,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
// Check to make sure that the database schema is correct.
// XXX Try to make schemaVersion const.
QM_TRY_UNWRAP(int32_t schemaVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion));
MOZ_TO_RESULT_INVOKE_MEMBER(connection, GetSchemaVersion));
QM_TRY(OkIf(schemaVersion <= kSQLiteSchemaVersion), Err(NS_ERROR_FAILURE));
@ -560,9 +561,10 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
#ifdef DEBUG
{
QM_TRY_INSPECT(const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion),
QM_ASSERT_UNREACHABLE);
QM_TRY_INSPECT(
const int32_t& schemaVersion,
MOZ_TO_RESULT_INVOKE_MEMBER(connection, GetSchemaVersion),
QM_ASSERT_UNREACHABLE);
MOZ_ASSERT(schemaVersion == kSQLiteSchemaVersion);
}
@ -570,7 +572,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection, CreateStatement,
"INSERT INTO database (origin) VALUES (:origin)"_ns));
@ -596,8 +598,8 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
return Err(NS_ERROR_FAILURE);
}
QM_TRY_UNWRAP(schemaVersion,
MOZ_TO_RESULT_INVOKE(connection, GetSchemaVersion));
QM_TRY_UNWRAP(schemaVersion, MOZ_TO_RESULT_INVOKE_MEMBER(
connection, GetSchemaVersion));
}
MOZ_ASSERT(schemaVersion == kSQLiteSchemaVersion);
@ -607,11 +609,12 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
if (newDatabase) {
// Windows caches the file size, let's force it to stat the file again.
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(aDBFile, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(aDBFile, Exists));
Unused << exists;
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(aDBFile, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(aDBFile, GetFileSize));
MOZ_ASSERT(fileSize > 0);
@ -620,11 +623,11 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateStorageConnection(
QM_TRY_INSPECT(
const auto& vacuumTimeStmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>, connection,
CreateStatement,
"UPDATE database "
"SET last_vacuum_time = :time"
", last_vacuum_size = :size;"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<mozIStorageStatement>,
connection, CreateStatement,
"UPDATE database "
"SET last_vacuum_time = :time"
", last_vacuum_size = :size;"_ns));
QM_TRY(MOZ_TO_RESULT(
vacuumTimeStmt->BindInt64ByName("time"_ns, vacuumTime)));
@ -648,7 +651,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> GetStorageConnection(
QM_TRY_INSPECT(const auto& databaseFile, QM_NewLocalFile(aDatabaseFilePath));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(databaseFile, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(databaseFile, Exists));
QM_TRY(OkIf(exists), Err(NS_ERROR_FAILURE));
@ -657,9 +660,9 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> GetStorageConnection(
MOZ_SELECT_OVERLOAD(do_GetService),
MOZ_STORAGE_SERVICE_CONTRACTID));
QM_TRY_UNWRAP(auto connection,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenDatabase, databaseFile));
QM_TRY_UNWRAP(auto connection, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, ss,
OpenDatabase, databaseFile));
QM_TRY(MOZ_TO_RESULT(SetDefaultPragmas(connection)));
@ -692,7 +695,7 @@ CreateArchiveStorageConnection(const nsAString& aStoragePath) {
MOZ_ASSERT(exists);
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(archiveFile, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(archiveFile, IsDirectory));
if (isDirectory) {
LS_WARNING("ls-archive is not a file!");
@ -708,8 +711,8 @@ CreateArchiveStorageConnection(const nsAString& aStoragePath) {
auto connection,
QM_OR_ELSE_WARN_IF(
// Expression.
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, archiveFile),
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, archiveFile),
// Predicate.
IsDatabaseCorruptionError,
// Fallback. Don't throw an error, leave a corrupted ls-archive
@ -753,9 +756,9 @@ nsresult SetShadowJournalMode(mozIStorageConnection* aConnection) {
CreateAndExecuteSingleStepStatement(
*aConnection, journalModeQueryStart + journalModeWAL));
QM_TRY_INSPECT(
const auto& journalMode,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoCString, *stmt, GetUTF8String, 0));
QM_TRY_INSPECT(const auto& journalMode,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsAutoCString, *stmt,
GetUTF8String, 0));
if (journalMode.Equals(journalModeWAL)) {
// WAL mode successfully enabled. Set limits on its size here.
@ -766,7 +769,7 @@ nsresult SetShadowJournalMode(mozIStorageConnection* aConnection) {
*aConnection, "PRAGMA page_size;"_ns));
QM_TRY_INSPECT(const int32_t& pageSize,
MOZ_TO_RESULT_INVOKE(*stmt, GetInt32, 0));
MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt32, 0));
MOZ_ASSERT(pageSize >= 512 && pageSize <= 65536);
@ -803,8 +806,8 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateShadowStorageConnection(
auto connection,
QM_OR_ELSE_WARN_IF(
// Expression.
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, shadowFile),
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, shadowFile),
// Predicate.
IsDatabaseCorruptionError,
// Fallback.
@ -812,9 +815,9 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateShadowStorageConnection(
-> Result<nsCOMPtr<mozIStorageConnection>, nsresult> {
QM_TRY(MOZ_TO_RESULT(shadowFile->Remove(false)));
QM_TRY_RETURN(
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, shadowFile));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, ss, OpenUnsharedDatabase,
shadowFile));
})));
QM_TRY(MOZ_TO_RESULT(SetShadowJournalMode(connection)));
@ -841,7 +844,7 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> CreateShadowStorageConnection(
QM_TRY(MOZ_TO_RESULT(connection->Close()));
QM_TRY(MOZ_TO_RESULT(shadowFile->Remove(false)));
QM_TRY_UNWRAP(connection, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_UNWRAP(connection, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, shadowFile));
@ -863,7 +866,8 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> GetShadowStorageConnection(
QM_TRY_INSPECT(const auto& shadowFile, GetShadowFile(aBasePath));
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(shadowFile, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(shadowFile, Exists));
QM_TRY(OkIf(exists), Err(NS_ERROR_FAILURE));
@ -872,8 +876,8 @@ Result<nsCOMPtr<mozIStorageConnection>, nsresult> GetShadowStorageConnection(
MOZ_SELECT_OVERLOAD(do_GetService),
MOZ_STORAGE_SERVICE_CONTRACTID));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageConnection>, ss,
OpenUnsharedDatabase, shadowFile));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageConnection>, ss, OpenUnsharedDatabase, shadowFile));
}
nsresult AttachShadowDatabase(const nsAString& aBasePath,
@ -887,17 +891,17 @@ nsresult AttachShadowDatabase(const nsAString& aBasePath,
#ifdef DEBUG
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(shadowFile, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(shadowFile, Exists));
MOZ_ASSERT(exists);
}
#endif
QM_TRY_INSPECT(const auto& path,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, shadowFile, GetPath));
QM_TRY_INSPECT(const auto& path, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, shadowFile, GetPath));
QM_TRY_INSPECT(const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, "ATTACH DATABASE :path AS shadow;"_ns));
@ -955,7 +959,7 @@ Result<bool, nsresult> ExistsAsFile(nsIFile& aFile) {
QM_TRY_INSPECT(const auto& res,
QM_OR_ELSE_LOG_VERBOSE_IF(
// Expression.
MOZ_TO_RESULT_INVOKE(aFile, IsDirectory)
MOZ_TO_RESULT_INVOKE_MEMBER(aFile, IsDirectory)
.map([](const bool isDirectory) {
return isDirectory ? ExistsAsFileResult::IsDirectory
: ExistsAsFileResult::IsFile;
@ -1009,7 +1013,7 @@ Result<UsageInfo, nsresult> LoadUsageFile(nsIFile& aUsageFile) {
AssertIsOnIOThread();
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(aUsageFile, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(aUsageFile, GetFileSize));
QM_TRY(OkIf(fileSize == kUsageFileSize), Err(NS_ERROR_FILE_CORRUPTED));
@ -1022,12 +1026,12 @@ Result<UsageInfo, nsresult> LoadUsageFile(nsIFile& aUsageFile) {
NS_NewObjectInputStream(bufferedStream);
QM_TRY_INSPECT(const uint32_t& cookie,
MOZ_TO_RESULT_INVOKE(binaryStream, Read32));
MOZ_TO_RESULT_INVOKE_MEMBER(binaryStream, Read32));
QM_TRY(OkIf(cookie == kUsageFileCookie), Err(NS_ERROR_FILE_CORRUPTED));
QM_TRY_INSPECT(const uint64_t& usage,
MOZ_TO_RESULT_INVOKE(binaryStream, Read64));
MOZ_TO_RESULT_INVOKE_MEMBER(binaryStream, Read64));
return UsageInfo{DatabaseUsageType(Some(usage))};
}
@ -2812,10 +2816,10 @@ nsresult LoadArchivedOrigins() {
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>, connection,
CreateStatement,
"SELECT DISTINCT originAttributes, originKey "
"FROM webappsstore2;"_ns));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection, CreateStatement,
"SELECT DISTINCT originAttributes, originKey "
"FROM webappsstore2;"_ns));
auto archivedOrigins = MakeUnique<ArchivedOriginHashtable>();
@ -2823,12 +2827,12 @@ nsresult LoadArchivedOrigins() {
// CollectElementsWhileHasResult
QM_TRY(quota::CollectWhileHasResult(
*stmt, [&archivedOrigins](auto& stmt) -> Result<Ok, nsresult> {
QM_TRY_INSPECT(
const auto& originSuffix,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, stmt, GetUTF8String, 0));
QM_TRY_INSPECT(
const auto& originNoSuffix,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, stmt, GetUTF8String, 1));
QM_TRY_INSPECT(const auto& originSuffix,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCString, stmt,
GetUTF8String, 0));
QM_TRY_INSPECT(const auto& originNoSuffix,
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCString, stmt,
GetUTF8String, 1));
const nsCString hashKey =
GetArchivedOriginHashKey(originSuffix, originNoSuffix);
@ -2879,7 +2883,7 @@ Result<int64_t, nsresult> GetUsage(mozIStorageConnection& aConnection,
QM_TRY(OkIf(stmt), Err(NS_ERROR_FAILURE));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(stmt, GetInt64, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(stmt, GetInt64, 0));
}
void ShadowWritesPrefChangedCallback(const char* aPrefName, void* aClosure) {
@ -3598,7 +3602,7 @@ Result<int64_t, nsresult> ConnectionWriteOptimizer::Perform(
QM_TRY(OkIf(stmt), Err(NS_ERROR_FAILURE));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(*stmt, GetInt64, 0));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(*stmt, GetInt64, 0));
}
nsresult ConnectionWriteOptimizer::PerformInsertOrUpdate(
@ -3944,7 +3948,7 @@ nsresult Connection::EnsureStorageConnection() {
QM_TRY_INSPECT(
const auto& databaseFilePath,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, directoryEntry, GetPath));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, directoryEntry, GetPath));
QM_TRY_UNWRAP(auto storageConnection,
GetStorageConnection(databaseFilePath));
@ -3968,7 +3972,7 @@ nsresult Connection::EnsureStorageConnection() {
QM_TRY(MOZ_TO_RESULT(directoryEntry->GetPath(mDirectoryPath)));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(directoryEntry, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(directoryEntry, Exists));
if (!exists) {
QM_TRY(
@ -3980,7 +3984,7 @@ nsresult Connection::EnsureStorageConnection() {
#ifdef DEBUG
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(directoryEntry, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(directoryEntry, Exists));
MOZ_ASSERT(!exists);
}
@ -6834,7 +6838,7 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
QM_TRY_INSPECT(
const auto& directoryPath,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, directoryEntry, GetPath));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, directoryEntry, GetPath));
// The ls directory doesn't need to be created when we don't have data for
// migration. It will be created on the connection thread in
@ -6945,7 +6949,7 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection, CreateStatement,
"INSERT INTO data (key, value, utf16Length, compressed) "
"SELECT key, compress(value), utf16Length(value), "
@ -6966,7 +6970,7 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
{
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection, CreateStatement,
"UPDATE database SET usage = :usage;"_ns));
@ -6978,7 +6982,7 @@ nsresult PrepareDatastoreOp::DatabaseWork() {
{
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection, CreateStatement,
"DELETE FROM webappsstore2 "
"WHERE originKey = :originKey "
@ -7060,7 +7064,8 @@ nsresult PrepareDatastoreOp::EnsureDirectoryEntry(nsIFile* aEntry,
AssertIsOnIOThread();
MOZ_ASSERT(aEntry);
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(aEntry, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(aEntry, Exists));
if (!exists) {
if (!aCreateIfNotExists) {
@ -7100,8 +7105,8 @@ nsresult PrepareDatastoreOp::VerifyDatabaseInformation(
QM_TRY(OkIf(stmt), NS_ERROR_FILE_CORRUPTED);
QM_TRY_INSPECT(const auto& origin,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, stmt, GetUTF8String, 0));
QM_TRY_INSPECT(const auto& origin, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, stmt, GetUTF8String, 0));
QM_TRY(OkIf(QuotaManager::AreOriginsEqualOnDisk(Origin(), origin)),
NS_ERROR_FILE_CORRUPTED);
@ -7504,8 +7509,8 @@ nsresult PrepareDatastoreOp::LoadDataOp::DoDatastoreWork() {
QM_TRY(quota::CollectWhileHasResult(
*stmt, [this](auto& stmt) -> mozilla::Result<Ok, nsresult> {
QM_TRY_UNWRAP(auto key,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, stmt, GetString, 0));
QM_TRY_UNWRAP(auto key, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, stmt, GetString, 0));
LSValue value;
QM_TRY(MOZ_TO_RESULT(value.InitFromStatement(&stmt, 1)));
@ -7584,8 +7589,8 @@ PrepareDatastoreOp::CompressFunction::OnFunctionCall(
#endif
QM_TRY_INSPECT(const auto& value,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, aFunctionArguments,
GetUTF8String, 0));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, aFunctionArguments, GetUTF8String, 0));
nsCString compressed;
QM_TRY(OkIf(SnappyCompress(value, compressed)), NS_ERROR_FAILURE);
@ -7619,8 +7624,8 @@ PrepareDatastoreOp::CompressibleFunction::OnFunctionCall(
#endif
QM_TRY_INSPECT(const auto& value,
MOZ_TO_RESULT_INVOKE_TYPED(nsCString, aFunctionArguments,
GetUTF8String, 0));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCString, aFunctionArguments, GetUTF8String, 0));
nsCString compressed;
QM_TRY(OkIf(SnappyCompress(value, compressed)), NS_ERROR_FAILURE);
@ -8106,13 +8111,14 @@ Result<UsageInfo, nsresult> QuotaClient::InitOrigin(
#ifdef DEBUG
{
QM_TRY_INSPECT(const bool& exists, MOZ_TO_RESULT_INVOKE(directory, Exists));
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE_MEMBER(directory, Exists));
MOZ_ASSERT(exists);
}
#endif
QM_TRY_INSPECT(const auto& directoryPath,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, directory, GetPath));
QM_TRY_INSPECT(const auto& directoryPath, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, directory, GetPath));
QM_TRY_INSPECT(const auto& usageFile, GetUsageFile(directoryPath));
@ -8198,7 +8204,7 @@ Result<UsageInfo, nsresult> QuotaClient::InitOrigin(
case nsIFileKind::ExistsAsFile: {
QM_TRY_INSPECT(
const auto& leafName,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, file, GetLeafName));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsString, file, GetLeafName));
if (leafName.Equals(kDataFileName) ||
leafName.Equals(kJournalFileName) ||
@ -8335,7 +8341,7 @@ nsresult QuotaClient::AboutToClearOrigins(
{
QM_TRY_INSPECT(const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection,
CreateStatement, "BEGIN IMMEDIATE;"_ns));
@ -8354,7 +8360,7 @@ nsresult QuotaClient::AboutToClearOrigins(
{
QM_TRY_INSPECT(const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, connection,
CreateStatement, "COMMIT;"_ns));
@ -8668,7 +8674,7 @@ nsresult QuotaClient::PerformDelete(
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection, CreateStatement,
"DELETE FROM "_ns + aSchemaName + ".webappsstore2"_ns +
aArchivedOriginScope->GetBindingClause() + ";"_ns));
@ -8771,8 +8777,8 @@ QuotaClient::MatchFunction::OnFunctionCall(
MOZ_ASSERT(aResult);
QM_TRY_INSPECT(const auto& suffix,
MOZ_TO_RESULT_INVOKE_TYPED(nsAutoCString, aFunctionArguments,
GetUTF8String, 1));
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsAutoCString, aFunctionArguments, GetUTF8String, 1));
OriginAttributes oa;
QM_TRY(OkIf(oa.PopulateFromSuffix(suffix)), NS_ERROR_FAILURE);

File diff suppressed because it is too large Load Diff

View File

@ -44,9 +44,9 @@ CachingDatabaseConnection::GetCachedStatement(const nsACString& aQuery) {
ScopedLogExtraInfo{ScopedLogExtraInfo::kTagQuery, aQuery};
QM_TRY_RETURN(
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
**mStorageConnection,
CreateStatement, aQuery),
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, **mStorageConnection,
CreateStatement, aQuery),
QM_PROPAGATE,
([&aQuery,
&storageConnection = **mStorageConnection](const auto&) {

View File

@ -210,8 +210,9 @@ class CachingDatabaseConnection::LazyStatement final {
QM_TRY(std::forward<BindFunctor>(aBindFunctor)(*borrowedStatement));
QM_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(&*borrowedStatement, ExecuteStep));
QM_TRY_INSPECT(
const bool& hasResult,
MOZ_TO_RESULT_INVOKE_MEMBER(&*borrowedStatement, ExecuteStep));
return hasResult ? Some(std::move(borrowedStatement)) : Nothing{};
}

View File

@ -161,8 +161,8 @@ nsDependentCSubstring GetLeafName(const nsACString& aPath) {
Result<nsCOMPtr<nsIFile>, nsresult> CloneFileAndAppend(
nsIFile& aDirectory, const nsAString& aPathElement) {
QM_TRY_UNWRAP(auto resultFile, MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>,
aDirectory, Clone));
QM_TRY_UNWRAP(auto resultFile, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<nsIFile>, aDirectory, Clone));
QM_TRY(MOZ_TO_RESULT(resultFile->Append(aPathElement)));
@ -176,10 +176,11 @@ Result<nsIFileKind, nsresult> GetDirEntryKind(nsIFile& aFile) {
// NS_ERROR_FILE_TARGET_DOES_NOT_EXIST and NS_ERROR_FILE_FS_CORRUPTED results
// and not spam the reports.
QM_TRY_RETURN(QM_OR_ELSE_LOG_VERBOSE_IF(
MOZ_TO_RESULT_INVOKE(aFile, IsDirectory).map([](const bool isDirectory) {
return isDirectory ? nsIFileKind::ExistsAsDirectory
: nsIFileKind::ExistsAsFile;
}),
MOZ_TO_RESULT_INVOKE_MEMBER(aFile, IsDirectory)
.map([](const bool isDirectory) {
return isDirectory ? nsIFileKind::ExistsAsDirectory
: nsIFileKind::ExistsAsFile;
}),
([](const nsresult rv) {
return rv == NS_ERROR_FILE_NOT_FOUND ||
rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ||
@ -192,16 +193,16 @@ Result<nsIFileKind, nsresult> GetDirEntryKind(nsIFile& aFile) {
Result<nsCOMPtr<mozIStorageStatement>, nsresult> CreateStatement(
mozIStorageConnection& aConnection, const nsACString& aStatementString) {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<mozIStorageStatement>,
aConnection, CreateStatement,
aStatementString));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection, CreateStatement,
aStatementString));
}
template <SingleStepResult ResultHandling>
Result<SingleStepSuccessType<ResultHandling>, nsresult> ExecuteSingleStep(
nsCOMPtr<mozIStorageStatement>&& aStatement) {
QM_TRY_INSPECT(const bool& hasResult,
MOZ_TO_RESULT_INVOKE(aStatement, ExecuteStep));
MOZ_TO_RESULT_INVOKE_MEMBER(aStatement, ExecuteStep));
if constexpr (ResultHandling == SingleStepResult::AssertHasResult) {
MOZ_ASSERT(hasResult);
@ -227,7 +228,7 @@ template <SingleStepResult ResultHandling>
Result<SingleStepSuccessType<ResultHandling>, nsresult>
CreateAndExecuteSingleStepStatement(mozIStorageConnection& aConnection,
const nsACString& aStatementString) {
QM_TRY_UNWRAP(auto stmt, MOZ_TO_RESULT_INVOKE_TYPED(
QM_TRY_UNWRAP(auto stmt, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, aConnection,
CreateStatement, aStatementString));

View File

@ -1409,7 +1409,9 @@ template <typename StepFunc>
Result<Ok, nsresult> CollectWhileHasResult(mozIStorageStatement& aStmt,
StepFunc&& aStepFunc) {
return CollectWhile(
[&aStmt] { QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE(aStmt, ExecuteStep)); },
[&aStmt] {
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(aStmt, ExecuteStep));
},
[&aStmt, &aStepFunc] { return aStepFunc(aStmt); });
}
@ -1443,9 +1445,9 @@ template <typename Cancel, typename Body>
Result<mozilla::Ok, nsresult> CollectEachFile(nsIFile& aDirectory,
const Cancel& aCancel,
const Body& aBody) {
QM_TRY_INSPECT(const auto& entries,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIDirectoryEnumerator>,
aDirectory, GetDirectoryEntries));
QM_TRY_INSPECT(const auto& entries, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<nsIDirectoryEnumerator>,
aDirectory, GetDirectoryEntries));
return CollectEach(
[&entries, &aCancel]() -> Result<nsCOMPtr<nsIFile>, nsresult> {
@ -1453,8 +1455,8 @@ Result<mozilla::Ok, nsresult> CollectEachFile(nsIFile& aDirectory,
return nsCOMPtr<nsIFile>{};
}
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, entries,
GetNextFile));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<nsIFile>,
entries, GetNextFile));
},
aBody);
}
@ -1478,9 +1480,9 @@ template <typename T, typename Body>
auto ReduceEachFileAtomicCancelable(nsIFile& aDirectory,
const Atomic<bool>& aCanceled, T aInit,
const Body& aBody) -> Result<T, nsresult> {
QM_TRY_INSPECT(const auto& entries,
MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIDirectoryEnumerator>,
aDirectory, GetDirectoryEntries));
QM_TRY_INSPECT(const auto& entries, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<nsIDirectoryEnumerator>,
aDirectory, GetDirectoryEntries));
return ReduceEach(
[&entries, &aCanceled]() -> Result<nsCOMPtr<nsIFile>, nsresult> {
@ -1488,8 +1490,8 @@ auto ReduceEachFileAtomicCancelable(nsIFile& aDirectory,
return nsCOMPtr<nsIFile>{};
}
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, entries,
GetNextFile));
QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<nsIFile>,
entries, GetNextFile));
},
std::move(aInit), aBody);
}

View File

@ -109,15 +109,15 @@ Result<R, nsresult> ToResultGet(const Func& aFunc, Args&&... aArgs) {
#define MOZ_TO_RESULT_GET_TYPED(resultType, ...) \
::mozilla::ToResultGet<MOZ_REMOVE_PAREN(resultType)>(__VA_ARGS__)
#define QM_TO_RESULT_INVOKE(obj, methodname, ...) \
::mozilla::ToResultInvoke<QMResult>( \
#define QM_TO_RESULT_INVOKE_MEMBER(obj, methodname, ...) \
::mozilla::ToResultInvokeMember<QMResult>( \
(obj), &::mozilla::detail::DerefedType<decltype(obj)>::methodname, \
##__VA_ARGS__)
#define QM_TO_RESULT_INVOKE_TYPED(resultType, obj, methodname, ...) \
(::mozilla::ToResultInvoke<resultType, QMResult>( \
::std::mem_fn( \
&::mozilla::detail::DerefedType<decltype(obj)>::methodname), \
#define QM_TO_RESULT_INVOKE_MEMBER_TYPED(resultType, obj, methodname, ...) \
(::mozilla::ToResultInvoke<resultType, QMResult>( \
::std::mem_fn( \
&::mozilla::detail::DerefedType<decltype(obj)>::methodname), \
(obj), ##__VA_ARGS__))
#endif

View File

@ -33,18 +33,18 @@ nsresult AutoDatabaseAttacher::Attach() {
#ifdef DEBUG
{
QM_TRY_INSPECT(const bool& exists,
MOZ_TO_RESULT_INVOKE(mDatabaseFile, Exists));
MOZ_TO_RESULT_INVOKE_MEMBER(mDatabaseFile, Exists));
MOZ_ASSERT(exists);
}
#endif
QM_TRY_INSPECT(const auto& path,
MOZ_TO_RESULT_INVOKE_TYPED(nsString, mDatabaseFile, GetPath));
QM_TRY_INSPECT(const auto& path, MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsString, mDatabaseFile, GetPath));
QM_TRY_INSPECT(
const auto& stmt,
MOZ_TO_RESULT_INVOKE_TYPED(
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(
nsCOMPtr<mozIStorageStatement>, mConnection, CreateStatement,
"ATTACH DATABASE :path AS "_ns + mSchemaName + ";"_ns));

View File

@ -1710,7 +1710,7 @@ Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
[](UsageInfo usageInfo,
const nsCOMPtr<nsIFile>& file) -> Result<UsageInfo, nsresult> {
QM_TRY_INSPECT(const bool& isDirectory,
MOZ_TO_RESULT_INVOKE(file, IsDirectory));
MOZ_TO_RESULT_INVOKE_MEMBER(file, IsDirectory));
if (isDirectory) {
Unused << WARN_IF_FILE_IS_UNKNOWN(*file);
@ -1722,7 +1722,7 @@ Result<UsageInfo, nsresult> QuotaClient::GetUsageForOrigin(
if (StringEndsWith(leafName, kSDBSuffix)) {
QM_TRY_INSPECT(const int64_t& fileSize,
MOZ_TO_RESULT_INVOKE(file, GetFileSize));
MOZ_TO_RESULT_INVOKE_MEMBER(file, GetFileSize));
MOZ_ASSERT(fileSize >= 0);

View File

@ -161,12 +161,11 @@ auto ToResultInvokeSelector(const Func& aFunc, Args&&... aArgs)
* auto existsOrErr = ToResultInvoke<bool>(std::mem_fn(&nsIFile::Exists),
* *file);
*
* but it is more convenient to use the member function overload, which
* has the additional benefit of enabling the deduction of the success result
* type:
* but it is more convenient to use the member function version, which has the
* additional benefit of enabling the deduction of the success result type:
*
* nsCOMPtr<nsIFile> file = ...;
* auto existsOrErr = ToResultInvoke(*file, &nsIFile::Exists);
* auto existsOrErr = ToResultInvokeMember(*file, &nsIFile::Exists);
*/
template <typename R, typename E = nsresult, typename Func, typename... Args>
Result<R, E> ToResultInvoke(const Func& aFunc, Args&&... aArgs) {
@ -211,7 +210,7 @@ auto ToResultInvokeMemberInternal(T& aObj, const Func& aFunc, Args&&... aArgs) {
}
}
// For use in MOZ_TO_RESULT_INVOKE.
// For use in MOZ_TO_RESULT_INVOKE_MEMBER/MOZ_TO_RESULT_INVOKE_MEMBER_TYPED.
template <typename T>
auto DerefHelper(const T&) -> T&;
@ -230,7 +229,8 @@ using DerefedType =
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>>
auto ToResultInvoke(T& aObj, nsresult (U::*aFunc)(XArgs...), Args&&... aArgs) {
auto ToResultInvokeMember(T& aObj, nsresult (U::*aFunc)(XArgs...),
Args&&... aArgs) {
return detail::ToResultInvokeMemberInternal<E,
detail::select_last_t<XArgs...>>(
aObj, aFunc, std::forward<Args>(aArgs)...);
@ -239,8 +239,8 @@ auto ToResultInvoke(T& aObj, nsresult (U::*aFunc)(XArgs...), Args&&... aArgs) {
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>>
auto ToResultInvoke(const T& aObj, nsresult (U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
auto ToResultInvokeMember(const T& aObj, nsresult (U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return detail::ToResultInvokeMemberInternal<E,
detail::select_last_t<XArgs...>>(
aObj, aFunc, std::forward<Args>(aArgs)...);
@ -248,42 +248,44 @@ auto ToResultInvoke(const T& aObj, nsresult (U::*aFunc)(XArgs...) const,
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args>
auto ToResultInvoke(T* const aObj, nsresult (U::*aFunc)(XArgs...),
Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(T* const aObj, nsresult (U::*aFunc)(XArgs...),
Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args>
auto ToResultInvoke(const T* const aObj, nsresult (U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(const T* const aObj,
nsresult (U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, template <class> class SmartPtr, typename T,
typename U, typename... XArgs, typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>,
typename = decltype(*std::declval<const SmartPtr<T>>())>
auto ToResultInvoke(const SmartPtr<T>& aObj, nsresult (U::*aFunc)(XArgs...),
Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(const SmartPtr<T>& aObj,
nsresult (U::*aFunc)(XArgs...), Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, template <class> class SmartPtr, typename T,
typename U, typename... XArgs, typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>,
typename = decltype(*std::declval<const SmartPtr<T>>())>
auto ToResultInvoke(const SmartPtr<const T>& aObj,
nsresult (U::*aFunc)(XArgs...) const, Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(const SmartPtr<const T>& aObj,
nsresult (U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
#if defined(XP_WIN) && !defined(_WIN64)
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>>
auto ToResultInvoke(T& aObj, nsresult (__stdcall U::*aFunc)(XArgs...),
Args&&... aArgs) {
auto ToResultInvokeMember(T& aObj, nsresult (__stdcall U::*aFunc)(XArgs...),
Args&&... aArgs) {
return detail::ToResultInvokeMemberInternal<E,
detail::select_last_t<XArgs...>>(
aObj, aFunc, std::forward<Args>(aArgs)...);
@ -292,9 +294,9 @@ auto ToResultInvoke(T& aObj, nsresult (__stdcall U::*aFunc)(XArgs...),
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>>
auto ToResultInvoke(const T& aObj,
nsresult (__stdcall U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
auto ToResultInvokeMember(const T& aObj,
nsresult (__stdcall U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return detail::ToResultInvokeMemberInternal<E,
detail::select_last_t<XArgs...>>(
aObj, aFunc, std::forward<Args>(aArgs)...);
@ -302,62 +304,65 @@ auto ToResultInvoke(const T& aObj,
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args>
auto ToResultInvoke(T* const aObj, nsresult (__stdcall U::*aFunc)(XArgs...),
Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(T* const aObj,
nsresult (__stdcall U::*aFunc)(XArgs...),
Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, typename T, typename U, typename... XArgs,
typename... Args>
auto ToResultInvoke(const T* const aObj,
nsresult (__stdcall U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(const T* const aObj,
nsresult (__stdcall U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, template <class> class SmartPtr, typename T,
typename U, typename... XArgs, typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>,
typename = decltype(*std::declval<const SmartPtr<T>>())>
auto ToResultInvoke(const SmartPtr<T>& aObj,
nsresult (__stdcall U::*aFunc)(XArgs...), Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(const SmartPtr<T>& aObj,
nsresult (__stdcall U::*aFunc)(XArgs...),
Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
template <typename E = nsresult, template <class> class SmartPtr, typename T,
typename U, typename... XArgs, typename... Args,
typename = std::enable_if_t<std::is_base_of_v<U, T>>,
typename = decltype(*std::declval<const SmartPtr<T>>())>
auto ToResultInvoke(const SmartPtr<const T>& aObj,
nsresult (__stdcall U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return ToResultInvoke<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
auto ToResultInvokeMember(const SmartPtr<const T>& aObj,
nsresult (__stdcall U::*aFunc)(XArgs...) const,
Args&&... aArgs) {
return ToResultInvokeMember<E>(*aObj, aFunc, std::forward<Args>(aArgs)...);
}
#endif
// Macro version of ToResultInvoke for member functions. The macro has the
// advantage of not requiring spelling out the member function's declarator type
// name, at the expense of having a non-standard syntax. It can be used like
// this:
// Macro version of ToResultInvokeMember for member functions. The macro has
// the advantage of not requiring spelling out the member function's declarator
// type name, at the expense of having a non-standard syntax. It can be used
// like this:
//
// nsCOMPtr<nsIFile> file;
// auto existsOrErr = MOZ_TO_RESULT_INVOKE(file, Exists);
#define MOZ_TO_RESULT_INVOKE(obj, methodname, ...) \
::mozilla::ToResultInvoke( \
// auto existsOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(file, Exists);
#define MOZ_TO_RESULT_INVOKE_MEMBER(obj, methodname, ...) \
::mozilla::ToResultInvokeMember( \
(obj), &::mozilla::detail::DerefedType<decltype(obj)>::methodname, \
##__VA_ARGS__)
// Macro version of ToResultInvoke for member functions, where the result type
// does not match the output parameter type. The macro has the advantage of not
// requiring spelling out the member function's declarator type name, at the
// expense of having a non-standard syntax. It can be used like this:
// Macro version of ToResultInvokeMember for member functions, where the result
// type does not match the output parameter type. The macro has the advantage
// of not requiring spelling out the member function's declarator type name, at
// the expense of having a non-standard syntax. It can be used like this:
//
// nsCOMPtr<nsIFile> file;
// auto existsOrErr = MOZ_TO_RESULT_INVOKE(nsCOMPtr<nsIFile>, file, Clone);
#define MOZ_TO_RESULT_INVOKE_TYPED(resultType, obj, methodname, ...) \
::mozilla::ToResultInvoke<resultType>( \
::std::mem_fn( \
&::mozilla::detail::DerefedType<decltype(obj)>::methodname), \
// auto existsOrErr =
// MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<nsIFile>, file, Clone);
#define MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(resultType, obj, methodname, ...) \
::mozilla::ToResultInvoke<resultType>( \
::std::mem_fn( \
&::mozilla::detail::DerefedType<decltype(obj)>::methodname), \
(obj), ##__VA_ARGS__)
} // namespace mozilla

View File

@ -87,7 +87,7 @@ static_assert(
std::is_same_v<mozilla::detail::DerefedType<nsCOMPtr<nsIFile>>, nsIFile>);
} // namespace
TEST(ResultExtensions_ToResultInvoke, Lambda)
TEST(ResultExtensions_ToResultInvoke, Lambda_NoInput)
{
TestClass foo;
@ -110,7 +110,7 @@ TEST(ResultExtensions_ToResultInvoke, Lambda)
}
}
TEST(ResultExtensions_ToResultInvoke, MemFn)
TEST(ResultExtensions_ToResultInvoke, MemFn_NoInput)
{
TestClass foo;
@ -133,225 +133,7 @@ TEST(ResultExtensions_ToResultInvoke, MemFn)
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoInput)
{
TestClass foo;
// success
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedNoInput);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedNoInputFails);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoInput_Const)
{
const TestClass foo;
// success
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedNoInputConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr =
ToResultInvoke(foo, &TestClass::NonOverloadedNoInputFailsConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoInput_Ref)
{
TestClass foo;
// success
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedNoInputRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr =
ToResultInvoke(foo, &TestClass::NonOverloadedNoInputFailsRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_WithInput)
{
TestClass foo;
// success
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedWithInput,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(-TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedWithInputFails,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoOutput)
{
TestClass foo;
// success
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedNoOutput,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
}
// failure
{
auto valOrErr = ToResultInvoke(foo, &TestClass::NonOverloadedNoOutputFails,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoInput_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInput);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInputFails);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoInput_Const_Macro)
{
const TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInputConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInputFailsConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoInput_Ref_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInputRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInputFailsRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_WithInput_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedWithInput,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(-TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedWithInputFails,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, MemberFunction_NoOutput_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoOutput,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoOutputFails,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, PolymorphicPointerResult_nsCOMPtr_Result)
TEST(ResultExtensions_ToResultInvoke, MemFn_Polymorphic_NoInput)
{
TestClass foo;
@ -383,14 +165,13 @@ TEST(ResultExtensions_ToResultInvoke, PolymorphicPointerResult_nsCOMPtr_Result)
}
}
TEST(ResultExtensions_ToResultInvoke, RefPtr_MemberFunction_NoInput)
TEST(ResultExtensions_ToResultInvokeMember, NoInput)
{
auto foo = MakeRefPtr<RefCountedTestClass>();
TestClass foo;
// success
{
auto valOrErr =
ToResultInvoke(foo, &RefCountedTestClass::NonOverloadedNoInput);
auto valOrErr = ToResultInvokeMember(foo, &TestClass::NonOverloadedNoInput);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
@ -399,20 +180,21 @@ TEST(ResultExtensions_ToResultInvoke, RefPtr_MemberFunction_NoInput)
// failure
{
auto valOrErr =
ToResultInvoke(foo, &RefCountedTestClass::NonOverloadedNoInputFails);
ToResultInvokeMember(foo, &TestClass::NonOverloadedNoInputFails);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, RefPtr_MemberFunction_NoInput_Macro)
TEST(ResultExtensions_ToResultInvokeMember, NoInput_Const)
{
auto foo = MakeRefPtr<RefCountedTestClass>();
const TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInput);
auto valOrErr =
ToResultInvokeMember(foo, &TestClass::NonOverloadedNoInputConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
@ -420,21 +202,244 @@ TEST(ResultExtensions_ToResultInvoke, RefPtr_MemberFunction_NoInput_Macro)
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(foo, NonOverloadedNoInputFails);
auto valOrErr =
ToResultInvokeMember(foo, &TestClass::NonOverloadedNoInputFailsConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, RawPtr_MemberFunction_NoInput_Macro)
TEST(ResultExtensions_ToResultInvokeMember, NoInput_Ref)
{
TestClass foo;
// success
{
auto valOrErr =
ToResultInvokeMember(foo, &TestClass::NonOverloadedNoInputRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr =
ToResultInvokeMember(foo, &TestClass::NonOverloadedNoInputFailsRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, WithInput)
{
TestClass foo;
// success
{
auto valOrErr = ToResultInvokeMember(
foo, &TestClass::NonOverloadedWithInput, -TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(-TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = ToResultInvokeMember(
foo, &TestClass::NonOverloadedWithInputFails, -TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, NoOutput)
{
TestClass foo;
// success
{
auto valOrErr = ToResultInvokeMember(foo, &TestClass::NonOverloadedNoOutput,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
}
// failure
{
auto valOrErr = ToResultInvokeMember(
foo, &TestClass::NonOverloadedNoOutputFails, -TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, NoInput_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInput);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInputFails);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, NoInput_Const_Macro)
{
const TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInputConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr =
MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInputFailsConst);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, NoInput_Ref_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInputRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr =
MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInputFailsRef);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, WithInput_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedWithInput,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(-TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(
foo, NonOverloadedWithInputFails, -TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, NoOutput_Macro)
{
TestClass foo;
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoOutput,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoOutputFails,
-TestClass::kTestValue);
static_assert(std::is_same_v<decltype(valOrErr), Result<Ok, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, RefPtr_NoInput)
{
auto foo = MakeRefPtr<RefCountedTestClass>();
// success
{
auto valOrErr =
ToResultInvokeMember(foo, &RefCountedTestClass::NonOverloadedNoInput);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = ToResultInvokeMember(
foo, &RefCountedTestClass::NonOverloadedNoInputFails);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, RefPtr_NoInput_Macro)
{
auto foo = MakeRefPtr<RefCountedTestClass>();
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInput);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
}
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(foo, NonOverloadedNoInputFails);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvokeMember, RawPtr_NoInput_Macro)
{
auto foo = MakeRefPtr<RefCountedTestClass>();
auto* fooPtr = foo.get();
// success
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(fooPtr, NonOverloadedNoInput);
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(fooPtr, NonOverloadedNoInput);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(TestClass::kTestValue, valOrErr.unwrap());
@ -442,37 +447,44 @@ TEST(ResultExtensions_ToResultInvoke, RawPtr_MemberFunction_NoInput_Macro)
// failure
{
auto valOrErr = MOZ_TO_RESULT_INVOKE(fooPtr, NonOverloadedNoInputFails);
auto valOrErr =
MOZ_TO_RESULT_INVOKE_MEMBER(fooPtr, NonOverloadedNoInputFails);
static_assert(std::is_same_v<decltype(valOrErr), Result<int, nsresult>>);
ASSERT_TRUE(valOrErr.isErr());
ASSERT_EQ(NS_ERROR_FAILURE, valOrErr.unwrapErr());
}
}
TEST(ResultExtensions_ToResultInvoke, nsCOMPtr_NS_IMETHOD_bool_Result)
TEST(ResultExtensions_ToResultInvokeMember, nsCOMPtr_AbstractClass_WithInput)
{
nsCOMPtr<nsIFile> file = MakeAndAddRef<nsLocalFile>();
ASSERT_TRUE(ToResultInvoke(file, &nsIFile::Equals, file).isOk());
}
TEST(ResultExtensions_ToResultInvoke, RawPtr_AbstractClass_MemberFunction_Macro)
{
nsCOMPtr<nsIFile> file = MakeAndAddRef<nsLocalFile>();
auto* filePtr = file.get();
auto valOrErr = MOZ_TO_RESULT_INVOKE(filePtr, Equals, file);
auto valOrErr = ToResultInvokeMember(file, &nsIFile::Equals, file);
static_assert(std::is_same_v<decltype(valOrErr), Result<bool, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(true, valOrErr.unwrap());
}
TEST(ResultExtensions_ToResultInvoke,
RawPtr_AbstractClass_MemberFunction_NoInput_Macro_Typed)
TEST(ResultExtensions_ToResultInvokeMember,
RawPtr_AbstractClass_WithInput_Macro)
{
nsCOMPtr<nsIFile> file = MakeAndAddRef<nsLocalFile>();
auto* filePtr = file.get();
auto valOrErr = MOZ_TO_RESULT_INVOKE_TYPED(nsCOMPtr<nsIFile>, filePtr, Clone);
auto valOrErr = MOZ_TO_RESULT_INVOKE_MEMBER(filePtr, Equals, file);
static_assert(std::is_same_v<decltype(valOrErr), Result<bool, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());
ASSERT_EQ(true, valOrErr.unwrap());
}
TEST(ResultExtensions_ToResultInvokeMember,
RawPtr_AbstractClass_NoInput_Macro_Typed)
{
nsCOMPtr<nsIFile> file = MakeAndAddRef<nsLocalFile>();
auto* filePtr = file.get();
auto valOrErr =
MOZ_TO_RESULT_INVOKE_MEMBER_TYPED(nsCOMPtr<nsIFile>, filePtr, Clone);
static_assert(
std::is_same_v<decltype(valOrErr), Result<nsCOMPtr<nsIFile>, nsresult>>);
ASSERT_TRUE(valOrErr.isOk());