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
|
|
|
*/
|
|
|
|
|
2020-04-10 12:42:33 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-03-24 14:37:39 +01:00
|
|
|
#include <AK/FlyString.h>
|
2021-10-02 16:03:45 +01:00
|
|
|
#include <LibJS/Runtime/Completion.h>
|
2020-03-24 14:37:39 +01:00
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
class Error : public Object {
|
2020-06-21 15:14:02 +02:00
|
|
|
JS_OBJECT(Error, Object);
|
|
|
|
|
2020-03-24 14:37:39 +01:00
|
|
|
public:
|
2021-06-11 20:40:08 +01:00
|
|
|
static Error* create(GlobalObject&);
|
|
|
|
static Error* create(GlobalObject&, String const& message);
|
2020-04-17 19:31:48 +02:00
|
|
|
|
2021-04-12 00:08:28 +02:00
|
|
|
explicit Error(Object& prototype);
|
|
|
|
virtual ~Error() override = default;
|
2021-06-26 19:06:55 +01:00
|
|
|
|
2021-10-02 16:03:45 +01:00
|
|
|
ThrowCompletionOr<void> install_error_cause(Value options);
|
2020-03-24 14:37:39 +01:00
|
|
|
};
|
|
|
|
|
2021-06-11 17:54:42 +01:00
|
|
|
// NOTE: Making these inherit from Error is not required by the spec but
|
|
|
|
// our way of implementing the [[ErrorData]] internal slot, which is
|
|
|
|
// used in Object.prototype.toString().
|
|
|
|
#define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
|
|
|
class ClassName final : public Error { \
|
|
|
|
JS_OBJECT(ClassName, Error); \
|
|
|
|
\
|
|
|
|
public: \
|
2021-06-11 20:40:08 +01:00
|
|
|
static ClassName* create(GlobalObject&); \
|
|
|
|
static ClassName* create(GlobalObject&, String const& message); \
|
2021-06-11 17:54:42 +01:00
|
|
|
\
|
|
|
|
explicit ClassName(Object& prototype); \
|
|
|
|
virtual ~ClassName() override = default; \
|
2020-04-10 12:42:33 +02:00
|
|
|
};
|
|
|
|
|
2020-12-01 21:05:25 +01:00
|
|
|
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
|
2021-06-11 17:54:42 +01:00
|
|
|
DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName)
|
|
|
|
JS_ENUMERATE_NATIVE_ERRORS
|
2020-04-10 14:06:52 +02:00
|
|
|
#undef __JS_ENUMERATE
|
2020-03-24 14:37:39 +01:00
|
|
|
}
|