Comment.cpp 1003 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. Comment::Comment(Document& document, DeprecatedString const& data)
  12. : CharacterData(document, NodeType::COMMENT_NODE, data)
  13. {
  14. }
  15. // https://dom.spec.whatwg.org/#dom-comment-comment
  16. WebIDL::ExceptionOr<JS::NonnullGCPtr<Comment>> Comment::construct_impl(JS::Realm& realm, DeprecatedString const& data)
  17. {
  18. auto& window = verify_cast<HTML::Window>(realm.global_object());
  19. return MUST_OR_THROW_OOM(realm.heap().allocate<Comment>(realm, window.associated_document(), data));
  20. }
  21. JS::ThrowCompletionOr<void> Comment::initialize(JS::Realm& realm)
  22. {
  23. MUST_OR_THROW_OOM(Base::initialize(realm));
  24. set_prototype(&Bindings::ensure_web_prototype<Bindings::CommentPrototype>(realm, "Comment"));
  25. return {};
  26. }
  27. }