mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:37:36 +00:00
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.
This commit is contained in:
parent
ba97f6a0d3
commit
d8044c5358
15 changed files with 118 additions and 93 deletions
|
@ -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:
|
||||
|
|
|
@ -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") \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue