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