ErrorEvent.h 2.0 KB

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