Error.h 1.9 KB

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