PromiseRejectionEvent.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. JS_DECLARE_ALLOCATOR(PromiseRejectionEvent);
  21. public:
  22. [[nodiscard]] static JS::NonnullGCPtr<PromiseRejectionEvent> create(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& = {});
  23. static WebIDL::ExceptionOr<JS::NonnullGCPtr<PromiseRejectionEvent>> construct_impl(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const&);
  24. virtual ~PromiseRejectionEvent() override;
  25. // Needs to return a pointer for the generated JS bindings to work.
  26. JS::Promise const* promise() const { return m_promise; }
  27. JS::Value reason() const { return m_reason; }
  28. private:
  29. PromiseRejectionEvent(JS::Realm&, FlyString const& event_name, PromiseRejectionEventInit const& event_init);
  30. virtual void initialize(JS::Realm&) override;
  31. virtual void visit_edges(Cell::Visitor&) override;
  32. JS::GCPtr<JS::Promise> m_promise;
  33. JS::Value m_reason;
  34. };
  35. }