Serenity Operating System
1/*
2 * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/FlyString.h>
10#include <LibWeb/DOM/Event.h>
11
12namespace Web::HTML {
13
14// https://html.spec.whatwg.org/multipage/webappapis.html#erroreventinit
15struct ErrorEventInit : public DOM::EventInit {
16 String message;
17 String filename; // FIXME: This should be a USVString.
18 u32 lineno { 0 };
19 u32 colno { 0 };
20 JS::Value error { JS::js_null() };
21};
22
23// https://html.spec.whatwg.org/multipage/webappapis.html#errorevent
24class ErrorEvent final : public DOM::Event {
25 WEB_PLATFORM_OBJECT(ErrorEvent, DOM::Event);
26
27public:
28 static WebIDL::ExceptionOr<JS::NonnullGCPtr<ErrorEvent>> create(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init = {});
29 static WebIDL::ExceptionOr<JS::NonnullGCPtr<ErrorEvent>> construct_impl(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init);
30
31 virtual ~ErrorEvent() override;
32
33 // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-message
34 String const& message() const { return m_message; }
35
36 // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-filename
37 String const& filename() const { return m_filename; }
38
39 // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-lineno
40 u32 lineno() const { return m_lineno; }
41
42 // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-colno
43 u32 colno() const { return m_colno; }
44
45 // https://html.spec.whatwg.org/multipage/webappapis.html#dom-errorevent-error
46 JS::Value error() const { return m_error; }
47
48private:
49 ErrorEvent(JS::Realm&, FlyString const& event_name, ErrorEventInit const& event_init);
50
51 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
52 virtual void visit_edges(Cell::Visitor&) override;
53
54 String m_message;
55 String m_filename; // FIXME: This should be a USVString.
56 u32 m_lineno { 0 };
57 u32 m_colno { 0 };
58 JS::Value m_error;
59};
60
61}