зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1651016 - Allow MOZ_TRY/QM_TRY to handle bool values by wrapping them with OkIf; r=dom-workers-and-storage-reviewers,ttung,sg,asuth
Differential Revision: https://phabricator.services.mozilla.com/D83928
This commit is contained in:
Родитель
4b7144c3a5
Коммит
4c3f248c7a
|
@ -348,6 +348,17 @@ namespace mozilla {
|
|||
|
||||
class LogModule;
|
||||
|
||||
struct NotOk {};
|
||||
|
||||
// Allow MOZ_TRY/QM_TRY to handle `bool` values by wrapping them with OkIf.
|
||||
// TODO: Maybe move this to mfbt/ResultExtensions.h
|
||||
inline Result<Ok, NotOk> OkIf(bool aValue) {
|
||||
if (aValue) {
|
||||
return Ok();
|
||||
}
|
||||
return Err(NotOk());
|
||||
}
|
||||
|
||||
namespace dom {
|
||||
namespace quota {
|
||||
|
||||
|
|
|
@ -154,3 +154,17 @@ TEST(QuotaCommon_TryVar, Failure_NoErr)
|
|||
|
||||
EXPECT_FALSE(flag);
|
||||
}
|
||||
|
||||
TEST(QuotaCommon_OkIf, True)
|
||||
{
|
||||
auto res = OkIf(true);
|
||||
|
||||
EXPECT_TRUE(res.isOk());
|
||||
}
|
||||
|
||||
TEST(QuotaCommon_SuccessIf, False)
|
||||
{
|
||||
auto res = OkIf(false);
|
||||
|
||||
EXPECT_TRUE(res.isErr());
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче