mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
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.
This commit is contained in:
parent
f617127772
commit
d5fbf7323a
Notes:
github-actions[bot]
2024-12-04 16:47:55 +00:00
Author: https://github.com/yyny Commit: https://github.com/LadybirdBrowser/ladybird/commit/d5fbf7323a6 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2454 Reviewed-by: https://github.com/AtkinsSJ ✅
2 changed files with 8 additions and 8 deletions
8
AK/Try.h
8
AK/Try.h
|
@ -24,11 +24,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<decltype(_temporary_result.release_value())>, \
|
||||
"Do not return a reference from a fallible expression"); \
|
||||
if (_temporary_result.is_error()) [[unlikely]] \
|
||||
|
@ -36,11 +36,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<decltype(_temporary_result.release_value())>, \
|
||||
"Do not return a reference from a fallible expression"); \
|
||||
AK_HANDLE_UNEXPECTED_ERROR(_temporary_result) \
|
||||
|
|
|
@ -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<JS::InternalError>((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(); \
|
||||
\
|
||||
|
|
Loading…
Reference in a new issue