Error.h 1.8 KB

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