PromiseRejectionEvent.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #pragma once
  8. #include <LibJS/Runtime/Promise.h>
  9. #include <LibJS/Runtime/Value.h>
  10. #include <LibWeb/DOM/Event.h>
  11. namespace Web::HTML {
  12. struct PromiseRejectionEventInit : public DOM::EventInit {
  13. JS::Handle<JS::Promise> promise;
  14. JS::Value reason;
  15. };
  16. class PromiseRejectionEvent final : public DOM::Event {
  17. WEB_PLATFORM_OBJECT(PromiseRejectionEvent, DOM::Event);
  18. public:
  19. static PromiseRejectionEvent* create(HTML::Window&, FlyString const& event_name, PromiseRejectionEventInit const& event_init = {});
  20. static PromiseRejectionEvent* create_with_global_object(HTML::Window&, FlyString const& event_name, PromiseRejectionEventInit const& event_init);
  21. PromiseRejectionEvent(HTML::Window&, FlyString const& event_name, PromiseRejectionEventInit const& event_init);
  22. virtual ~PromiseRejectionEvent() override;
  23. // Needs to return a pointer for the generated JS bindings to work.
  24. JS::Promise const* promise() const { return m_promise; }
  25. JS::Value reason() const { return m_reason; }
  26. private:
  27. virtual void visit_edges(Cell::Visitor&) override;
  28. JS::Promise* m_promise { nullptr };
  29. JS::Value m_reason;
  30. };
  31. }
  32. WRAPPER_HACK(PromiseRejectionEvent, Web::HTML)