Comment.cpp 885 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/CommentPrototype.h>
  7. #include <LibWeb/DOM/Comment.h>
  8. #include <LibWeb/HTML/Window.h>
  9. #include <LibWeb/Layout/TextNode.h>
  10. namespace Web::DOM {
  11. JS_DEFINE_ALLOCATOR(Comment);
  12. Comment::Comment(Document& document, String const& data)
  13. : CharacterData(document, NodeType::COMMENT_NODE, data)
  14. {
  15. }
  16. // https://dom.spec.whatwg.org/#dom-comment-comment
  17. WebIDL::ExceptionOr<JS::NonnullGCPtr<Comment>> Comment::construct_impl(JS::Realm& realm, String const& data)
  18. {
  19. auto& window = verify_cast<HTML::Window>(realm.global_object());
  20. return realm.heap().allocate<Comment>(realm, window.associated_document(), data);
  21. }
  22. void Comment::initialize(JS::Realm& realm)
  23. {
  24. Base::initialize(realm);
  25. WEB_SET_PROTOTYPE_FOR_INTERFACE(Comment);
  26. }
  27. }