1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * Implementations of DOM Core's Comment node.
12 #include "mozilla/dom/Comment.h"
13 #include "mozilla/dom/CommentBinding.h"
14 #include "mozilla/dom/Document.h"
15 #include "mozilla/IntegerPrintfMacros.h"
16 #include "nsPIDOMWindow.h"
18 using namespace mozilla
;
21 namespace mozilla::dom
{
23 Comment::~Comment() = default;
25 already_AddRefed
<CharacterData
> Comment::CloneDataNode(
26 mozilla::dom::NodeInfo
* aNodeInfo
, bool aCloneText
) const {
27 RefPtr
<mozilla::dom::NodeInfo
> ni
= aNodeInfo
;
28 auto* nim
= ni
->NodeInfoManager();
29 RefPtr
<Comment
> it
= new (nim
) Comment(ni
.forget());
38 void Comment::List(FILE* out
, int32_t aIndent
) const {
40 for (indx
= aIndent
; --indx
>= 0;) fputs(" ", out
);
42 fprintf(out
, "Comment@%p refcount=%" PRIuPTR
"<!--", (void*)this,
46 ToCString(tmp
, 0, mText
.GetLength());
47 fputs(NS_LossyConvertUTF16toASCII(tmp
).get(), out
);
54 already_AddRefed
<Comment
> Comment::Constructor(const GlobalObject
& aGlobal
,
55 const nsAString
& aData
,
57 nsCOMPtr
<nsPIDOMWindowInner
> window
=
58 do_QueryInterface(aGlobal
.GetAsSupports());
59 if (!window
|| !window
->GetDoc()) {
60 aRv
.Throw(NS_ERROR_FAILURE
);
64 return window
->GetDoc()->CreateComment(aData
);
67 JSObject
* Comment::WrapNode(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
68 return Comment_Binding::Wrap(aCx
, this, aGivenProto
);
71 } // namespace mozilla::dom