2020-03-24 14:37:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2021-04-22 22:51:19 +02:00
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
2020-03-24 14:37:39 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-24 14:37:39 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/Error.h>
|
2020-04-17 19:31:48 +02:00
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2020-03-24 14:37:39 +01:00
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2021-04-12 00:08:28 +02:00
|
|
|
Error* Error::create(GlobalObject& global_object, const String& message)
|
2020-04-17 19:31:48 +02:00
|
|
|
{
|
2021-04-12 00:08:28 +02:00
|
|
|
auto& vm = global_object.vm();
|
|
|
|
auto* error = global_object.heap().allocate<Error>(global_object, *global_object.error_prototype());
|
2021-06-11 00:22:53 +01:00
|
|
|
if (!message.is_null()) {
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
|
|
error->define_property(vm.names.message, js_string(vm, message), attr);
|
|
|
|
}
|
2021-04-12 00:08:28 +02:00
|
|
|
return error;
|
2020-04-17 19:31:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 00:08:28 +02:00
|
|
|
Error::Error(Object& prototype)
|
2020-06-23 17:21:53 +02:00
|
|
|
: Object(prototype)
|
2020-03-24 14:37:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-12 00:08:28 +02:00
|
|
|
#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()); \
|
2021-06-11 00:22:53 +01:00
|
|
|
if (!message.is_null()) { \
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable; \
|
|
|
|
error->define_property(vm.names.message, js_string(vm, message), attr); \
|
|
|
|
} \
|
2021-04-12 00:08:28 +02:00
|
|
|
return error; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
ClassName::ClassName(Object& prototype) \
|
|
|
|
: Error(prototype) \
|
|
|
|
{ \
|
|
|
|
}
|
2020-04-10 12:42:33 +02:00
|
|
|
|
2021-06-11 17:54:42 +01:00
|
|
|
JS_ENUMERATE_NATIVE_ERRORS
|
2020-04-10 14:06:52 +02:00
|
|
|
#undef __JS_ENUMERATE
|
2020-04-10 12:42:33 +02:00
|
|
|
|
2020-03-24 14:37:39 +01:00
|
|
|
}
|