Serenity Operating System
at master 43 lines 1.2 kB view raw
1/* 2 * Copyright (c) 2020-2021, Luke Wilde <lukew@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibWeb/DOM/DocumentFragment.h> 8#include <LibWeb/HTML/Window.h> 9 10namespace Web::DOM { 11 12DocumentFragment::DocumentFragment(Document& document) 13 : ParentNode(document, NodeType::DOCUMENT_FRAGMENT_NODE) 14{ 15} 16 17JS::ThrowCompletionOr<void> DocumentFragment::initialize(JS::Realm& realm) 18{ 19 MUST_OR_THROW_OOM(Base::initialize(realm)); 20 set_prototype(&Bindings::ensure_web_prototype<Bindings::DocumentFragmentPrototype>(realm, "DocumentFragment")); 21 22 return {}; 23} 24 25void DocumentFragment::visit_edges(Cell::Visitor& visitor) 26{ 27 Base::visit_edges(visitor); 28 visitor.visit(m_host.ptr()); 29} 30 31void DocumentFragment::set_host(Web::DOM::Element* element) 32{ 33 m_host = element; 34} 35 36// https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment 37WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> DocumentFragment::construct_impl(JS::Realm& realm) 38{ 39 auto& window = verify_cast<HTML::Window>(realm.global_object()); 40 return MUST_OR_THROW_OOM(realm.heap().allocate<DocumentFragment>(realm, window.associated_document())); 41} 42 43}