mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 08:57:35 +00:00
LibJS: Implement the Error Cause proposal
Currently stage 3. https://github.com/tc39/proposal-error-cause
This commit is contained in:
parent
8d77a3297a
commit
862ba64037
11 changed files with 130 additions and 42 deletions
|
@ -10,14 +10,17 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
Error* Error::create(GlobalObject& global_object, const String& message)
|
||||
Error* Error::create(GlobalObject& global_object)
|
||||
{
|
||||
return global_object.heap().allocate<Error>(global_object, *global_object.error_prototype());
|
||||
}
|
||||
|
||||
Error* Error::create(GlobalObject& global_object, String const& message)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto* error = global_object.heap().allocate<Error>(global_object, *global_object.error_prototype());
|
||||
if (!message.is_null()) {
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
error->define_property(vm.names.message, js_string(vm, message), attr);
|
||||
}
|
||||
auto* error = Error::create(global_object);
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
error->define_property(vm.names.message, js_string(vm, message), attr);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -26,21 +29,24 @@ Error::Error(Object& prototype)
|
|||
{
|
||||
}
|
||||
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||
ClassName* ClassName::create(GlobalObject& global_object, const String& message) \
|
||||
{ \
|
||||
auto& vm = global_object.vm(); \
|
||||
auto* error = global_object.heap().allocate<ClassName>(global_object, *global_object.snake_name##_prototype()); \
|
||||
if (!message.is_null()) { \
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
||||
error->define_property(vm.names.message, js_string(vm, message), attr); \
|
||||
} \
|
||||
return error; \
|
||||
} \
|
||||
\
|
||||
ClassName::ClassName(Object& prototype) \
|
||||
: Error(prototype) \
|
||||
{ \
|
||||
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
||||
ClassName* ClassName::create(GlobalObject& global_object) \
|
||||
{ \
|
||||
return global_object.heap().allocate<ClassName>(global_object, *global_object.snake_name##_prototype()); \
|
||||
} \
|
||||
\
|
||||
ClassName* ClassName::create(GlobalObject& global_object, String const& message) \
|
||||
{ \
|
||||
auto& vm = global_object.vm(); \
|
||||
auto* error = ClassName::create(global_object); \
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
||||
error->define_property(vm.names.message, js_string(vm, message), attr); \
|
||||
return error; \
|
||||
} \
|
||||
\
|
||||
ClassName::ClassName(Object& prototype) \
|
||||
: Error(prototype) \
|
||||
{ \
|
||||
}
|
||||
|
||||
JS_ENUMERATE_NATIVE_ERRORS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue