diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-07 12:14:54 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-08 12:13:15 +0100 |
commit | d8044c5358ab8440286f39c3d1efe2c5f39bc115 (patch) | |
tree | eb966d631ff464f284844b863230fe56fec7ad3c /Userland/Libraries/LibJS | |
parent | ba97f6a0d3516a19306137bed8df7310bacabfb5 (diff) | |
download | serenity-d8044c5358ab8440286f39c3d1efe2c5f39bc115.zip |
LibJS+LibWeb: Move the macro to convert ENOMEM to an exception to LibJS
Move the macro to LibJS and change it to return a throw completion
instead of a WebIDL exception. This will let us use this macro within
LibJS to handle OOM conditions.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Completion.h | 13 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ErrorTypes.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Completion.h b/Userland/Libraries/LibJS/Runtime/Completion.h index 7c6e144caa..0203b642f6 100644 --- a/Userland/Libraries/LibJS/Runtime/Completion.h +++ b/Userland/Libraries/LibJS/Runtime/Completion.h @@ -11,10 +11,23 @@ #include <AK/Optional.h> #include <AK/Try.h> #include <AK/Variant.h> +#include <LibJS/Runtime/ErrorTypes.h> #include <LibJS/Runtime/Value.h> 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); \ + } \ + _temporary_result.release_value(); \ + }) + // 6.2.3 The Completion Record Specification Type, https://tc39.es/ecma262/#sec-completion-record-specification-type class [[nodiscard]] Completion { public: diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h index bd4b1919c2..37ca52de2e 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h +++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h @@ -110,6 +110,7 @@ "Object prototype must not be {} on a super property access") \ M(ObjectPrototypeWrongType, "Prototype must be an object or null") \ M(OptionIsNotValidValue, "{} is not a valid value for option {}") \ + M(OutOfMemory, "Out of memory") \ M(OverloadResolutionFailed, "Overload resolution failed") \ M(PrivateFieldAlreadyDeclared, "Private field '{}' has already been declared") \ M(PrivateFieldDoesNotExistOnObject, "Private field '{}' does not exist on object") \ |