Error.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/FlyString.h>
  9. #include <LibJS/Runtime/Object.h>
  10. namespace JS {
  11. class Error : public Object {
  12. JS_OBJECT(Error, Object);
  13. public:
  14. static Error* create(GlobalObject&, const String& message = {});
  15. explicit Error(Object& prototype);
  16. virtual ~Error() override = default;
  17. };
  18. #define DECLARE_ERROR_SUBCLASS(ClassName, snake_name, PrototypeName, ConstructorName) \
  19. class ClassName final : public Error { \
  20. JS_OBJECT(ClassName, Error); \
  21. \
  22. public: \
  23. static ClassName* create(GlobalObject&, const String& message = {}); \
  24. \
  25. explicit ClassName(Object& prototype); \
  26. virtual ~ClassName() override = default; \
  27. };
  28. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  29. DECLARE_ERROR_SUBCLASS(ClassName, snake_name, PrototypeName, ConstructorName)
  30. JS_ENUMERATE_ERROR_SUBCLASSES
  31. #undef __JS_ENUMERATE
  32. }