PromiseRejectionEvent.cpp 1.3 KB

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