Bug 455540. Eliminate the non-OOM-failures-possible version of GetNodInfo. r+sr=jst

This commit is contained in:
Boris Zbarsky 2008-10-07 14:53:22 -04:00
parent e8e7d646e5
commit 4f3a824bf4
4 changed files with 29 additions and 34 deletions

View File

@ -262,34 +262,11 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
nsresult
nsNodeInfoManager::GetNodeInfo(const nsAString& aQualifiedName,
nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
const nsAString& aNamespaceURI,
nsINodeInfo** aNodeInfo)
{
NS_ENSURE_ARG(!aQualifiedName.IsEmpty());
nsAString::const_iterator start, end;
aQualifiedName.BeginReading(start);
aQualifiedName.EndReading(end);
nsCOMPtr<nsIAtom> prefixAtom;
nsAString::const_iterator iter(start);
if (FindCharInReadable(':', iter, end)) {
prefixAtom = do_GetAtom(Substring(start, iter));
NS_ENSURE_TRUE(prefixAtom, NS_ERROR_OUT_OF_MEMORY);
start = ++iter; // step over the ':'
if (iter == end) {
// No data after the ':'.
return NS_ERROR_INVALID_ARG;
}
}
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(Substring(start, end));
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
PRInt32 nsid = kNameSpaceID_None;
@ -300,7 +277,7 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aQualifiedName,
NS_ENSURE_SUCCESS(rv, rv);
}
*aNodeInfo = GetNodeInfo(nameAtom, prefixAtom, nsid).get();
*aNodeInfo = GetNodeInfo(nameAtom, aPrefix, nsid).get();
return *aNodeInfo ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -89,7 +89,7 @@ public:
PRInt32 aNamespaceID);
nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
PRInt32 aNamespaceID, nsINodeInfo** aNodeInfo);
nsresult GetNodeInfo(const nsAString& aQualifiedName,
nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
const nsAString& aNamespaceURI,
nsINodeInfo** aNodeInfo);

View File

@ -82,7 +82,7 @@ const char XUL_FASTLOAD_FILE_BASENAME[] = "XUL";
// (opaque to XPCOM FastLoad code) format of XUL-specific XDR serializations.
// See also JSXDR_BYTECODE_VERSION in jsxdrapi.h, which tracks incompatible JS
// bytecode version changes.
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 24)
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 25)
#define XUL_SERIALIZATION_BUFFER_SIZE (64 * 1024)
#define XUL_DESERIALIZATION_BUFFER_SIZE (8 * 1024)

View File

@ -307,13 +307,23 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
nsCOMArray<nsINodeInfo> nodeInfos;
rv |= aStream->Read32(&count);
nsAutoString namespaceURI, qualifiedName;
nsAutoString namespaceURI, prefixStr, localName;
PRBool prefixIsNull;
nsCOMPtr<nsIAtom> prefix;
for (i = 0; i < count; ++i) {
rv |= aStream->ReadString(namespaceURI);
rv |= aStream->ReadString(qualifiedName);
rv |= aStream->ReadBoolean(&prefixIsNull);
if (prefixIsNull) {
prefix = nsnull;
} else {
rv |= aStream->ReadString(prefixStr);
prefix = do_GetAtom(prefixStr);
}
rv |= aStream->ReadString(localName);
nsCOMPtr<nsINodeInfo> nodeInfo;
rv |= mNodeInfoManager->GetNodeInfo(qualifiedName, namespaceURI, getter_AddRefs(nodeInfo));
rv |= mNodeInfoManager->GetNodeInfo(localName, prefix, namespaceURI,
getter_AddRefs(nodeInfo));
if (!nodeInfos.AppendObject(nodeInfo))
rv |= NS_ERROR_OUT_OF_MEMORY;
}
@ -428,9 +438,17 @@ nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream)
rv |= nodeInfo->GetNamespaceURI(namespaceURI);
rv |= aStream->WriteWStringZ(namespaceURI.get());
nsAutoString qualifiedName;
nodeInfo->GetQualifiedName(qualifiedName);
rv |= aStream->WriteWStringZ(qualifiedName.get());
nsAutoString prefix;
nodeInfo->GetPrefix(prefix);
PRBool nullPrefix = DOMStringIsNull(prefix);
rv |= aStream->WriteBoolean(nullPrefix);
if (!nullPrefix) {
rv |= aStream->WriteWStringZ(prefix.get());
}
nsAutoString localName;
nodeInfo->GetName(localName);
rv |= aStream->WriteWStringZ(localName.get());
}
// Now serialize the document contents