content/base/src/Comment.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  * Implementations of DOM Core's nsIDOMComment node.
     8  */
    10 #include "nsCOMPtr.h"
    11 #include "mozilla/dom/Comment.h"
    12 #include "mozilla/dom/CommentBinding.h"
    13 #include "mozilla/IntegerPrintfMacros.h"
    15 using namespace mozilla;
    16 using namespace dom;
    18 namespace mozilla {
    19 namespace dom {
    21 Comment::~Comment()
    22 {
    23 }
    25 NS_IMPL_ISUPPORTS_INHERITED(Comment, nsGenericDOMDataNode, nsIDOMNode,
    26                             nsIDOMCharacterData, nsIDOMComment)
    28 bool
    29 Comment::IsNodeOfType(uint32_t aFlags) const
    30 {
    31   return !(aFlags & ~(eCONTENT | eCOMMENT | eDATA_NODE));
    32 }
    34 nsGenericDOMDataNode*
    35 Comment::CloneDataNode(nsINodeInfo *aNodeInfo, bool aCloneText) const
    36 {
    37   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
    38   Comment *it = new Comment(ni.forget());
    39   if (it && aCloneText) {
    40     it->mText = mText;
    41   }
    43   return it;
    44 }
    46 #ifdef DEBUG
    47 void
    48 Comment::List(FILE* out, int32_t aIndent) const
    49 {
    50   int32_t indx;
    51   for (indx = aIndent; --indx >= 0; ) fputs("  ", out);
    53   fprintf(out, "Comment@%p refcount=%" PRIuPTR "<!--", (void*)this, mRefCnt.get());
    55   nsAutoString tmp;
    56   ToCString(tmp, 0, mText.GetLength());
    57   fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
    59   fputs("-->\n", out);
    60 }
    61 #endif
    63 /* static */ already_AddRefed<Comment>
    64 Comment::Constructor(const GlobalObject& aGlobal,
    65                      const nsAString& aData, ErrorResult& aRv)
    66 {
    67   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
    68   if (!window || !window->GetDoc()) {
    69     aRv.Throw(NS_ERROR_FAILURE);
    70     return nullptr;
    71   }
    73   return window->GetDoc()->CreateComment(aData);
    74 }
    76 JSObject*
    77 Comment::WrapNode(JSContext *aCx)
    78 {
    79   return CommentBinding::Wrap(aCx, this);
    80 }
    82 } // namespace dom
    83 } // namespace mozilla

mercurial