Bug 883313 - Fix nsHTMLDocument::SetBody to call either ReplaceChild or AppendChild, not both. r=smaug, a=abillings
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 04 Jul 2013 17:20:45 +0200
changeset 147887 73b647c71e493b36b08a5b1ce731af3dda884864
parent 147886 6f0387d46402994d682885207a486fbd909d19a6
child 147888 c01770ec0e205f493161042126413feda42ba5fc
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, abillings
bugs883313
milestone24.0a2
Bug 883313 - Fix nsHTMLDocument::SetBody to call either ReplaceChild or AppendChild, not both. r=smaug, a=abillings
content/html/document/src/nsHTMLDocument.cpp
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -1121,22 +1121,22 @@ nsHTMLDocument::SetBody(nsGenericHTMLEle
                     newBody->Tag() == nsGkAtoms::frameset) ||
       !root || !root->IsHTML() ||
       root->Tag() != nsGkAtoms::html) {
     rv.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
     return;
   }
 
   // Use DOM methods so that we pass through the appropriate security checks.
-  Element* currentBody = GetBodyElement();
+  nsCOMPtr<Element> currentBody = GetBodyElement();
   if (currentBody) {
     root->ReplaceChild(*newBody, *currentBody, rv);
+  } else {
+    root->AppendChild(*newBody, rv);
   }
-
-  root->AppendChild(*newBody, rv);
 }
 
 NS_IMETHODIMP
 nsHTMLDocument::GetHead(nsIDOMHTMLHeadElement** aHead)
 {
   *aHead = nullptr;
 
   Element* head = GetHeadElement();