PromiseRejectionEvent.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_DEFINE_ALLOCATOR(PromiseRejectionEvent);
  10. JS::NonnullGCPtr<PromiseRejectionEvent> PromiseRejectionEvent::create(JS::Realm& realm, FlyString const& event_name, PromiseRejectionEventInit const& event_init)
  11. {
  12. return realm.heap().allocate<PromiseRejectionEvent>(realm, realm, event_name, event_init);
  13. }
  14. WebIDL::ExceptionOr<JS::NonnullGCPtr<PromiseRejectionEvent>> PromiseRejectionEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, PromiseRejectionEventInit const& event_init)
  15. {
  16. return create(realm, event_name, event_init);
  17. }
  18. PromiseRejectionEvent::PromiseRejectionEvent(JS::Realm& realm, FlyString const& event_name, PromiseRejectionEventInit const& event_init)
  19. : DOM::Event(realm, event_name, event_init)
  20. , m_promise(const_cast<JS::Promise*>(event_init.promise.cell()))
  21. , m_reason(event_init.reason)
  22. {
  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. void PromiseRejectionEvent::initialize(JS::Realm& realm)
  32. {
  33. Base::initialize(realm);
  34. WEB_SET_PROTOTYPE_FOR_INTERFACE(PromiseRejectionEvent);
  35. }
  36. }