1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:17:34 +00:00

LibWeb: Add & use TRY_OR_RETURN_OOM macro

This is a convenient way to return a DOM exception for operations that
return ErrorOr and only have an OOM failure path.
This commit is contained in:
Linus Groh 2022-07-17 18:23:27 +01:00
parent 452dc544bc
commit bc68539e26
4 changed files with 19 additions and 15 deletions

View file

@ -13,6 +13,16 @@
namespace Web::DOM {
#define TRY_OR_RETURN_OOM(expression) \
({ \
auto _temporary_result = (expression); \
if (_temporary_result.is_error()) { \
VERIFY(_temporary_result.error().code() == ENOMEM); \
return DOM::UnknownError::create("Out of memory."sv); \
} \
_temporary_result.release_value(); \
})
// The following have a legacy code value but *don't* produce it as
// DOMException.code value when used as name (and are therefore omitted here):
// - DOMStringSizeError (DOMSTRING_SIZE_ERR = 2)