tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Comment.cpp (2043B)


      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/. */
      6 
      7 /*
      8 * Implementations of DOM Core's Comment node.
      9 */
     10 
     11 #include "mozilla/dom/Comment.h"
     12 
     13 #include "mozilla/IntegerPrintfMacros.h"
     14 #include "mozilla/dom/CommentBinding.h"
     15 #include "mozilla/dom/Document.h"
     16 #include "nsCOMPtr.h"
     17 #include "nsPIDOMWindow.h"
     18 
     19 using namespace mozilla;
     20 using namespace dom;
     21 
     22 namespace mozilla::dom {
     23 
     24 Comment::~Comment() = default;
     25 
     26 already_AddRefed<CharacterData> Comment::CloneDataNode(
     27    mozilla::dom::NodeInfo* aNodeInfo, bool aCloneText) const {
     28  RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
     29  auto* nim = ni->NodeInfoManager();
     30  RefPtr<Comment> it = new (nim) Comment(ni.forget());
     31  if (aCloneText) {
     32    it->mBuffer = mBuffer;
     33  }
     34 
     35  return it.forget();
     36 }
     37 
     38 #ifdef DEBUG
     39 void Comment::List(FILE* out, int32_t aIndent) const {
     40  int32_t indx;
     41  for (indx = aIndent; --indx >= 0;) fputs("  ", out);
     42 
     43  fprintf(out, "Comment@%p refcount=%" PRIuPTR "<!--", (void*)this,
     44          mRefCnt.get());
     45 
     46  nsAutoString tmp;
     47  ToCString(tmp, 0, mBuffer.GetLength());
     48  fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
     49 
     50  fputs("-->\n", out);
     51 }
     52 #endif
     53 
     54 /* static */
     55 already_AddRefed<Comment> Comment::Constructor(const GlobalObject& aGlobal,
     56                                               const nsAString& aData,
     57                                               ErrorResult& aRv) {
     58  nsCOMPtr<nsPIDOMWindowInner> window =
     59      do_QueryInterface(aGlobal.GetAsSupports());
     60  if (!window || !window->GetDoc()) {
     61    aRv.Throw(NS_ERROR_FAILURE);
     62    return nullptr;
     63  }
     64 
     65  return window->GetDoc()->CreateComment(aData);
     66 }
     67 
     68 JSObject* Comment::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     69  return Comment_Binding::Wrap(aCx, this, aGivenProto);
     70 }
     71 
     72 }  // namespace mozilla::dom