ErrorEvent.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. public:
  20. using WrapperType = Bindings::ErrorEventWrapper;
  21. static NonnullRefPtr<ErrorEvent> create(FlyString const& event_name, ErrorEventInit const& event_init = {})
  22. {
  23. return adopt_ref(*new ErrorEvent(event_name, event_init));
  24. }
  25. static NonnullRefPtr<ErrorEvent> create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, ErrorEventInit const& event_init)
  26. {
  27. return ErrorEvent::create(event_name, event_init);
  28. }
  29. virtual ~ErrorEvent() override = default;
  30. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-message
  31. String const& message() const { return m_message; }
  32. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-filename
  33. String const& filename() const { return m_filename; }
  34. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-lineno
  35. u32 lineno() const { return m_lineno; }
  36. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-colno
  37. u32 colno() const { return m_colno; }
  38. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-error
  39. JS::Value error() const { return m_error.value(); }
  40. private:
  41. ErrorEvent(FlyString const& event_name, ErrorEventInit const& event_init)
  42. : DOM::Event(event_name)
  43. , m_message(event_init.message)
  44. , m_filename(event_init.filename)
  45. , m_lineno(event_init.lineno)
  46. , m_colno(event_init.colno)
  47. , m_error(JS::make_handle(event_init.error))
  48. {
  49. }
  50. String m_message { "" };
  51. String m_filename { "" }; // FIXME: This should be a USVString.
  52. u32 m_lineno { 0 };
  53. u32 m_colno { 0 };
  54. JS::Handle<JS::Value> m_error;
  55. };
  56. }