From c48363726e06a3c30b1fce6f16411dabf5d651b8 Mon Sep 17 00:00:00 2001 From: Jan Varga Date: Fri, 12 Nov 2021 07:58:47 +0000 Subject: [PATCH] Bug 1731803 - Change QM_TO_RESULT to use generic ToResult function; r=dom-storage-reviewers,jari Differential Revision: https://phabricator.services.mozilla.com/D126271 --- dom/quota/QMResult.h | 2 +- dom/quota/QMResultInlines.h | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dom/quota/QMResult.h b/dom/quota/QMResult.h index afaa10991b4c..7bbe23a81d1f 100644 --- a/dom/quota/QMResult.h +++ b/dom/quota/QMResult.h @@ -72,6 +72,6 @@ inline OkOrErr ToResult(QMResult&& aValue); // TODO: Maybe move this to mfbt/ResultExtensions.h #define MOZ_TO_RESULT(expr) ToResult(expr) -#define QM_TO_RESULT(expr) ToResult(ToQMResult(expr)) +#define QM_TO_RESULT(expr) ToResult(expr) #endif diff --git a/dom/quota/QMResultInlines.h b/dom/quota/QMResultInlines.h index 272e15ed55a4..c5538242f477 100644 --- a/dom/quota/QMResultInlines.h +++ b/dom/quota/QMResultInlines.h @@ -12,11 +12,11 @@ #endif #include "mozilla/Result.h" +#include "mozilla/ResultExtensions.h" + #ifdef QM_ERROR_STACKS_ENABLED -# include "mozilla/ResultVariant.h" # include "nsError.h" -#else -# include "mozilla/ResultExtensions.h" +# include "mozilla/ResultVariant.h" #endif namespace mozilla { @@ -55,6 +55,11 @@ class [[nodiscard]] GenericErrorResult { operator nsresult() const { return mErrorValue.NSResult(); } }; +template <> +struct ResultTypeTraits { + static QMResult From(nsresult aValue) { return ToQMResult(aValue); } +}; + inline OkOrErr ToResult(const QMResult& aValue) { if (NS_FAILED(aValue.NSResult())) { return Err(aValue);