Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / base / Comment.cpp
blobd9f5d68bcc06221bfc600026cdc5e55d7e4fbba6
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/. */
7 /*
8 * Implementations of DOM Core's Comment node.
9 */
11 #include "nsCOMPtr.h"
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;
19 using namespace dom;
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());
30 if (aCloneText) {
31 it->mText = mText;
34 return it.forget();
37 #ifdef DEBUG
38 void Comment::List(FILE* out, int32_t aIndent) const {
39 int32_t indx;
40 for (indx = aIndent; --indx >= 0;) fputs(" ", out);
42 fprintf(out, "Comment@%p refcount=%" PRIuPTR "<!--", (void*)this,
43 mRefCnt.get());
45 nsAutoString tmp;
46 ToCString(tmp, 0, mText.GetLength());
47 fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
49 fputs("-->\n", out);
51 #endif
53 /* static */
54 already_AddRefed<Comment> Comment::Constructor(const GlobalObject& aGlobal,
55 const nsAString& aData,
56 ErrorResult& aRv) {
57 nsCOMPtr<nsPIDOMWindowInner> window =
58 do_QueryInterface(aGlobal.GetAsSupports());
59 if (!window || !window->GetDoc()) {
60 aRv.Throw(NS_ERROR_FAILURE);
61 return nullptr;
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