ErrorConstructor.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. JS_DECLARE_ALLOCATOR(ErrorConstructor);
  13. public:
  14. virtual void initialize(Realm&) override;
  15. virtual ~ErrorConstructor() override = default;
  16. virtual ThrowCompletionOr<Value> call() override;
  17. virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override;
  18. private:
  19. explicit ErrorConstructor(Realm&);
  20. virtual bool has_constructor() const override { return true; }
  21. };
  22. #define DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName) \
  23. class ConstructorName final : public NativeFunction { \
  24. JS_OBJECT(ConstructorName, NativeFunction); \
  25. JS_DECLARE_ALLOCATOR(ConstructorName); \
  26. \
  27. public: \
  28. virtual void initialize(Realm&) override; \
  29. virtual ~ConstructorName() override; \
  30. virtual ThrowCompletionOr<Value> call() override; \
  31. virtual ThrowCompletionOr<NonnullGCPtr<Object>> construct(FunctionObject& new_target) override; \
  32. \
  33. private: \
  34. explicit ConstructorName(Realm&); \
  35. \
  36. virtual bool has_constructor() const override \
  37. { \
  38. return true; \
  39. } \
  40. };
  41. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  42. DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName)
  43. JS_ENUMERATE_NATIVE_ERRORS
  44. #undef __JS_ENUMERATE
  45. }