NS_STATIC_CAST(const char*, extraWhiteSpace), NS_STATIC_CAST(const char*, textC)));
extraWhiteSpace.get(), textC.get()));
XULContentSinkImpl::CloseContainer(const nsIParserNode& aNode){    // Never EVER return anything but NS_OK or    // NS_ERROR_HTMLPARSER_BLOCK from this method. Doing so will blow    // the parser's little mind all over the planet.    nsresult rv;#ifdef PR_LOGGING    if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {        const nsAReadableString& text = aNode.GetText();        nsCAutoString extraWhiteSpace;        PRInt32 count = mContextStack.Depth();        while (--count > 0)            extraWhiteSpace += "  ";        nsCAutoString textC;        textC.AssignWithConversion(text);        PR_LOG(gLog, PR_LOG_DEBUG,               ("xul: %.5d. %s</%s>",                aNode.GetSourceLineNumber(),                NS_STATIC_CAST(const char*, extraWhiteSpace),                NS_STATIC_CAST(const char*, textC)));    }#endif    nsXULPrototypeNode* node;    rv = mContextStack.GetTopNode(&node);    if (NS_FAILED(rv)) {#ifdef PR_LOGGING        if (PR_LOG_TEST(gLog, PR_LOG_ALWAYS)) {            char* tagStr = ToNewCString(aNode.GetText());            PR_LOG(gLog, PR_LOG_ALWAYS,                   ("xul: extra close tag '</%s>' detected at line %d\n",                    tagStr, aNode.GetSourceLineNumber()));            nsCRT::free(tagStr);        }#endif        return NS_OK;    }    switch (node->mType) {    case nsXULPrototypeNode::eType_Element: {        // Flush any text _now_, so that we'll get text nodes created        // before popping the stack.        FlushText();        // Pop the context stack and do prototype hookup.        nsVoidArray* children;        rv = mContextStack.GetTopChildren(&children);        if (NS_FAILED(rv)) return rv;        nsXULPrototypeElement* element =            NS_REINTERPRET_CAST(nsXULPrototypeElement*, node);        PRInt32 count = children->Count();        if (count) {            element->mChildren = new nsXULPrototypeNode*[count];            if (! element->mChildren)                return NS_ERROR_OUT_OF_MEMORY;            for (PRInt32 i = count - 1; i >= 0; --i)                element->mChildren[i] =                    NS_REINTERPRET_CAST(nsXULPrototypeNode*, children->ElementAt(i));            element->mNumChildren = count;        }    }    break;    case nsXULPrototypeNode::eType_Script: {        nsXULPrototypeScript* script =            NS_STATIC_CAST(nsXULPrototypeScript*, node);        // If given a src= attribute, we must ignore script tag content.        if (! script->mSrcURI && ! script->mJSObject) {            nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);            rv = script->Compile(mText, mTextLength, mDocumentURL,                                 script->mLineNo, doc, mPrototype);        }        FlushText(PR_FALSE);    }    break;    default:        NS_ERROR("didn't expect that");        break;    }    rv = mContextStack.Pop(&mState);    NS_ASSERTION(NS_SUCCEEDED(rv), "context stack corrupted");    if (NS_FAILED(rv)) return rv;    PopNameSpaces();    if (mContextStack.Depth() == 0) {        // The root element should -always- be an element, because        // it'll have been created via XULContentSinkImpl::OpenRoot().        NS_ASSERTION(node->mType == nsXULPrototypeNode::eType_Element, "root is not an element");        if (node->mType != nsXULPrototypeNode::eType_Element)            return NS_ERROR_UNEXPECTED;        // Now that we're done parsing, set the prototype document's        // root element. This transfers ownership of the prototype        // element tree to the prototype document.        nsXULPrototypeElement* element =            NS_STATIC_CAST(nsXULPrototypeElement*, node);        rv = mPrototype->SetRootElement(element);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to set document root");        if (NS_FAILED(rv)) return rv;        mState = eInEpilog;    }    return NS_OK;}