ErrorEvent.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/DOM/Event.h>
  8. namespace Web::HTML {
  9. // https://html.spec.whatwg.org/multipage/webappapis.html#erroreventinit
  10. struct ErrorEventInit : public DOM::EventInit {
  11. DeprecatedString message { "" };
  12. DeprecatedString filename { "" }; // FIXME: This should be a USVString.
  13. u32 lineno { 0 };
  14. u32 colno { 0 };
  15. JS::Value error { JS::js_null() };
  16. };
  17. // https://html.spec.whatwg.org/multipage/webappapis.html#errorevent
  18. class ErrorEvent final : public DOM::Event {
  19. WEB_PLATFORM_OBJECT(ErrorEvent, DOM::Event);
  20. public:
  21. static WebIDL::ExceptionOr<JS::NonnullGCPtr<ErrorEvent>> create(JS::Realm&, DeprecatedFlyString const& event_name, ErrorEventInit const& event_init = {});
  22. static WebIDL::ExceptionOr<JS::NonnullGCPtr<ErrorEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, ErrorEventInit const& event_init);
  23. virtual ~ErrorEvent() override;
  24. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-message
  25. DeprecatedString const& message() const { return m_message; }
  26. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-filename
  27. DeprecatedString const& filename() const { return m_filename; }
  28. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-lineno
  29. u32 lineno() const { return m_lineno; }
  30. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-colno
  31. u32 colno() const { return m_colno; }
  32. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-error
  33. JS::Value error() const { return m_error; }
  34. private:
  35. ErrorEvent(JS::Realm&, DeprecatedFlyString const& event_name, ErrorEventInit const& event_init);
  36. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  37. virtual void visit_edges(Cell::Visitor&) override;
  38. DeprecatedString m_message { "" };
  39. DeprecatedString m_filename { "" }; // FIXME: This should be a USVString.
  40. u32 m_lineno { 0 };
  41. u32 m_colno { 0 };
  42. JS::Value m_error;
  43. };
  44. }