summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML/ErrorEvent.h
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2021-10-14 16:53:39 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-07 14:58:18 +0100
commit11eedc309a548227ca70039189153f371b7bd0a7 (patch)
treebe55e562302caa51197cd46fafd82070f0dd9c3f /Userland/Libraries/LibWeb/HTML/ErrorEvent.h
parentdc42ca37bd63496cd47345b5540dd39d9924b2c7 (diff)
downloadserenity-11eedc309a548227ca70039189153f371b7bd0a7.zip
LibWeb: Implement ErrorEvent
This will be used by the new EventTarget to check if it needs to do special error event handling. Currently it isn't used for anything else.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/ErrorEvent.h')
-rw-r--r--Userland/Libraries/LibWeb/HTML/ErrorEvent.h72
1 files changed, 72 insertions, 0 deletions
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 <lukew@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/DOM/Event.h>
+
+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<ErrorEvent> create(FlyString const& event_name, ErrorEventInit const& event_init = {})
+ {
+ return adopt_ref(*new ErrorEvent(event_name, event_init));
+ }
+
+ static NonnullRefPtr<ErrorEvent> 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<JS::Value> m_error;
+};
+
+}