PromiseRejectionEvent.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/PromiseRejectionEventPrototype.h>
  7. #include <LibWeb/HTML/PromiseRejectionEvent.h>
  8. #include <LibWeb/HTML/Window.h>
  9. namespace Web::HTML {
  10. PromiseRejectionEvent* PromiseRejectionEvent::create(HTML::Window& window_object, FlyString const& event_name, PromiseRejectionEventInit const& event_init)
  11. {
  12. return window_object.heap().allocate<PromiseRejectionEvent>(window_object.realm(), window_object, event_name, event_init);
  13. }
  14. PromiseRejectionEvent* PromiseRejectionEvent::create_with_global_object(HTML::Window& window_object, FlyString const& event_name, PromiseRejectionEventInit const& event_init)
  15. {
  16. return create(window_object, event_name, event_init);
  17. }
  18. PromiseRejectionEvent::PromiseRejectionEvent(HTML::Window& window_object, FlyString const& event_name, PromiseRejectionEventInit const& event_init)
  19. : DOM::Event(window_object, event_name, event_init)
  20. , m_promise(const_cast<JS::Promise*>(event_init.promise.cell()))
  21. , m_reason(event_init.reason)
  22. {
  23. set_prototype(&window_object.ensure_web_prototype<Bindings::PromiseRejectionEventPrototype>("PromiseRejectionEvent"));
  24. }
  25. PromiseRejectionEvent::~PromiseRejectionEvent() = default;
  26. void PromiseRejectionEvent::visit_edges(Cell::Visitor& visitor)
  27. {
  28. Base::visit_edges(visitor);
  29. visitor.visit(m_promise);
  30. visitor.visit(m_reason);
  31. }
  32. }