diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-16 12:55:22 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-02-17 09:14:23 -0500 |
commit | 4d10911f96eb6ad55a9798b7237a60407f645e91 (patch) | |
tree | 08ff30edf026fd06a1c68290d87ee928db96a72c /Userland/Libraries/LibJS/Runtime/Completion.h | |
parent | 93ad25fbe51d39094ea42eb9dd62b0d7203a4d5f (diff) | |
download | serenity-4d10911f96eb6ad55a9798b7237a60407f645e91.zip |
LibJS: Pre-allocate the out-of-memory error string on the VM
If we are out of memory, we can't try to allocate a string that could
fail as well. When Error is converted to String, this would result in an
endless OOM-throwing loop. Instead, pre-allocate the string on the VM,
and use it to construct the Error.
Note that as of this commit, the OOM string is still a DeprecatedString.
This is just preporatory for Error's conversion to String.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/Completion.h')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Completion.h | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index b5d089ab84..78e7bc8b87 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -17,18 +17,18 @@ namespace JS { -#define TRY_OR_THROW_OOM(vm, expression) \ - ({ \ - /* Ignore -Wshadow to allow nesting the macro. */ \ - AK_IGNORE_DIAGNOSTIC("-Wshadow", \ - auto&& _temporary_result = (expression)); \ - if (_temporary_result.is_error()) { \ - VERIFY(_temporary_result.error().code() == ENOMEM); \ - return (vm).throw_completion<JS::InternalError>(JS::ErrorType::OutOfMemory); \ - } \ - static_assert(!::AK::Detail::IsLvalueReference<decltype(_temporary_result.release_value())>, \ - "Do not return a reference from a fallible expression"); \ - _temporary_result.release_value(); \ +#define TRY_OR_THROW_OOM(vm, expression) \ + ({ \ + /* Ignore -Wshadow to allow nesting the macro. */ \ + AK_IGNORE_DIAGNOSTIC("-Wshadow", \ + auto&& _temporary_result = (expression)); \ + if (_temporary_result.is_error()) { \ + VERIFY(_temporary_result.error().code() == ENOMEM); \ + return (vm).throw_completion<JS::InternalError>((vm).error_message(::JS::VM::ErrorMessage::OutOfMemory)); \ + } \ + static_assert(!::AK::Detail::IsLvalueReference<decltype(_temporary_result.release_value())>, \ + "Do not return a reference from a fallible expression"); \ + _temporary_result.release_value(); \ }) #define MUST_OR_THROW_OOM(expression) \ |