PromiseRejectionEvent.cpp 1.4 KB

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