FlushTextAndRelease();  SINK_TRACE_NODE(SINK_TRACE_CALLS, "SinkContext::CloseContainer", aTag, mStackPos - 1, mSink);  NS_WARN_IF_FALSE(mStackPos > 0, "stack out of bounds. wrong context probably!");  if (mStackPos <= 0) { return NS_OK;
if (eHTMLTag_frameset == aTag) { MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::CloseContainer()\n")); MOZ_TIMER_STOP(mWatch); return CloseFrameset();
SinkContext::CloseContainer(const nsHTMLTag aTag){  nsresult result = NS_OK;  // Flush any collected text content. Release the last text  // node to indicate that no more should be added to it.  FlushTextAndRelease();  SINK_TRACE_NODE(SINK_TRACE_CALLS,                  "SinkContext::CloseContainer",                   aTag, mStackPos - 1, mSink);  NS_WARN_IF_FALSE(mStackPos > 0,                   "stack out of bounds. wrong context probably!");  if (mStackPos <= 0) {    return NS_OK; // Fix crash - Ref. bug 45975 or 45007  }  --mStackPos;  nsHTMLTag nodeType = mStack[mStackPos].mType;  nsIHTMLContent* content = mStack[mStackPos].mContent;  content->Compact();  // Add container to its parent if we haven't already done it  if ((mStack[mStackPos].mFlags & APPENDED) == 0) {    NS_ASSERTION(mStackPos > 0, "container w/o parent");    if (mStackPos <= 0) {      return NS_ERROR_FAILURE;    }    nsIHTMLContent* parent = mStack[mStackPos - 1].mContent;    // If the parent has an insertion point, insert rather than    // append.    if (mStack[mStackPos - 1].mInsertionPoint != -1) {      result = parent->InsertChildAt(content,                                     mStack[mStackPos - 1].mInsertionPoint++,                                     PR_FALSE, PR_FALSE);    } else {      result = parent->AppendChildTo(content, PR_FALSE, PR_FALSE);    }  }  // If we're in a state where we do append notifications as  // we go up the tree, and we're at the level where the next  // notification needs to be done, do the notification.  if (mNotifyLevel >= mStackPos) {    // Check to see if new content has been added after our last    // notification    if (mStack[mStackPos].mNumFlushed < content->GetChildCount()) {#ifdef NS_DEBUG      // Tracing code      nsCOMPtr<nsIAtom> tag;      mStack[mStackPos].mContent->GetTag(getter_AddRefs(tag));      const char *tagStr;      tag->GetUTF8String(&tagStr);      SINK_TRACE(SINK_TRACE_REFLOW,                 ("SinkContext::CloseContainer: reflow on notifyImmediate "                  "tag=%s newIndex=%d stackPos=%d",                  tagStr,                  mStack[mStackPos].mNumFlushed, mStackPos));#endif      mSink->NotifyAppend(content, mStack[mStackPos].mNumFlushed);    }    // Indicate that notification has now happened at this level    mNotifyLevel = mStackPos - 1;  }  if (mSink->IsMonolithicContainer(nodeType)) {    --mSink->mInMonolithicContainer;  }  DidAddContent(content, PR_FALSE);  // Special handling for certain tags  switch (nodeType) {  case eHTMLTag_noembed:  case eHTMLTag_noframes:    // Fix bug 40216    NS_ASSERTION((mSink->mInsideNoXXXTag > 0), "mInsideNoXXXTag underflow");    if (mSink->mInsideNoXXXTag > 0) {      mSink->mInsideNoXXXTag--;    }    break;  case eHTMLTag_form:    {      mSink->mFlags &= ~NS_SINK_FLAG_FORM_ON_STACK;      // If there's a FORM on the stack, but this close tag doesn't      // close the form, then close out the form *and* close out the      // next container up. This is since the parser doesn't do fix up      // of invalid form nesting. When the end FORM tag comes through,      // we'll ignore it.      if (aTag != nodeType) {        result = CloseContainer(aTag);      }    }    break;  case eHTMLTag_iframe:    mSink->mNumOpenIFRAMES--;    break;  case eHTMLTag_select:    {      nsCOMPtr<nsISelectElement> select = do_QueryInterface(content);      if (select) {        result = select->DoneAddingChildren();      }    }    break;  default:    break;  }  NS_IF_RELEASE(content);#ifdef DEBUG  if (mPreAppend &&      SINK_LOG_TEST(gSinkLogModuleInfo, SINK_ALWAYS_REFLOW)) {    mSink->ForceReflow();  }#endif  return result;}