ErrorEvent.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. JS_DECLARE_ALLOCATOR(ErrorEvent);
  22. public:
  23. [[nodiscard]] static JS::NonnullGCPtr<ErrorEvent> create(JS::Realm&, FlyString const& event_name, ErrorEventInit const& = {});
  24. static WebIDL::ExceptionOr<JS::NonnullGCPtr<ErrorEvent>> construct_impl(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init);
  25. virtual ~ErrorEvent() override;
  26. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-message
  27. String const& message() const { return m_message; }
  28. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-filename
  29. String const& filename() const { return m_filename; }
  30. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-lineno
  31. u32 lineno() const { return m_lineno; }
  32. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-colno
  33. u32 colno() const { return m_colno; }
  34. // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-error
  35. JS::Value error() const { return m_error; }
  36. private:
  37. ErrorEvent(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init);
  38. virtual void initialize(JS::Realm&) override;
  39. virtual void visit_edges(Cell::Visitor&) override;
  40. String m_message;
  41. String m_filename; // FIXME: This should be a USVString.
  42. u32 m_lineno { 0 };
  43. u32 m_colno { 0 };
  44. JS::Value m_error;
  45. };
  46. }