From a8094f3333647736f0bc360bd5f88cb8fdf3ec16 Mon Sep 17 00:00:00 2001 From: Jonne Ransijn Date: Sun, 17 Nov 2024 11:21:20 +0100 Subject: [PATCH] AK+LibJS: Allow `{TRY,MUST}{,_OR_THROW_OOM}` on list-initializers List initializers may contain commas without surrounding parenthesis, causing them to be passed as multiple macro arguments. --- AK/Try.h | 8 ++++---- Libraries/LibJS/Runtime/Completion.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AK/Try.h b/AK/Try.h index 14edb5c0676..4a7e4a54ca0 100644 --- a/AK/Try.h +++ b/AK/Try.h @@ -21,11 +21,11 @@ // from a fallible expression. This will not do what you want; the statement expression // will create a copy regardless, so it is explicitly disallowed. -#define TRY(expression) \ +#define TRY(...) \ ({ \ /* Ignore -Wshadow to allow nesting the macro. */ \ AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto&& _temporary_result = (expression)); \ + auto&& _temporary_result = (__VA_ARGS__)); \ static_assert(!::AK::Detail::IsLvalueReference, \ "Do not return a reference from a fallible expression"); \ if (_temporary_result.is_error()) [[unlikely]] \ @@ -33,11 +33,11 @@ _temporary_result.release_value(); \ }) -#define MUST(expression) \ +#define MUST(...) \ ({ \ /* Ignore -Wshadow to allow nesting the macro. */ \ AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto&& _temporary_result = (expression)); \ + auto&& _temporary_result = (__VA_ARGS__)); \ static_assert(!::AK::Detail::IsLvalueReference, \ "Do not return a reference from a fallible expression"); \ VERIFY(!_temporary_result.is_error()); \ diff --git a/Libraries/LibJS/Runtime/Completion.h b/Libraries/LibJS/Runtime/Completion.h index b599a0911d1..80692eedbd1 100644 --- a/Libraries/LibJS/Runtime/Completion.h +++ b/Libraries/LibJS/Runtime/Completion.h @@ -17,11 +17,11 @@ namespace JS { -#define TRY_OR_THROW_OOM(vm, expression) \ +#define TRY_OR_THROW_OOM(vm, ...) \ ({ \ /* Ignore -Wshadow to allow nesting the macro. */ \ AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto&& _temporary_result = (expression)); \ + auto&& _temporary_result = (__VA_ARGS__)); \ if (_temporary_result.is_error()) { \ VERIFY(_temporary_result.error().code() == ENOMEM); \ return (vm).throw_completion((vm).error_message(::JS::VM::ErrorMessage::OutOfMemory)); \ @@ -31,11 +31,11 @@ namespace JS { _temporary_result.release_value(); \ }) -#define MUST_OR_THROW_OOM(expression) \ +#define MUST_OR_THROW_OOM(...) \ ({ \ /* Ignore -Wshadow to allow nesting the macro. */ \ AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto&& _temporary_result = (expression)); \ + auto&& _temporary_result = (__VA_ARGS__)); \ if (_temporary_result.is_error()) { \ auto _completion = _temporary_result.release_error(); \ \