From cd49f30bea734feb9ac46d637e2ed3439e47e3c3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 10 Nov 2021 11:54:54 +0100 Subject: [PATCH] AK+LibJS: Simplify MUST() and move it from LibJS to AK/Try.h This is generally useful so let's move it to AK. Also it seems that we don't need the temporary variable hack anymore, so let's lose that. --- AK/Try.h | 7 +++++++ Userland/Libraries/LibJS/Runtime/Completion.h | 13 ------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/AK/Try.h b/AK/Try.h index 15d470e86b..8db09a950a 100644 --- a/AK/Try.h +++ b/AK/Try.h @@ -16,3 +16,10 @@ return _temporary_result.release_error(); \ _temporary_result.release_value(); \ }) + +#define MUST(expression) \ + ({ \ + auto _temporary_result = (expression); \ + VERIFY(!_temporary_result.is_error()); \ + _temporary_result.release_value(); \ + }) diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index c6cefab011..26c4c07ae7 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -26,19 +26,6 @@ namespace JS { _temporary_result.release_value(); \ }) -// MUST() is to the spec's `!` what TRY() is to `?`. -// https://tc39.es/ecma262/#sec-returnifabrupt-shorthands -#define MUST(expression) \ - ({ \ - auto _temporary_result = (expression); \ - VERIFY(!_temporary_result.is_error()); \ - /* The return value of "! Something()" is commonly */ \ - /* ignored, so we assign to a temporary variable here */ \ - /* to avoid having to (void) all the things. */ \ - auto _temporary_value = _temporary_result.release_value(); \ - move(_temporary_value); \ - }) - // 6.2.3 The Completion Record Specification Type, https://tc39.es/ecma262/#sec-completion-record-specification-type class [[nodiscard]] Completion { public: