rv |= GetDocumentPrincipal(getter_AddRefs(principal));
principal = GetDocumentPrincipal(); if (!principal) rv |= NS_ERROR_FAILURE;
nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream){    nsresult rv;    PRUint32 version;    rv = aStream->Read32(&version);    if (version != XUL_FASTLOAD_FILE_VERSION)        return NS_ERROR_FAILURE;    rv |= aStream->ReadObject(PR_TRUE, getter_AddRefs(mURI));    PRUint32 referenceCount;    nsCOMPtr<nsIURI> referenceURI;    PRUint32 i;    // nsISupportsArray mStyleSheetReferences    rv |= aStream->Read32(&referenceCount);    if (NS_FAILED(rv)) return rv;    for (i = 0; i < referenceCount; ++i) {        rv |= aStream->ReadObject(PR_TRUE, getter_AddRefs(referenceURI));                mStyleSheetReferences->AppendElement(referenceURI);    }    // nsISupportsArray mOverlayReferences    rv |= aStream->Read32(&referenceCount);    for (i = 0; i < referenceCount; ++i) {        rv |= aStream->ReadObject(PR_TRUE, getter_AddRefs(referenceURI));                mOverlayReferences->AppendElement(referenceURI);    }    // nsIPrincipal mDocumentPrincipal    nsCOMPtr<nsIPrincipal> principal;    rv |= NS_ReadOptionalObject(aStream, PR_TRUE, getter_AddRefs(principal));    if (! principal) {        rv |= GetDocumentPrincipal(getter_AddRefs(principal));    } else {        mNodeInfoManager->SetDocumentPrincipal(principal);        mDocumentPrincipal = principal;    }    // nsIScriptGlobalObject mGlobalObject    NewXULPDGlobalObject(getter_AddRefs(mGlobalObject));    if (! mGlobalObject)        return NS_ERROR_OUT_OF_MEMORY;    mRoot = new nsXULPrototypeElement();    if (! mRoot)       return NS_ERROR_OUT_OF_MEMORY;    nsCOMPtr<nsIScriptContext> scriptContext;    rv |= mGlobalObject->GetContext(getter_AddRefs(scriptContext));    NS_ASSERTION(scriptContext != nsnull,                 "no prototype script context!");    // nsINodeInfo table    nsCOMPtr<nsISupportsArray> nodeInfos;    rv |= NS_NewISupportsArray(getter_AddRefs(nodeInfos));    NS_ENSURE_TRUE(nodeInfos, rv);    rv |= aStream->Read32(&referenceCount);    nsAutoString namespaceURI, qualifiedName;    for (i = 0; i < referenceCount; ++i) {        rv |= aStream->ReadString(namespaceURI);        rv |= aStream->ReadString(qualifiedName);        nsCOMPtr<nsINodeInfo> nodeInfo;        rv |= mNodeInfoManager->GetNodeInfo(qualifiedName, namespaceURI, getter_AddRefs(nodeInfo));        rv |= nodeInfos->AppendElement(nodeInfo);    }    // Document contents    PRUint32 type;    rv |= aStream->Read32(&type);    if ((nsXULPrototypeNode::Type)type != nsXULPrototypeNode::eType_Element)        return NS_ERROR_FAILURE;    rv |= mRoot->Deserialize(aStream, scriptContext, mURI, nodeInfos);    rv |= NotifyLoadDone();    return rv;}