Bug 468562 - 'ASSERTION: Inserting multiple children without flushing' r+sr=mrbkap, a=dveditz GECKO1914_20091006_RELBRANCH
authorbnewman@mozilla.com
Sun, 01 Nov 2009 20:54:27 +0200
branchGECKO1914_20091006_RELBRANCH
changeset 26519 c204f7bb0064824dde9d28d394cf6611306492e9
parent 26518 edf189567edc4e7984f111709b9a1c58cf6ea6ed
child 26520 57f71400f4cfa968e0871b7a29640bc1e2056e64
push id2081
push usergsharp@mozilla.com
push dateMon, 02 Nov 2009 18:09:05 +0000
reviewersdveditz
bugs468562
milestone1.9.1.4
Bug 468562 - 'ASSERTION: Inserting multiple children without flushing' r+sr=mrbkap, a=dveditz
content/html/document/src/nsHTMLContentSink.cpp
--- a/content/html/document/src/nsHTMLContentSink.cpp
+++ b/content/html/document/src/nsHTMLContentSink.cpp
@@ -331,17 +331,17 @@ public:
   SinkContext(HTMLContentSink* aSink);
   ~SinkContext();
 
   nsresult Begin(nsHTMLTag aNodeType, nsGenericHTMLElement* aRoot,
                  PRUint32 aNumFlushed, PRInt32 aInsertionPoint);
   nsresult OpenContainer(const nsIParserNode& aNode);
   nsresult CloseContainer(const nsHTMLTag aTag, PRBool aMalformed);
   nsresult AddLeaf(const nsIParserNode& aNode);
-  nsresult AddLeaf(nsGenericHTMLElement* aContent);
+  nsresult AddLeaf(nsIContent* aContent);
   nsresult AddComment(const nsIParserNode& aNode);
   nsresult End();
 
   nsresult GrowStack();
   nsresult AddText(const nsAString& aText);
   nsresult FlushText(PRBool* aDidFlush = nsnull,
                      PRBool aReleaseLast = PR_FALSE);
   nsresult FlushTextAndRelease(PRBool* aDidFlush = nsnull)
@@ -895,16 +895,17 @@ SinkContext::HaveNotifiedForCurrentConte
   }
 
   return PR_TRUE;
 }
 
 nsIContent *
 SinkContext::Node::Add(nsIContent *child)
 {
+  NS_ASSERTION(mContent, "No parent to insert/append into!");
   if (mInsertionPoint != -1) {
     NS_ASSERTION(mNumFlushed == mContent->GetChildCount(),
                  "Inserting multiple children without flushing.");
     mContent->InsertChildAt(child, mInsertionPoint++, PR_FALSE);
   } else {
     mContent->AppendChildTo(child, PR_FALSE);
   }
   return child;
@@ -1150,17 +1151,17 @@ SinkContext::AddLeaf(const nsIParserNode
   default:
     break;
   }
 
   return rv;
 }
 
 nsresult
-SinkContext::AddLeaf(nsGenericHTMLElement* aContent)
+SinkContext::AddLeaf(nsIContent* aContent)
 {
   NS_ASSERTION(mStackPos > 0, "leaf w/o container");
   if (mStackPos <= 0) {
     return NS_ERROR_FAILURE;
   }
   
   DidAddContent(mStack[mStackPos - 1].Add(aContent));
 
@@ -1472,23 +1473,18 @@ SinkContext::FlushText(PRBool* aDidFlush
 
       // Set the text in the text node
       mLastTextNode->SetText(mText, mTextLength, PR_FALSE);
 
       // Eat up the rest of the text up in state.
       mLastTextNodeSize += mTextLength;
       mTextLength = 0;
 
-      // Add text to its parent
-      NS_ASSERTION(mStackPos > 0, "leaf w/o container");
-      if (mStackPos <= 0) {
-        return NS_ERROR_FAILURE;
-      }
-
-      DidAddContent(mStack[mStackPos - 1].Add(mLastTextNode));
+      rv = AddLeaf(mLastTextNode);
+      NS_ENSURE_SUCCESS(rv, rv);
 
       didFlush = PR_TRUE;
     }
   }
 
   if (aDidFlush) {
     *aDidFlush = didFlush;
   }
@@ -2900,23 +2896,18 @@ HTMLContentSink::ProcessBASEElement(nsGe
     }
   }
 }
 
 nsresult
 HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode)
 {
   nsresult  result = NS_OK;
-  nsGenericHTMLElement* parent = nsnull;
 
   if (mCurrentContext) {
-    parent = mCurrentContext->mStack[mCurrentContext->mStackPos - 1].mContent;
-  }
-
-  if (parent) {
     // Create content object
     nsCOMPtr<nsIContent> element;
     nsCOMPtr<nsINodeInfo> nodeInfo;
     nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::link, nsnull, kNameSpaceID_None);
 
     result = NS_NewHTMLElement(getter_AddRefs(element), nodeInfo, PR_FALSE);
     NS_ENSURE_SUCCESS(result, result);
 
@@ -2934,17 +2925,18 @@ HTMLContentSink::ProcessLINKTag(const ns
 
     // Add in the attributes and add the style content object to the
     // head container.
     AddBaseTagInfo(element);
     result = AddAttributes(aNode, element);
     if (NS_FAILED(result)) {
       return result;
     }
-    parent->AppendChildTo(element, PR_FALSE);
+
+    mCurrentContext->AddLeaf(element); // <link>s are leaves
 
     if (ssle) {
       ssle->SetEnableUpdates(PR_TRUE);
       PRBool willNotify;
       PRBool isAlternate;
       result = ssle->UpdateStyleSheet(this, &willNotify, &isAlternate);
       if (NS_SUCCEEDED(result) && willNotify && !isAlternate) {
         ++mPendingSheetCount;