LCOV - code coverage report
Current view: top level - dom/base - DocumentFragment.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 9 57 15.8 %
Date: 2017-07-14 16:53:18 Functions: 5 9 55.6 %
Legend: Lines: hit not hit

          Line data    Source code
       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             :  * Implementation of DOM Core's nsIDOMDocumentFragment.
       9             :  */
      10             : 
      11             : #include "mozilla/dom/DocumentFragment.h"
      12             : #include "mozilla/dom/Element.h" // for NS_IMPL_ELEMENT_CLONE
      13             : #include "mozilla/dom/NodeInfo.h"
      14             : #include "nsNodeInfoManager.h"
      15             : #include "nsError.h"
      16             : #include "nsGkAtoms.h"
      17             : #include "nsDOMString.h"
      18             : #include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_TEAROFF
      19             : #include "mozilla/dom/DocumentFragmentBinding.h"
      20             : #include "nsPIDOMWindow.h"
      21             : #include "nsIDocument.h"
      22             : #include "mozilla/IntegerPrintfMacros.h"
      23             : 
      24             : namespace mozilla {
      25             : namespace dom {
      26             : 
      27             : JSObject*
      28           4 : DocumentFragment::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
      29             : {
      30           4 :   return DocumentFragmentBinding::Wrap(aCx, this, aGivenProto);
      31             : }
      32             : 
      33             : bool
      34         338 : DocumentFragment::IsNodeOfType(uint32_t aFlags) const
      35             : {
      36         338 :   return !(aFlags & ~(eCONTENT | eDOCUMENT_FRAGMENT));
      37             : }
      38             : 
      39             : #ifdef DEBUG
      40             : void
      41           0 : DocumentFragment::List(FILE* out, int32_t aIndent) const
      42             : {
      43             :   int32_t indent;
      44           0 :   for (indent = aIndent; --indent >= 0; ) {
      45           0 :     fputs("  ", out);
      46             :   }
      47             : 
      48           0 :   fprintf(out, "DocumentFragment@%p", (void *)this);
      49             : 
      50           0 :   fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
      51           0 :   fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
      52             : 
      53           0 :   nsIContent* child = GetFirstChild();
      54           0 :   if (child) {
      55           0 :     fputs("\n", out);
      56             : 
      57           0 :     for (; child; child = child->GetNextSibling()) {
      58           0 :       child->List(out, aIndent + 1);
      59             :     }
      60             : 
      61           0 :     for (indent = aIndent; --indent >= 0; ) {
      62           0 :       fputs("  ", out);
      63             :     }
      64             :   }
      65             : 
      66           0 :   fputs(">\n", out);
      67           0 : }
      68             : 
      69             : void
      70           0 : DocumentFragment::DumpContent(FILE* out, int32_t aIndent,
      71             :                               bool aDumpAll) const
      72             : {
      73             :   int32_t indent;
      74           0 :   for (indent = aIndent; --indent >= 0; ) {
      75           0 :     fputs("  ", out);
      76             :   }
      77             : 
      78           0 :   fputs("<DocumentFragment>", out);
      79             : 
      80           0 :   if(aIndent) {
      81           0 :     fputs("\n", out);
      82             :   }
      83             : 
      84           0 :   for (nsIContent* child = GetFirstChild();
      85           0 :        child;
      86           0 :        child = child->GetNextSibling()) {
      87           0 :     int32_t indent = aIndent ? aIndent + 1 : 0;
      88           0 :     child->DumpContent(out, indent, aDumpAll);
      89             :   }
      90           0 :   for (indent = aIndent; --indent >= 0; ) {
      91           0 :     fputs("  ", out);
      92             :   }
      93           0 :   fputs("</DocumentFragment>", out);
      94             : 
      95           0 :   if(aIndent) {
      96           0 :     fputs("\n", out);
      97             :   }
      98           0 : }
      99             : #endif
     100             : 
     101             : /* static */ already_AddRefed<DocumentFragment>
     102           0 : DocumentFragment::Constructor(const GlobalObject& aGlobal,
     103             :                               ErrorResult& aRv)
     104             : {
     105           0 :   nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
     106           0 :   if (!window || !window->GetDoc()) {
     107           0 :     aRv.Throw(NS_ERROR_FAILURE);
     108           0 :     return nullptr;
     109             :   }
     110             : 
     111           0 :   return window->GetDoc()->CreateDocumentFragment();
     112             : }
     113             : 
     114             : // QueryInterface implementation for DocumentFragment
     115          40 : NS_INTERFACE_MAP_BEGIN(DocumentFragment)
     116          40 :   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     117          36 :   NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment)
     118           0 :   NS_INTERFACE_MAP_ENTRY(nsIContent)
     119           0 :   NS_INTERFACE_MAP_ENTRY(nsINode)
     120           0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment)
     121           0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
     122           0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
     123           0 :   NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
     124           0 :   NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
     125             :                                  new nsNodeSupportsWeakRefTearoff(this))
     126             :   // DOM bindings depend on the identity pointer being the
     127             :   // same as nsINode (which nsIContent inherits).
     128           0 :   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
     129           0 : NS_INTERFACE_MAP_END
     130             : 
     131          44 : NS_IMPL_ADDREF_INHERITED(DocumentFragment, FragmentOrElement)
     132          40 : NS_IMPL_RELEASE_INHERITED(DocumentFragment, FragmentOrElement)
     133             : 
     134           0 : NS_IMPL_ELEMENT_CLONE(DocumentFragment)
     135             : 
     136             : } // namespace dom
     137             : } // namespace mozilla

Generated by: LCOV version 1.13