ErrorConstructor.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Runtime/Error.h>
  8. #include <LibJS/Runtime/NativeFunction.h>
  9. namespace JS {
  10. class ErrorConstructor final : public NativeFunction {
  11. JS_OBJECT(ErrorConstructor, NativeFunction);
  12. public:
  13. virtual void initialize(Realm&) override;
  14. virtual ~ErrorConstructor() override = default;
  15. virtual ThrowCompletionOr<Value> call() override;
  16. virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
  17. private:
  18. explicit ErrorConstructor(Realm&);
  19. virtual bool has_constructor() const override { return true; }
  20. };
  21. #define DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
  22. class ConstructorName final : public NativeFunction { \
  23. JS_OBJECT(ConstructorName, NativeFunction); \
  24. \
  25. public: \
  26. virtual void initialize(Realm&) override; \
  27. virtual ~ConstructorName() override; \
  28. virtual ThrowCompletionOr<Value> call() override; \
  29. virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override; \
  30. \
  31. private: \
  32. explicit ConstructorName(Realm&); \
  33. \
  34. virtual bool has_constructor() const override \
  35. { \
  36. return true; \
  37. } \
  38. };
  39. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  40. DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName)
  41. JS_ENUMERATE_NATIVE_ERRORS
  42. #undef __JS_ENUMERATE
  43. }