PromiseRejectionEvent.h 1.4 KB

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