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