ErrorEvent.h 1.9 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 <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. String message { "" };
  12. String 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 ErrorEvent* create(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init = {});
  22. static ErrorEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, ErrorEventInit const& event_init);
  23. ErrorEvent(HTML::Window&, 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. virtual void visit_edges(Cell::Visitor&) override;
  37. String m_message { "" };
  38. String m_filename { "" }; // FIXME: This should be a USVString.
  39. u32 m_lineno { 0 };
  40. u32 m_colno { 0 };
  41. JS::Value m_error;
  42. };
  43. }
  44. WRAPPER_HACK(ErrorEvent, Web::HTML)