DocumentFragment.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2020-2021, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/DOM/DocumentFragment.h>
  7. #include <LibWeb/HTML/Window.h>
  8. namespace Web::DOM {
  9. JS_DEFINE_ALLOCATOR(DocumentFragment);
  10. DocumentFragment::DocumentFragment(Document& document)
  11. : ParentNode(document, NodeType::DOCUMENT_FRAGMENT_NODE)
  12. {
  13. }
  14. void DocumentFragment::initialize(JS::Realm& realm)
  15. {
  16. Base::initialize(realm);
  17. WEB_SET_PROTOTYPE_FOR_INTERFACE(DocumentFragment);
  18. }
  19. void DocumentFragment::visit_edges(Cell::Visitor& visitor)
  20. {
  21. Base::visit_edges(visitor);
  22. visitor.visit(m_host);
  23. }
  24. void DocumentFragment::set_host(Web::DOM::Element* element)
  25. {
  26. m_host = element;
  27. }
  28. // https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment
  29. WebIDL::ExceptionOr<JS::NonnullGCPtr<DocumentFragment>> DocumentFragment::construct_impl(JS::Realm& realm)
  30. {
  31. auto& window = verify_cast<HTML::Window>(realm.global_object());
  32. return realm.heap().allocate<DocumentFragment>(realm, window.associated_document());
  33. }
  34. }