diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index cac70f5aad..16270225c3 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -56,6 +56,8 @@ #include #include #include +#include +#include #include #include #include @@ -325,6 +327,7 @@ ADD_WINDOW_OBJECT_INTERFACE(DOMRectReadOnly) \ ADD_WINDOW_OBJECT_INTERFACE(DOMStringMap) \ ADD_WINDOW_OBJECT_INTERFACE(Element) \ + ADD_WINDOW_OBJECT_INTERFACE(ErrorEvent) \ ADD_WINDOW_OBJECT_INTERFACE(Event) \ ADD_WINDOW_OBJECT_INTERFACE(EventTarget) \ ADD_WINDOW_OBJECT_INTERFACE(History) \ diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 1f59aa84ee..ef3adaf176 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -413,6 +413,7 @@ libweb_js_wrapper(HTML/CanvasRenderingContext2D) libweb_js_wrapper(HTML/CloseEvent) libweb_js_wrapper(HTML/DOMParser) libweb_js_wrapper(HTML/DOMStringMap) +libweb_js_wrapper(HTML/ErrorEvent) libweb_js_wrapper(HTML/History) libweb_js_wrapper(HTML/HTMLAnchorElement) libweb_js_wrapper(HTML/HTMLAreaElement) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 414b387d10..1c188c7be3 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -128,6 +128,7 @@ class CanvasRenderingContext2D; class CloseEvent; class DOMParser; class DOMStringMap; +class ErrorEvent; struct EventHandler; class EventLoop; class HTMLAnchorElement; @@ -330,6 +331,7 @@ class DOMRectWrapper; class DOMStringMapWrapper; class DOMTokenListWrapper; class ElementWrapper; +class ErrorEventWrapper; class EventListenerWrapper; class EventTargetWrapper; class EventWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/ErrorEvent.h b/Userland/Libraries/LibWeb/HTML/ErrorEvent.h new file mode 100644 index 0000000000..3dd9eae119 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ErrorEvent.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2021, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/webappapis.html#erroreventinit +struct ErrorEventInit : public DOM::EventInit { + String message { "" }; + String filename { "" }; // FIXME: This should be a USVString. + u32 lineno { 0 }; + u32 colno { 0 }; + JS::Value error { JS::js_null() }; +}; + +// https://html.spec.whatwg.org/multipage/webappapis.html#errorevent +class ErrorEvent final : public DOM::Event { +public: + using WrapperType = Bindings::ErrorEventWrapper; + + static NonnullRefPtr create(FlyString const& event_name, ErrorEventInit const& event_init = {}) + { + return adopt_ref(*new ErrorEvent(event_name, event_init)); + } + + static NonnullRefPtr create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, ErrorEventInit const& event_init) + { + return ErrorEvent::create(event_name, event_init); + } + + virtual ~ErrorEvent() override = default; + + // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-message + String const& message() const { return m_message; } + + // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-filename + String const& filename() const { return m_filename; } + + // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-lineno + u32 lineno() const { return m_lineno; } + + // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-colno + u32 colno() const { return m_colno; } + + // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-error + JS::Value error() const { return m_error.value(); } + +private: + ErrorEvent(FlyString const& event_name, ErrorEventInit const& event_init) + : DOM::Event(event_name) + , m_message(event_init.message) + , m_filename(event_init.filename) + , m_lineno(event_init.lineno) + , m_colno(event_init.colno) + , m_error(JS::make_handle(event_init.error)) + { + } + + String m_message { "" }; + String m_filename { "" }; // FIXME: This should be a USVString. + u32 m_lineno { 0 }; + u32 m_colno { 0 }; + JS::Handle m_error; +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/ErrorEvent.idl b/Userland/Libraries/LibWeb/HTML/ErrorEvent.idl new file mode 100644 index 0000000000..2f8912dffb --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/ErrorEvent.idl @@ -0,0 +1,20 @@ +#import + +[Exposed=(Window,Worker)] +interface ErrorEvent : Event { + constructor(DOMString type, optional ErrorEventInit eventInitDict = {}); + + readonly attribute DOMString message; + readonly attribute USVString filename; + readonly attribute unsigned long lineno; + readonly attribute unsigned long colno; + readonly attribute any error; +}; + +dictionary ErrorEventInit : EventInit { + DOMString message = ""; + USVString filename = ""; + unsigned long lineno = 0; + unsigned long colno = 0; + any error = null; +};