2021-10-11 12:59:45 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2021-10-11 12:59:45 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-03-05 10:56:50 +01:00
|
|
|
#include <AK/FlyString.h>
|
2024-11-15 04:01:23 +13:00
|
|
|
#include <LibGC/Root.h>
|
2021-10-11 12:59:45 +01:00
|
|
|
#include <LibJS/Runtime/Promise.h>
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
#include <LibWeb/DOM/Event.h>
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
|
|
struct PromiseRejectionEventInit : public DOM::EventInit {
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Root<JS::Object> promise;
|
2024-12-03 03:05:15 +13:00
|
|
|
JS::Value reason { JS::js_undefined() };
|
2021-10-11 12:59:45 +01:00
|
|
|
};
|
|
|
|
|
2022-08-08 22:29:40 +02:00
|
|
|
class PromiseRejectionEvent final : public DOM::Event {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(PromiseRejectionEvent, DOM::Event);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(PromiseRejectionEvent);
|
2022-08-08 22:29:40 +02:00
|
|
|
|
2021-10-11 12:59:45 +01:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<PromiseRejectionEvent> create(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& = {});
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<PromiseRejectionEvent>> construct_impl(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const&);
|
2021-10-11 12:59:45 +01:00
|
|
|
|
2022-08-08 22:29:40 +02:00
|
|
|
virtual ~PromiseRejectionEvent() override;
|
2021-10-11 12:59:45 +01:00
|
|
|
|
|
|
|
// Needs to return a pointer for the generated JS bindings to work.
|
2024-10-25 12:36:25 -06:00
|
|
|
JS::Object const* promise() const { return m_promise; }
|
2022-08-08 22:29:40 +02:00
|
|
|
JS::Value reason() const { return m_reason; }
|
|
|
|
|
|
|
|
private:
|
2023-03-05 10:56:50 +01:00
|
|
|
PromiseRejectionEvent(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init);
|
2022-09-25 16:38:21 -06:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-08 22:29:40 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<JS::Object> m_promise;
|
2022-08-08 22:29:40 +02:00
|
|
|
JS::Value m_reason;
|
2021-10-11 12:59:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|