nsDocumentFragment::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { NS_ENSURE_ARG_POINTER(aReturn); *aReturn = nsnull;  nsresult rv = NS_OK; nsCOMPtr<nsIDOMDocumentFragment> newFragment;  rv = NS_NewDocumentFragment(getter_AddRefs(newFragment), mOwnerDocument); NS_ENSURE_SUCCESS(rv, rv);  if (aDeep) { nsCOMPtr<nsIDOMNodeList> childNodes;  GetChildNodes(getter_AddRefs(childNodes)); if (childNodes) { PRUint32 index, count; childNodes->GetLength(&count);  for (index = 0; index < count; ++index) { nsCOMPtr<nsIDOMNode> child; childNodes->Item(index, getter_AddRefs(child)); if (child) { nsCOMPtr<nsIDOMNode> newChild; rv = child->CloneNode(PR_TRUE, getter_AddRefs(newChild)); NS_ENSURE_SUCCESS(rv, rv);  nsCOMPtr<nsIDOMNode> dummyNode; rv = newFragment->AppendChild(newChild, getter_AddRefs(dummyNode)); NS_ENSURE_SUCCESS(rv, rv); } } } }  return CallQueryInterface(newFragment, aReturn); }
NS_IMPL_DOM_CLONENODE(nsDocumentFragment)
nsDocumentFragment::CloneNode(PRBool aDeep, nsIDOMNode** aReturn){  NS_ENSURE_ARG_POINTER(aReturn);  *aReturn = nsnull;  nsresult rv = NS_OK;  nsCOMPtr<nsIDOMDocumentFragment> newFragment;  rv = NS_NewDocumentFragment(getter_AddRefs(newFragment), mOwnerDocument);  NS_ENSURE_SUCCESS(rv, rv);  if (aDeep) {    nsCOMPtr<nsIDOMNodeList> childNodes;    GetChildNodes(getter_AddRefs(childNodes));    if (childNodes) {      PRUint32 index, count;      childNodes->GetLength(&count);      for (index = 0; index < count; ++index) {        nsCOMPtr<nsIDOMNode> child;        childNodes->Item(index, getter_AddRefs(child));        if (child) {          nsCOMPtr<nsIDOMNode> newChild;          rv = child->CloneNode(PR_TRUE, getter_AddRefs(newChild));          NS_ENSURE_SUCCESS(rv, rv);          nsCOMPtr<nsIDOMNode> dummyNode;          rv = newFragment->AppendChild(newChild,                                        getter_AddRefs(dummyNode));          NS_ENSURE_SUCCESS(rv, rv);        }      } // End of for loop    } // if (childNodes)  } // if (aDeep)  return CallQueryInterface(newFragment, aReturn);}