Bug 1193572, part 1 - Don't use return values of failing calls in XUL deserialize methods. r=baku

This commit is contained in:
Andrew McCreight 2015-08-13 14:24:59 -07:00
parent a4a08bb58a
commit e75d7d53b5

View File

@ -2278,16 +2278,15 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
// Read Node Info
uint32_t number = 0;
nsresult rv = aStream->Read32(&number);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
mNodeInfo = aNodeInfos->SafeElementAt(number, nullptr);
if (!mNodeInfo) {
return NS_ERROR_UNEXPECTED;
}
// Read Attributes
nsresult tmp = aStream->Read32(&number);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = aStream->Read32(&number);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
mNumAttributes = int32_t(number);
if (mNumAttributes > 0) {
@ -2298,10 +2297,8 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
nsAutoString attributeValue;
for (uint32_t i = 0; i < mNumAttributes; ++i) {
tmp = aStream->Read32(&number);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = aStream->Read32(&number);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
mozilla::dom::NodeInfo* ni = aNodeInfos->SafeElementAt(number, nullptr);
if (!ni) {
return NS_ERROR_UNEXPECTED;
@ -2309,31 +2306,23 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
mAttributes[i].mName.SetTo(ni);
tmp = aStream->ReadString(attributeValue);
if (NS_FAILED(tmp)) {
rv = tmp;
}
tmp = SetAttrAt(i, attributeValue, aDocumentURI);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = aStream->ReadString(attributeValue);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
rv = SetAttrAt(i, attributeValue, aDocumentURI);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
}
}
tmp = aStream->Read32(&number);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = aStream->Read32(&number);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
uint32_t numChildren = int32_t(number);
if (numChildren > 0) {
mChildren.SetCapacity(numChildren);
for (uint32_t i = 0; i < numChildren; i++) {
tmp = aStream->Read32(&number);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = aStream->Read32(&number);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
Type childType = (Type)number;
nsRefPtr<nsXULPrototypeNode> child;
@ -2343,31 +2332,25 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
child = new nsXULPrototypeElement();
child->mType = childType;
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
break;
case eType_Text:
child = new nsXULPrototypeText();
child->mType = childType;
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
break;
case eType_PI:
child = new nsXULPrototypePI();
child->mType = childType;
tmp = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = child->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
break;
case eType_Script: {
// language version/options obtained during deserialization.
@ -2375,28 +2358,20 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
child = script;
child->mType = childType;
tmp = aStream->ReadBoolean(&script->mOutOfLine);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = aStream->ReadBoolean(&script->mOutOfLine);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
if (! script->mOutOfLine) {
tmp = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
} else {
nsCOMPtr<nsISupports> supports;
tmp = aStream->ReadObject(true, getter_AddRefs(supports));
rv = aStream->ReadObject(true, getter_AddRefs(supports));
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
script->mSrcURI = do_QueryInterface(supports);
if (NS_FAILED(tmp)) {
rv = tmp;
}
tmp = script->DeserializeOutOfLine(aStream, aProtoDoc);
if (NS_FAILED(tmp)) {
rv = tmp;
}
rv = script->DeserializeOutOfLine(aStream, aProtoDoc);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
}
// If we failed to deserialize, consider deleting 'script'?
break;
@ -2417,7 +2392,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
// death. So, let's just fail now, and propagate that failure
// upward so that the ChromeProtocolHandler knows it can't use
// a cached chrome channel for this.
if (NS_FAILED(rv))
if (NS_WARN_IF(NS_FAILED(rv)))
return rv;
}
}
@ -2617,13 +2592,16 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
nsIURI* aDocumentURI,
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
{
nsresult rv;
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
!mScriptObject,
"prototype script not well-initialized when deserializing?!");
// Read basic prototype data
aStream->Read32(&mLineNo);
aStream->Read32(&mLangVersion);
rv = aStream->Read32(&mLineNo);
if (NS_FAILED(rv)) return rv;
rv = aStream->Read32(&mLangVersion);
if (NS_FAILED(rv)) return rv;
AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, xpc::CompilationScope());
@ -2631,8 +2609,8 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
JSAutoCompartment ac(cx, global);
JS::Rooted<JSScript*> newScriptObject(cx);
nsresult rv = nsContentUtils::XPConnect()->ReadScript(aStream, cx,
newScriptObject.address());
rv = nsContentUtils::XPConnect()->ReadScript(aStream, cx,
newScriptObject.address());
NS_ENSURE_SUCCESS(rv, rv);
Set(newScriptObject);
return NS_OK;
@ -2862,11 +2840,11 @@ nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
nsIURI* aDocumentURI,
const nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> *aNodeInfos)
{
nsresult rv;
rv = aStream->ReadString(mValue);
return rv;
nsresult rv = aStream->ReadString(mValue);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
//----------------------------------------------------------------------
@ -2905,10 +2883,9 @@ nsXULPrototypePI::Deserialize(nsIObjectInputStream* aStream,
nsresult rv;
rv = aStream->ReadString(mTarget);
nsresult tmp = aStream->ReadString(mData);
if (NS_FAILED(tmp)) {
rv = tmp;
}
if (NS_FAILED(rv)) return rv;
rv = aStream->ReadString(mData);
if (NS_FAILED(rv)) return rv;
return rv;
}