Serenity Operating System
1/*
2 * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
3 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include <AK/FlyString.h>
11#include <LibJS/Heap/Handle.h>
12#include <LibJS/Runtime/Promise.h>
13#include <LibJS/Runtime/Value.h>
14#include <LibWeb/DOM/Event.h>
15
16namespace Web::HTML {
17
18struct PromiseRejectionEventInit : public DOM::EventInit {
19 JS::Handle<JS::Promise> promise;
20 JS::Value reason;
21};
22
23class PromiseRejectionEvent final : public DOM::Event {
24 WEB_PLATFORM_OBJECT(PromiseRejectionEvent, DOM::Event);
25
26public:
27 static WebIDL::ExceptionOr<JS::NonnullGCPtr<PromiseRejectionEvent>> create(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init = {});
28 static WebIDL::ExceptionOr<JS::NonnullGCPtr<PromiseRejectionEvent>> construct_impl(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init);
29
30 virtual ~PromiseRejectionEvent() override;
31
32 // Needs to return a pointer for the generated JS bindings to work.
33 JS::Promise const* promise() const { return m_promise; }
34 JS::Value reason() const { return m_reason; }
35
36private:
37 PromiseRejectionEvent(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init);
38
39 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
40 virtual void visit_edges(Cell::Visitor&) override;
41
42 JS::Promise* m_promise { nullptr };
43 JS::Value m_reason;
44};
45
46}