From adc8da34e90f3e02a8d8a8d280713e96b367831e Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Tue, 30 Nov 2021 05:05:51 +0000 Subject: [PATCH] Bug 1731960 - Move all Result extensions from QMResult.h to a dedicated file; r=dom-storage-reviewers,jari Differential Revision: https://phabricator.services.mozilla.com/D126324 --- dom/cache/Cache.cpp | 1 + dom/cache/CacheStorage.cpp | 1 + dom/cache/Context.cpp | 1 + dom/cache/DBAction.cpp | 1 + dom/cache/DBSchema.cpp | 2 +- dom/cache/FileUtils.cpp | 2 +- dom/cache/FileUtilsImpl.h | 1 + dom/cache/PrincipalVerifier.cpp | 2 +- dom/cache/QuotaClientImpl.h | 2 +- dom/indexedDB/ActorsChild.cpp | 1 + dom/indexedDB/ActorsParent.cpp | 2 +- dom/indexedDB/ActorsParentCommon.cpp | 1 + dom/indexedDB/DBSchema.cpp | 1 + dom/indexedDB/FileInfoImpl.h | 2 +- dom/indexedDB/IDBDatabase.cpp | 2 +- dom/indexedDB/IndexedDatabaseManager.cpp | 1 + dom/indexedDB/Key.cpp | 1 + dom/indexedDB/KeyPath.cpp | 1 + dom/indexedDB/PermissionRequestBase.cpp | 1 + dom/indexedDB/SchemaUpgrades.cpp | 1 + dom/localstorage/ActorsParent.cpp | 2 +- dom/localstorage/LocalStorageCommon.cpp | 1 + dom/quota/ActorsParent.cpp | 2 +- dom/quota/CachingDatabaseConnection.h | 1 + dom/quota/FileStreams.cpp | 1 + dom/quota/ForwardDecls.h | 32 +++++ dom/quota/QMResult.h | 36 +----- dom/quota/QuotaCommon.cpp | 1 + dom/quota/QuotaManager.h | 2 +- dom/quota/QuotaManagerService.cpp | 1 + .../{QMResultInlines.h => ResultExtensions.h} | 24 +++- dom/quota/StorageHelpers.cpp | 2 + dom/quota/moz.build | 3 +- dom/quota/test/gtest/Common.cpp | 28 +++++ dom/quota/test/gtest/Common.h | 32 +++++ dom/quota/test/gtest/TestForwardDecls.cpp | 12 ++ dom/quota/test/gtest/TestQMResult.cpp | 116 +++--------------- dom/quota/test/gtest/TestQuotaCommon.cpp | 1 + dom/quota/test/gtest/TestResultExtensions.cpp | 110 +++++++++++++++++ dom/quota/test/gtest/moz.build | 3 + dom/simpledb/ActorsParent.cpp | 1 + 41 files changed, 289 insertions(+), 149 deletions(-) create mode 100644 dom/quota/ForwardDecls.h rename dom/quota/{QMResultInlines.h => ResultExtensions.h} (74%) create mode 100644 dom/quota/test/gtest/Common.cpp create mode 100644 dom/quota/test/gtest/Common.h create mode 100644 dom/quota/test/gtest/TestForwardDecls.cpp create mode 100644 dom/quota/test/gtest/TestResultExtensions.cpp diff --git a/dom/cache/Cache.cpp b/dom/cache/Cache.cpp index d6ad87175e1e..600413900b89 100644 --- a/dom/cache/Cache.cpp +++ b/dom/cache/Cache.cpp @@ -20,6 +20,7 @@ #include "mozilla/dom/cache/CacheCommon.h" #include "mozilla/dom/cache/CacheWorkerRef.h" #include "mozilla/dom/cache/ReadStream.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/ErrorResult.h" #include "mozilla/Preferences.h" #include "mozilla/Unused.h" diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index b0378333e536..4e54ba91a7dc 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -23,6 +23,7 @@ #include "mozilla/dom/cache/ReadStream.h" #include "mozilla/dom/cache/TypeUtils.h" #include "mozilla/dom/quota/QuotaManager.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/WorkerPrivate.h" #include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/BackgroundUtils.h" diff --git a/dom/cache/Context.cpp b/dom/cache/Context.cpp index 9395498084e6..81f1a5d3000b 100644 --- a/dom/cache/Context.cpp +++ b/dom/cache/Context.cpp @@ -16,6 +16,7 @@ #include "mozilla/dom/cache/ManagerId.h" #include "mozilla/dom/quota/DirectoryLock.h" #include "mozilla/dom/quota/QuotaManager.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozIStorageConnection.h" #include "nsIPrincipal.h" #include "nsIRunnable.h" diff --git a/dom/cache/DBAction.cpp b/dom/cache/DBAction.cpp index 831faeff00af..b85ca6acdaa5 100644 --- a/dom/cache/DBAction.cpp +++ b/dom/cache/DBAction.cpp @@ -11,6 +11,7 @@ #include "mozilla/dom/cache/FileUtils.h" #include "mozilla/dom/cache/QuotaClient.h" #include "mozilla/dom/quota/PersistenceType.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/net/nsFileProtocolHandler.h" #include "mozIStorageConnection.h" #include "mozIStorageService.h" diff --git a/dom/cache/DBSchema.cpp b/dom/cache/DBSchema.cpp index 7c6b396cb5e2..f48b56de63ab 100644 --- a/dom/cache/DBSchema.cpp +++ b/dom/cache/DBSchema.cpp @@ -11,7 +11,6 @@ #include "mozilla/dom/HeadersBinding.h" #include "mozilla/dom/InternalHeaders.h" #include "mozilla/dom/InternalResponse.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/ResponseBinding.h" #include "mozilla/dom/cache/CacheCommon.h" @@ -19,6 +18,7 @@ #include "mozilla/dom/cache/SavedTypes.h" #include "mozilla/dom/cache/Types.h" #include "mozilla/dom/cache/TypeUtils.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/net/MozURL.h" #include "mozilla/ResultExtensions.h" #include "mozilla/StaticPrefs_extensions.h" diff --git a/dom/cache/FileUtils.cpp b/dom/cache/FileUtils.cpp index 7f0916eb3f4c..5a3a53b6a6df 100644 --- a/dom/cache/FileUtils.cpp +++ b/dom/cache/FileUtils.cpp @@ -8,10 +8,10 @@ #include "DBSchema.h" #include "mozilla/dom/InternalResponse.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/quota/FileStreams.h" #include "mozilla/dom/quota/QuotaManager.h" #include "mozilla/dom/quota/QuotaObject.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/ScopeExit.h" #include "mozilla/SnappyCompressOutputStream.h" #include "mozilla/Unused.h" diff --git a/dom/cache/FileUtilsImpl.h b/dom/cache/FileUtilsImpl.h index 53fdc4e61b56..57820f44d0b2 100644 --- a/dom/cache/FileUtilsImpl.h +++ b/dom/cache/FileUtilsImpl.h @@ -9,6 +9,7 @@ #include "mozilla/dom/FlippedOnce.h" #include "mozilla/dom/cache/FileUtils.h" +#include "mozilla/dom/quota/ResultExtensions.h" namespace mozilla { namespace dom { diff --git a/dom/cache/PrincipalVerifier.cpp b/dom/cache/PrincipalVerifier.cpp index 535cbe4a46d0..8ee04e30d2e3 100644 --- a/dom/cache/PrincipalVerifier.cpp +++ b/dom/cache/PrincipalVerifier.cpp @@ -9,8 +9,8 @@ #include "ErrorList.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/QMResult.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/cache/ManagerId.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/ipc/BackgroundParent.h" #include "mozilla/ipc/PBackgroundParent.h" #include "mozilla/ipc/BackgroundUtils.h" diff --git a/dom/cache/QuotaClientImpl.h b/dom/cache/QuotaClientImpl.h index c150836f25d1..bd7e672e6b1a 100644 --- a/dom/cache/QuotaClientImpl.h +++ b/dom/cache/QuotaClientImpl.h @@ -8,9 +8,9 @@ #define mozilla_dom_cache_QuotaClientImpl_h #include "mozilla/dom/QMResult.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/cache/QuotaClient.h" #include "mozilla/dom/cache/FileUtils.h" +#include "mozilla/dom/quota/ResultExtensions.h" namespace mozilla { namespace dom { diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index 602ff58a2f67..0052c6ee6179 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -38,6 +38,7 @@ #include "mozilla/dom/IPCBlobUtils.h" #include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerRunnable.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/Encoding.h" #include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/ProfilerLabels.h" diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index d82edeb7de23..ee39eb58cf54 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -102,7 +102,6 @@ #include "mozilla/dom/Nullable.h" #include "mozilla/dom/PBackgroundMutableFileParent.h" #include "mozilla/dom/PContentParent.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/filehandle/ActorsParent.h" #include "mozilla/dom/indexedDB/IDBResult.h" @@ -136,6 +135,7 @@ #include "mozilla/dom/quota/QuotaCommon.h" #include "mozilla/dom/quota/QuotaManager.h" #include "mozilla/dom/quota/QuotaObject.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/UsageInfo.h" #include "mozilla/fallible.h" #include "mozilla/ipc/BackgroundParent.h" diff --git a/dom/indexedDB/ActorsParentCommon.cpp b/dom/indexedDB/ActorsParentCommon.cpp index b05d91b7f713..a3d5936dc49b 100644 --- a/dom/indexedDB/ActorsParentCommon.cpp +++ b/dom/indexedDB/ActorsParentCommon.cpp @@ -41,6 +41,7 @@ #include "mozilla/TelemetryScalarEnums.h" #include "mozilla/dom/quota/DecryptingInputStream_impl.h" #include "mozilla/dom/quota/QuotaCommon.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/ScopedLogExtraInfo.h" #include "mozilla/fallible.h" #include "mozilla/ipc/BackgroundParent.h" diff --git a/dom/indexedDB/DBSchema.cpp b/dom/indexedDB/DBSchema.cpp index d8be3524e384..b6d5bf01e871 100644 --- a/dom/indexedDB/DBSchema.cpp +++ b/dom/indexedDB/DBSchema.cpp @@ -15,6 +15,7 @@ #include "js/StructuredClone.h" #include "mozIStorageConnection.h" #include "mozilla/dom/quota/QuotaCommon.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/ProfilerLabels.h" #include "nsDebug.h" #include "nsError.h" diff --git a/dom/indexedDB/FileInfoImpl.h b/dom/indexedDB/FileInfoImpl.h index f6fd18a28f56..33566d7d9c32 100644 --- a/dom/indexedDB/FileInfoImpl.h +++ b/dom/indexedDB/FileInfoImpl.h @@ -10,8 +10,8 @@ #include "FileInfo.h" #include "mozilla/dom/QMResult.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/quota/QuotaCommon.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/Mutex.h" #include "nsIFile.h" diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index e87003169aa7..ad9687f164e4 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -33,8 +33,8 @@ #include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h" #include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h" #include "mozilla/dom/IPCBlobUtils.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/quota/QuotaManager.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/ipc/FileDescriptor.h" diff --git a/dom/indexedDB/IndexedDatabaseManager.cpp b/dom/indexedDB/IndexedDatabaseManager.cpp index f34845163f3c..cf4acac13394 100644 --- a/dom/indexedDB/IndexedDatabaseManager.cpp +++ b/dom/indexedDB/IndexedDatabaseManager.cpp @@ -23,6 +23,7 @@ #include "mozilla/dom/ErrorEventBinding.h" #include "mozilla/dom/WorkerScope.h" #include "mozilla/dom/WorkerPrivate.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/intl/LocaleCanonicalizer.h" #include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/PBackgroundChild.h" diff --git a/dom/indexedDB/Key.cpp b/dom/indexedDB/Key.cpp index 37ccba1fc0cd..38bee65d960a 100644 --- a/dom/indexedDB/Key.cpp +++ b/dom/indexedDB/Key.cpp @@ -28,6 +28,7 @@ #include "mozilla/intl/Collator.h" #include "mozilla/ResultExtensions.h" #include "mozilla/ReverseIterator.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozIStorageStatement.h" #include "mozIStorageValueArray.h" #include "nsAlgorithm.h" diff --git a/dom/indexedDB/KeyPath.cpp b/dom/indexedDB/KeyPath.cpp index 25ad183ef474..d96e0bbd423e 100644 --- a/dom/indexedDB/KeyPath.cpp +++ b/dom/indexedDB/KeyPath.cpp @@ -19,6 +19,7 @@ #include "mozilla/dom/BlobBinding.h" #include "mozilla/dom/File.h" #include "mozilla/dom/IDBObjectStoreBinding.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "nsCharSeparatedTokenizer.h" #include "nsJSUtils.h" #include "nsPrintfCString.h" diff --git a/dom/indexedDB/PermissionRequestBase.cpp b/dom/indexedDB/PermissionRequestBase.cpp index ae9235ab15a6..8184d6899fcb 100644 --- a/dom/indexedDB/PermissionRequestBase.cpp +++ b/dom/indexedDB/PermissionRequestBase.cpp @@ -12,6 +12,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Services.h" #include "mozilla/dom/Element.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "nsIObserverService.h" #include "nsIPrincipal.h" #include "nsXULAppAPI.h" diff --git a/dom/indexedDB/SchemaUpgrades.cpp b/dom/indexedDB/SchemaUpgrades.cpp index f88e6f810113..9774f4725e46 100644 --- a/dom/indexedDB/SchemaUpgrades.cpp +++ b/dom/indexedDB/SchemaUpgrades.cpp @@ -49,6 +49,7 @@ #include "mozilla/dom/indexedDB/Key.h" #include "mozilla/dom/quota/PersistenceType.h" #include "mozilla/dom/quota/QuotaCommon.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/fallible.h" #include "mozilla/ipc/BackgroundParent.h" #include "mozilla/mozalloc.h" diff --git a/dom/localstorage/ActorsParent.cpp b/dom/localstorage/ActorsParent.cpp index fd098eac5c16..f33f861c9954 100644 --- a/dom/localstorage/ActorsParent.cpp +++ b/dom/localstorage/ActorsParent.cpp @@ -67,7 +67,6 @@ #include "mozilla/dom/PBackgroundLSSharedTypes.h" #include "mozilla/dom/PBackgroundLSSimpleRequestParent.h" #include "mozilla/dom/PBackgroundLSSnapshotParent.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/SnappyUtils.h" #include "mozilla/dom/StorageDBUpdater.h" #include "mozilla/dom/StorageUtils.h" @@ -84,6 +83,7 @@ #include "mozilla/dom/quota/StorageHelpers.h" #include "mozilla/dom/quota/QuotaManager.h" #include "mozilla/dom/quota/QuotaObject.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/UsageInfo.h" #include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/BackgroundParent.h" diff --git a/dom/localstorage/LocalStorageCommon.cpp b/dom/localstorage/LocalStorageCommon.cpp index f2130ea22731..faabcc9cb652 100644 --- a/dom/localstorage/LocalStorageCommon.cpp +++ b/dom/localstorage/LocalStorageCommon.cpp @@ -18,6 +18,7 @@ #include "mozilla/StaticPrefs_dom.h" #include "mozilla/StaticPrefs_network.h" #include "mozilla/dom/StorageUtils.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/ipc/PBackgroundSharedTypes.h" #include "mozilla/net/MozURL.h" #include "mozilla/net/WebSocketFrame.h" diff --git a/dom/quota/ActorsParent.cpp b/dom/quota/ActorsParent.cpp index f7c84a2c4342..389cd9403a53 100644 --- a/dom/quota/ActorsParent.cpp +++ b/dom/quota/ActorsParent.cpp @@ -77,7 +77,6 @@ #include "mozilla/dom/indexedDB/ActorsParent.h" #include "mozilla/dom/ipc/IdType.h" #include "mozilla/dom/localstorage/ActorsParent.h" -#include "mozilla/dom/QMResultInlines.h" #include "mozilla/dom/quota/CheckedUnsafePtr.h" #include "mozilla/dom/quota/Client.h" #include "mozilla/dom/quota/DirectoryLock.h" @@ -89,6 +88,7 @@ #include "mozilla/dom/quota/PQuotaUsageRequest.h" #include "mozilla/dom/quota/PQuotaUsageRequestParent.h" #include "mozilla/dom/quota/QuotaManagerImpl.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/ScopedLogExtraInfo.h" #include "mozilla/dom/simpledb/ActorsParent.h" #include "mozilla/fallible.h" diff --git a/dom/quota/CachingDatabaseConnection.h b/dom/quota/CachingDatabaseConnection.h index 29277bd4d82c..8c040e027ab6 100644 --- a/dom/quota/CachingDatabaseConnection.h +++ b/dom/quota/CachingDatabaseConnection.h @@ -20,6 +20,7 @@ #include "mozilla/InitializedOnce.h" #include "mozilla/NotNull.h" #include "mozilla/dom/quota/QuotaCommon.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/ScopedLogExtraInfo.h" namespace mozilla::dom::quota { diff --git a/dom/quota/FileStreams.cpp b/dom/quota/FileStreams.cpp index 237d71c78611..16b5544e9454 100644 --- a/dom/quota/FileStreams.cpp +++ b/dom/quota/FileStreams.cpp @@ -16,6 +16,7 @@ #include "mozilla/Assertions.h" #include "mozilla/DebugOnly.h" #include "mozilla/Result.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "nsDebug.h" #include "prio.h" diff --git a/dom/quota/ForwardDecls.h b/dom/quota/ForwardDecls.h new file mode 100644 index 000000000000..07b4d0f776ef --- /dev/null +++ b/dom/quota/ForwardDecls.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_QUOTA_FORWARD_DECLS_H_ +#define DOM_QUOTA_FORWARD_DECLS_H_ + +#include "mozilla/dom/quota/Config.h" + +#ifndef QM_ERROR_STACKS_ENABLED +enum class nsresult : uint32_t; +#endif + +namespace mozilla { + +#ifdef QM_ERROR_STACKS_ENABLED +class QMResult; +#else +using QMResult = nsresult; +#endif + +struct Ok; +template +class Result; + +using OkOrErr = Result; + +} // namespace mozilla + +#endif // DOM_QUOTA_FORWARD_DECLS_H_ diff --git a/dom/quota/QMResult.h b/dom/quota/QMResult.h index 10d280dc1cf4..f47c82584ebb 100644 --- a/dom/quota/QMResult.h +++ b/dom/quota/QMResult.h @@ -7,17 +7,13 @@ #ifndef DOM_QUOTA_QMRESULT_H_ #define DOM_QUOTA_QMRESULT_H_ -#include "mozilla/dom/quota/Config.h" - #include "ErrorList.h" +#include "mozilla/dom/quota/Config.h" +#include "mozilla/dom/quota/ForwardDecls.h" namespace mozilla { #ifdef QM_ERROR_STACKS_ENABLED -struct Ok; -template -class Result; - // A wrapped nsresult, primarily intended for use along with mozilla::Result // and QM_TRY macros. The wrapper contains stack id and frame id which are // reported in LogError besides the error result itself. @@ -53,38 +49,10 @@ class QMResult { QMResult(uint64_t aStackId, uint32_t aFrameId, nsresult aNSResult) : mStackId(aStackId), mFrameId(aFrameId), mNSResult(aNSResult) {} }; -#else -using QMResult = nsresult; #endif inline QMResult ToQMResult(nsresult aValue) { return QMResult(aValue); } -using OkOrErr = Result; - -#ifdef QM_ERROR_STACKS_ENABLED -template -inline Result ToResult(const QMResult& aValue); - -template -inline Result ToResult(QMResult&& aValue); -#endif - } // namespace mozilla -// TODO: Maybe move this to mfbt/ResultExtensions.h -#define MOZ_TO_RESULT(expr) ToResult(expr) - -#define QM_TO_RESULT(expr) ToResult(expr) - -#define QM_TO_RESULT_INVOKE(obj, methodname, ...) \ - ::mozilla::ToResultInvoke( \ - (obj), &::mozilla::detail::DerefedType::methodname, \ - ##__VA_ARGS__) - -#define QM_TO_RESULT_INVOKE_TYPED(resultType, obj, methodname, ...) \ - (::mozilla::ToResultInvoke( \ - ::std::mem_fn( \ - &::mozilla::detail::DerefedType::methodname), \ - (obj), ##__VA_ARGS__)) - #endif diff --git a/dom/quota/QuotaCommon.cpp b/dom/quota/QuotaCommon.cpp index 6a37b3ba43cc..49cb939bb7d2 100644 --- a/dom/quota/QuotaCommon.cpp +++ b/dom/quota/QuotaCommon.cpp @@ -17,6 +17,7 @@ #include "mozilla/TelemetryComms.h" #include "mozilla/TelemetryEventEnums.h" #include "mozilla/TextUtils.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/ScopedLogExtraInfo.h" #include "nsIConsoleService.h" #include "nsIFile.h" diff --git a/dom/quota/QuotaManager.h b/dom/quota/QuotaManager.h index 80b1a8de2d70..9c4d89986185 100644 --- a/dom/quota/QuotaManager.h +++ b/dom/quota/QuotaManager.h @@ -18,9 +18,9 @@ #include "mozilla/RefPtr.h" #include "mozilla/Result.h" #include "mozilla/dom/Nullable.h" -#include "mozilla/dom/QMResult.h" #include "mozilla/dom/ipc/IdType.h" #include "mozilla/dom/quota/CommonMetadata.h" +#include "mozilla/dom/quota/ForwardDecls.h" #include "mozilla/dom/quota/InitializationTypes.h" #include "mozilla/dom/quota/PersistenceType.h" #include "mozilla/dom/quota/QuotaCommon.h" diff --git a/dom/quota/QuotaManagerService.cpp b/dom/quota/QuotaManagerService.cpp index 34f346424f6f..48dcbfa659e7 100644 --- a/dom/quota/QuotaManagerService.cpp +++ b/dom/quota/QuotaManagerService.cpp @@ -32,6 +32,7 @@ #include "mozilla/Variant.h" #include "mozilla/dom/quota/PQuota.h" #include "mozilla/dom/quota/PersistenceType.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/fallible.h" #include "mozilla/hal_sandbox/PHal.h" #include "mozilla/ipc/BackgroundChild.h" diff --git a/dom/quota/QMResultInlines.h b/dom/quota/ResultExtensions.h similarity index 74% rename from dom/quota/QMResultInlines.h rename to dom/quota/ResultExtensions.h index e8637dea69fa..1a08d311c46f 100644 --- a/dom/quota/QMResultInlines.h +++ b/dom/quota/ResultExtensions.h @@ -7,15 +7,13 @@ #ifndef DOM_QUOTA_QMRESULTINLINES_H_ #define DOM_QUOTA_QMRESULTINLINES_H_ -#ifndef DOM_QUOTA_QMRESULT_H_ -# error Must include QMResult.h first -#endif - +#include "nsError.h" #include "mozilla/Result.h" #include "mozilla/ResultExtensions.h" +#include "mozilla/dom/QMResult.h" +#include "mozilla/dom/quota/Config.h" #ifdef QM_ERROR_STACKS_ENABLED -# include "nsError.h" # include "mozilla/ResultVariant.h" #endif @@ -83,4 +81,20 @@ inline Result ToResult(QMResult&& aValue) { } // namespace mozilla +// TODO: Maybe move this to mfbt/ResultExtensions.h +#define MOZ_TO_RESULT(expr) ToResult(expr) + +#define QM_TO_RESULT(expr) ToResult(expr) + +#define QM_TO_RESULT_INVOKE(obj, methodname, ...) \ + ::mozilla::ToResultInvoke( \ + (obj), &::mozilla::detail::DerefedType::methodname, \ + ##__VA_ARGS__) + +#define QM_TO_RESULT_INVOKE_TYPED(resultType, obj, methodname, ...) \ + (::mozilla::ToResultInvoke( \ + ::std::mem_fn( \ + &::mozilla::detail::DerefedType::methodname), \ + (obj), ##__VA_ARGS__)) + #endif diff --git a/dom/quota/StorageHelpers.cpp b/dom/quota/StorageHelpers.cpp index 1091a982824d..1b62d01c19c3 100644 --- a/dom/quota/StorageHelpers.cpp +++ b/dom/quota/StorageHelpers.cpp @@ -5,7 +5,9 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/quota/StorageHelpers.h" + #include "mozilla/dom/quota/QuotaCommon.h" +#include "mozilla/dom/quota/ResultExtensions.h" namespace mozilla::dom::quota { diff --git a/dom/quota/moz.build b/dom/quota/moz.build index 88f2655ac224..5294ff64b373 100644 --- a/dom/quota/moz.build +++ b/dom/quota/moz.build @@ -20,7 +20,6 @@ XPIDL_MODULE = "dom_quota" EXPORTS.mozilla.dom += [ "QMResult.h", - "QMResultInlines.h", "StorageManager.h", ] @@ -43,6 +42,7 @@ EXPORTS.mozilla.dom.quota += [ "FileStreams.h", "FirstInitializationAttempts.h", "FirstInitializationAttemptsImpl.h", + "ForwardDecls.h", "InitializationTypes.h", "IPCStreamCipherStrategy.h", "MemoryOutputStream.h", @@ -54,6 +54,7 @@ EXPORTS.mozilla.dom.quota += [ "QuotaManagerImpl.h", "QuotaManagerService.h", "QuotaObject.h", + "ResultExtensions.h", "ScopedLogExtraInfo.h", "SerializationHelpers.h", "StorageHelpers.h", diff --git a/dom/quota/test/gtest/Common.cpp b/dom/quota/test/gtest/Common.cpp new file mode 100644 index 000000000000..efbfd94775ad --- /dev/null +++ b/dom/quota/test/gtest/Common.cpp @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Common.h" + +#include "mozilla/dom/QMResult.h" + +namespace mozilla::dom::quota { + +#ifdef QM_ERROR_STACKS_ENABLED +uint64_t DOM_Quota_Test::sExpectedStackId; + +// static +void DOM_Quota_Test::SetUpTestCase() { + sExpectedStackId = QMResult().StackId(); +} + +// static +void DOM_Quota_Test::IncreaseExpectedStackId() { sExpectedStackId++; } + +// static +uint64_t DOM_Quota_Test::ExpectedStackId() { return sExpectedStackId; } +#endif + +} // namespace mozilla::dom::quota diff --git a/dom/quota/test/gtest/Common.h b/dom/quota/test/gtest/Common.h new file mode 100644 index 000000000000..eac58bd7fbe9 --- /dev/null +++ b/dom/quota/test/gtest/Common.h @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_QUOTA_TEST_GTEST_COMMON_H_ +#define DOM_QUOTA_TEST_GTEST_COMMON_H_ + +#include +#include "gtest/gtest.h" +#include "mozilla/dom/quota/Config.h" + +namespace mozilla::dom::quota { + +class DOM_Quota_Test : public testing::Test { +#ifdef QM_ERROR_STACKS_ENABLED + public: + static void SetUpTestCase(); + + static void IncreaseExpectedStackId(); + + static uint64_t ExpectedStackId(); + + private: + static uint64_t sExpectedStackId; +#endif +}; + +} // namespace mozilla::dom::quota + +#endif // DOM_QUOTA_TEST_GTEST_COMMON_H_ diff --git a/dom/quota/test/gtest/TestForwardDecls.cpp b/dom/quota/test/gtest/TestForwardDecls.cpp new file mode 100644 index 000000000000..223f83af0341 --- /dev/null +++ b/dom/quota/test/gtest/TestForwardDecls.cpp @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include "mozilla/dom/quota/ForwardDecls.h" + +using namespace mozilla; + +static_assert(std::is_same_v>); diff --git a/dom/quota/test/gtest/TestQMResult.cpp b/dom/quota/test/gtest/TestQMResult.cpp index 1fd382eed470..94cbec736441 100644 --- a/dom/quota/test/gtest/TestQMResult.cpp +++ b/dom/quota/test/gtest/TestQMResult.cpp @@ -4,30 +4,22 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "Common.h" +#include "gtest/gtest.h" #include "mozilla/dom/QMResult.h" -#include "gtest/gtest.h" - -#include "mozilla/dom/QMResultInlines.h" - using namespace mozilla; +using namespace mozilla::dom::quota; -static_assert(std::is_same_v>); - -uint64_t gBaseStackId; - -class DOM_Quota_QMResult : public testing::Test { -#ifdef QM_ERROR_STACKS_ENABLED - public: - static void SetUpTestCase() { gBaseStackId = QMResult().StackId(); } -#endif -}; +class DOM_Quota_QMResult : public DOM_Quota_Test {}; #ifdef QM_ERROR_STACKS_ENABLED TEST_F(DOM_Quota_QMResult, Construct_Default) { QMResult res; - ASSERT_EQ(res.StackId(), gBaseStackId + 1); + IncreaseExpectedStackId(); + + ASSERT_EQ(res.StackId(), ExpectedStackId()); ASSERT_EQ(res.FrameId(), 1u); ASSERT_EQ(res.NSResult(), NS_OK); } @@ -37,7 +29,9 @@ TEST_F(DOM_Quota_QMResult, Construct_FromNSResult) { QMResult res(NS_ERROR_FAILURE); #ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(res.StackId(), gBaseStackId + 2); + IncreaseExpectedStackId(); + + ASSERT_EQ(res.StackId(), ExpectedStackId()); ASSERT_EQ(res.FrameId(), 1u); ASSERT_EQ(res.NSResult(), NS_ERROR_FAILURE); #else @@ -49,13 +43,15 @@ TEST_F(DOM_Quota_QMResult, Construct_FromNSResult) { TEST_F(DOM_Quota_QMResult, Propagate) { QMResult res1(NS_ERROR_FAILURE); - ASSERT_EQ(res1.StackId(), gBaseStackId + 3); + IncreaseExpectedStackId(); + + ASSERT_EQ(res1.StackId(), ExpectedStackId()); ASSERT_EQ(res1.FrameId(), 1u); ASSERT_EQ(res1.NSResult(), NS_ERROR_FAILURE); QMResult res2 = res1.Propagate(); - ASSERT_EQ(res2.StackId(), gBaseStackId + 3); + ASSERT_EQ(res2.StackId(), ExpectedStackId()); ASSERT_EQ(res2.FrameId(), 2u); ASSERT_EQ(res2.NSResult(), NS_ERROR_FAILURE); } @@ -65,90 +61,12 @@ TEST_F(DOM_Quota_QMResult, ToQMResult) { auto res = ToQMResult(NS_ERROR_FAILURE); #ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(res.StackId(), gBaseStackId + 4); + IncreaseExpectedStackId(); + + ASSERT_EQ(res.StackId(), ExpectedStackId()); ASSERT_EQ(res.FrameId(), 1u); ASSERT_EQ(res.NSResult(), NS_ERROR_FAILURE); #else ASSERT_EQ(res, NS_ERROR_FAILURE); #endif } - -TEST_F(DOM_Quota_QMResult, ToResult) { - // copy - { - const auto res = ToQMResult(NS_ERROR_FAILURE); - auto okOrErr = ToResult(res); - static_assert(std::is_same_v); - ASSERT_TRUE(okOrErr.isErr()); - auto err = okOrErr.unwrapErr(); -#ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(err.StackId(), gBaseStackId + 5); - ASSERT_EQ(err.FrameId(), 1u); - ASSERT_EQ(err.NSResult(), NS_ERROR_FAILURE); -#else - ASSERT_EQ(err, NS_ERROR_FAILURE); -#endif - } - - // move - { - auto res = ToQMResult(NS_ERROR_FAILURE); - auto okOrErr = ToResult(std::move(res)); - static_assert(std::is_same_v); - ASSERT_TRUE(okOrErr.isErr()); - auto err = okOrErr.unwrapErr(); -#ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(err.StackId(), gBaseStackId + 6); - ASSERT_EQ(err.FrameId(), 1u); - ASSERT_EQ(err.NSResult(), NS_ERROR_FAILURE); -#else - ASSERT_EQ(err, NS_ERROR_FAILURE); -#endif - } -} - -TEST_F(DOM_Quota_QMResult, ToResult_Macro) { - auto okOrErr = QM_TO_RESULT(NS_ERROR_FAILURE); - static_assert(std::is_same_v); - ASSERT_TRUE(okOrErr.isErr()); - auto err = okOrErr.unwrapErr(); -#ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(err.StackId(), gBaseStackId + 7); - ASSERT_EQ(err.FrameId(), 1u); - ASSERT_EQ(err.NSResult(), NS_ERROR_FAILURE); -#else - ASSERT_EQ(err, NS_ERROR_FAILURE); -#endif -} - -TEST_F(DOM_Quota_QMResult, ErrorPropagation) { - OkOrErr okOrErr1 = ToResult(ToQMResult(NS_ERROR_FAILURE)); - const auto& err1 = okOrErr1.inspectErr(); -#ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(err1.StackId(), gBaseStackId + 8); - ASSERT_EQ(err1.FrameId(), 1u); - ASSERT_EQ(err1.NSResult(), NS_ERROR_FAILURE); -#else - ASSERT_EQ(err1, NS_ERROR_FAILURE); -#endif - - OkOrErr okOrErr2 = okOrErr1.propagateErr(); - const auto& err2 = okOrErr2.inspectErr(); -#ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(err2.StackId(), gBaseStackId + 8); - ASSERT_EQ(err2.FrameId(), 2u); - ASSERT_EQ(err2.NSResult(), NS_ERROR_FAILURE); -#else - ASSERT_EQ(err2, NS_ERROR_FAILURE); -#endif - - OkOrErr okOrErr3 = okOrErr2.propagateErr(); - const auto& err3 = okOrErr3.inspectErr(); -#ifdef QM_ERROR_STACKS_ENABLED - ASSERT_EQ(err3.StackId(), gBaseStackId + 8); - ASSERT_EQ(err3.FrameId(), 3u); - ASSERT_EQ(err3.NSResult(), NS_ERROR_FAILURE); -#else - ASSERT_EQ(err3, NS_ERROR_FAILURE); -#endif -} diff --git a/dom/quota/test/gtest/TestQuotaCommon.cpp b/dom/quota/test/gtest/TestQuotaCommon.cpp index a5b2b601b052..5f3e2d203b50 100644 --- a/dom/quota/test/gtest/TestQuotaCommon.cpp +++ b/dom/quota/test/gtest/TestQuotaCommon.cpp @@ -25,6 +25,7 @@ #include "mozilla/ResultVariant.h" #include "mozilla/Unused.h" #include "mozilla/fallible.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "nsCOMPtr.h" #include "nsLiteralString.h" #include "nsString.h" diff --git a/dom/quota/test/gtest/TestResultExtensions.cpp b/dom/quota/test/gtest/TestResultExtensions.cpp new file mode 100644 index 000000000000..187e4008e68c --- /dev/null +++ b/dom/quota/test/gtest/TestResultExtensions.cpp @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "Common.h" +#include "gtest/gtest.h" +#include "mozilla/dom/QMResult.h" +#include "mozilla/dom/quota/ResultExtensions.h" + +using namespace mozilla; +using namespace mozilla::dom::quota; + +class DOM_Quota_ResultExtensions_ToResult : public DOM_Quota_Test {}; +class DOM_Quota_ResultExtensions_GenericErrorResult : public DOM_Quota_Test {}; + +TEST_F(DOM_Quota_ResultExtensions_ToResult, FromQMResult_Failure) { + // copy + { + const auto res = ToQMResult(NS_ERROR_FAILURE); + auto okOrErr = ToResult(res); + static_assert(std::is_same_v); + ASSERT_TRUE(okOrErr.isErr()); + auto err = okOrErr.unwrapErr(); + +#ifdef QM_ERROR_STACKS_ENABLED + IncreaseExpectedStackId(); + + ASSERT_EQ(err.StackId(), ExpectedStackId()); + ASSERT_EQ(err.FrameId(), 1u); + ASSERT_EQ(err.NSResult(), NS_ERROR_FAILURE); +#else + ASSERT_EQ(err, NS_ERROR_FAILURE); +#endif + } + + // move + { + auto res = ToQMResult(NS_ERROR_FAILURE); + auto okOrErr = ToResult(std::move(res)); + static_assert(std::is_same_v); + ASSERT_TRUE(okOrErr.isErr()); + auto err = okOrErr.unwrapErr(); + +#ifdef QM_ERROR_STACKS_ENABLED + IncreaseExpectedStackId(); + + ASSERT_EQ(err.StackId(), ExpectedStackId()); + ASSERT_EQ(err.FrameId(), 1u); + ASSERT_EQ(err.NSResult(), NS_ERROR_FAILURE); +#else + ASSERT_EQ(err, NS_ERROR_FAILURE); +#endif + } +} + +TEST_F(DOM_Quota_ResultExtensions_ToResult, FromNSResult_Failure_Macro) { + auto okOrErr = QM_TO_RESULT(NS_ERROR_FAILURE); + static_assert(std::is_same_v); + ASSERT_TRUE(okOrErr.isErr()); + auto err = okOrErr.unwrapErr(); + +#ifdef QM_ERROR_STACKS_ENABLED + IncreaseExpectedStackId(); + + ASSERT_EQ(err.StackId(), ExpectedStackId()); + ASSERT_EQ(err.FrameId(), 1u); + ASSERT_EQ(err.NSResult(), NS_ERROR_FAILURE); +#else + ASSERT_EQ(err, NS_ERROR_FAILURE); +#endif +} + +TEST_F(DOM_Quota_ResultExtensions_GenericErrorResult, ErrorPropagation) { + OkOrErr okOrErr1 = ToResult(ToQMResult(NS_ERROR_FAILURE)); + const auto& err1 = okOrErr1.inspectErr(); + +#ifdef QM_ERROR_STACKS_ENABLED + IncreaseExpectedStackId(); + + ASSERT_EQ(err1.StackId(), ExpectedStackId()); + ASSERT_EQ(err1.FrameId(), 1u); + ASSERT_EQ(err1.NSResult(), NS_ERROR_FAILURE); +#else + ASSERT_EQ(err1, NS_ERROR_FAILURE); +#endif + + OkOrErr okOrErr2 = okOrErr1.propagateErr(); + const auto& err2 = okOrErr2.inspectErr(); + +#ifdef QM_ERROR_STACKS_ENABLED + ASSERT_EQ(err2.StackId(), ExpectedStackId()); + ASSERT_EQ(err2.FrameId(), 2u); + ASSERT_EQ(err2.NSResult(), NS_ERROR_FAILURE); +#else + ASSERT_EQ(err2, NS_ERROR_FAILURE); +#endif + + OkOrErr okOrErr3 = okOrErr2.propagateErr(); + const auto& err3 = okOrErr3.inspectErr(); + +#ifdef QM_ERROR_STACKS_ENABLED + ASSERT_EQ(err3.StackId(), ExpectedStackId()); + ASSERT_EQ(err3.FrameId(), 3u); + ASSERT_EQ(err3.NSResult(), NS_ERROR_FAILURE); +#else + ASSERT_EQ(err3, NS_ERROR_FAILURE); +#endif +} diff --git a/dom/quota/test/gtest/moz.build b/dom/quota/test/gtest/moz.build index 8fc38ee3f8b1..fcd229c9d991 100644 --- a/dom/quota/test/gtest/moz.build +++ b/dom/quota/test/gtest/moz.build @@ -5,13 +5,16 @@ # file, you can obtain one at http://mozilla.org/MPL/2.0/. UNIFIED_SOURCES = [ + "Common.cpp", "TestCheckedUnsafePtr.cpp", "TestEncryptedStream.cpp", "TestFlatten.cpp", + "TestForwardDecls.cpp", "TestPersistenceType.cpp", "TestQMResult.cpp", "TestQuotaCommon.cpp", "TestQuotaManager.cpp", + "TestResultExtensions.cpp", "TestScopedLogExtraInfo.cpp", "TestUsageInfo.cpp", ] diff --git a/dom/simpledb/ActorsParent.cpp b/dom/simpledb/ActorsParent.cpp index 80bdd0536259..f2ebdf763f44 100644 --- a/dom/simpledb/ActorsParent.cpp +++ b/dom/simpledb/ActorsParent.cpp @@ -40,6 +40,7 @@ #include "mozilla/dom/quota/MemoryOutputStream.h" #include "mozilla/dom/quota/QuotaCommon.h" #include "mozilla/dom/quota/QuotaManager.h" +#include "mozilla/dom/quota/ResultExtensions.h" #include "mozilla/dom/quota/UsageInfo.h" #include "mozilla/ipc/BackgroundParent.h" #include "mozilla/ipc/BackgroundUtils.h"