/* * Copyright (c) 2021, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Web::HTML { struct PromiseRejectionEventInit : public DOM::EventInit { JS::Handle promise; JS::Value reason; }; class PromiseRejectionEvent : public DOM::Event { public: using WrapperType = Bindings::PromiseRejectionEventWrapper; static NonnullRefPtr create(FlyString const& event_name, PromiseRejectionEventInit const& event_init = {}) { return adopt_ref(*new PromiseRejectionEvent(event_name, event_init)); } static NonnullRefPtr create_with_global_object(Bindings::WindowObject&, FlyString const& event_name, PromiseRejectionEventInit const& event_init) { return PromiseRejectionEvent::create(event_name, event_init); } virtual ~PromiseRejectionEvent() override = default; // Needs to return a pointer for the generated JS bindings to work. JS::Promise const* promise() const { return m_promise.cell(); } JS::Value reason() const { return m_reason.value(); } protected: PromiseRejectionEvent(FlyString const& event_name, PromiseRejectionEventInit const& event_init) : DOM::Event(event_name, event_init) , m_promise(event_init.promise) , m_reason(JS::make_handle(event_init.reason)) { } JS::Handle m_promise; JS::Handle m_reason; }; }