2020-04-01 19:42:07 +01:00
|
|
|
/*
|
2022-12-14 19:18:10 +00:00
|
|
|
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
2020-04-01 19:42:07 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-01 19:42:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-04-10 12:42:33 +02:00
|
|
|
#include <LibJS/Runtime/Error.h>
|
2020-04-01 19:42:07 +01:00
|
|
|
#include <LibJS/Runtime/NativeFunction.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2025-07-19 10:41:08 -07:00
|
|
|
class ErrorConstructor final : public NativeFunction {
|
2020-06-21 15:14:02 +02:00
|
|
|
JS_OBJECT(ErrorConstructor, NativeFunction);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(ErrorConstructor);
|
2020-06-21 15:14:02 +02:00
|
|
|
|
2020-04-01 19:42:07 +01:00
|
|
|
public:
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(Realm&) override;
|
2021-04-12 00:08:28 +02:00
|
|
|
virtual ~ErrorConstructor() override = default;
|
2020-04-01 19:42:07 +01:00
|
|
|
|
2021-10-20 21:16:30 +01:00
|
|
|
virtual ThrowCompletionOr<Value> call() override;
|
2024-11-15 04:01:23 +13:00
|
|
|
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override;
|
2020-04-01 19:42:07 +01:00
|
|
|
|
|
|
|
private:
|
2022-08-28 23:51:28 +02:00
|
|
|
explicit ErrorConstructor(Realm&);
|
|
|
|
|
2020-04-01 19:42:07 +01:00
|
|
|
virtual bool has_constructor() const override { return true; }
|
2024-11-10 05:59:08 +13:00
|
|
|
|
|
|
|
JS_DECLARE_NATIVE_FUNCTION(is_error);
|
2020-04-01 19:42:07 +01:00
|
|
|
};
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
#define DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
|
|
|
|
class ConstructorName final : public NativeFunction { \
|
|
|
|
JS_OBJECT(ConstructorName, NativeFunction); \
|
|
|
|
GC_DECLARE_ALLOCATOR(ConstructorName); \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
virtual void initialize(Realm&) override; \
|
|
|
|
virtual ~ConstructorName() override; \
|
|
|
|
virtual ThrowCompletionOr<Value> call() override; \
|
|
|
|
virtual ThrowCompletionOr<GC::Ref<Object>> construct(FunctionObject& new_target) override; \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
explicit ConstructorName(Realm&); \
|
|
|
|
\
|
|
|
|
virtual bool has_constructor() const override \
|
|
|
|
{ \
|
|
|
|
return true; \
|
|
|
|
} \
|
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_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName)
|
|
|
|
JS_ENUMERATE_NATIVE_ERRORS
|
2020-04-10 14:06:52 +02:00
|
|
|
#undef __JS_ENUMERATE
|
2020-04-10 12:42:33 +02:00
|
|
|
|
2020-04-01 19:42:07 +01:00
|
|
|
}
|