ErrorConstructor.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2020-2021, 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. explicit ErrorConstructor(GlobalObject&);
  14. virtual void initialize(GlobalObject&) override;
  15. virtual ~ErrorConstructor() override = default;
  16. virtual ThrowCompletionOr<Value> call() override;
  17. virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override;
  18. private:
  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. explicit ConstructorName(GlobalObject&); \
  27. virtual void initialize(GlobalObject&) override; \
  28. virtual ~ConstructorName() override; \
  29. virtual ThrowCompletionOr<Value> call() override; \
  30. virtual ThrowCompletionOr<Object*> construct(FunctionObject& new_target) override; \
  31. \
  32. private: \
  33. virtual bool has_constructor() const override { return true; } \
  34. };
  35. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  36. DECLARE_NATIVE_ERROR_CONSTRUCTOR(ClassName, snake_name, PrototypeName, ConstructorName)
  37. JS_ENUMERATE_NATIVE_ERRORS
  38. #undef __JS_ENUMERATE
  39. }