Error.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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&);
  15. static Error* create(GlobalObject&, String const& message);
  16. explicit Error(Object& prototype);
  17. virtual ~Error() override = default;
  18. };
  19. // NOTE: Making these inherit from Error is not required by the spec but
  20. // our way of implementing the [[ErrorData]] internal slot, which is
  21. // used in Object.prototype.toString().
  22. #define DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName) \
  23. class ClassName final : public Error { \
  24. JS_OBJECT(ClassName, Error); \
  25. \
  26. public: \
  27. static ClassName* create(GlobalObject&); \
  28. static ClassName* create(GlobalObject&, String const& message); \
  29. \
  30. explicit ClassName(Object& prototype); \
  31. virtual ~ClassName() override = default; \
  32. };
  33. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  34. DECLARE_NATIVE_ERROR(ClassName, snake_name, PrototypeName, ConstructorName)
  35. JS_ENUMERATE_NATIVE_ERRORS
  36. #undef __JS_ENUMERATE
  37. }