Bug 1193572, part 4 - Make script element ownership more direct. r=baku

Rather than keep around a raw pointer |script| and depend on the fact
that |child| will keep alive the same object, make |script| strong,
then pass the reference off to |child| when we're finished with it.

I removed the comment about deleting |script| on failure because the
existing stack smart pointers already are doing this.

Also fix a tiny style nit.
This commit is contained in:
Andrew McCreight 2015-08-13 14:24:59 -07:00
parent 79605358de
commit 28bd11ffb5

View File

@ -2350,12 +2350,11 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
break;
case eType_Script: {
// language version/options obtained during deserialization.
nsXULPrototypeScript* script = new nsXULPrototypeScript(0, 0);
child = script;
nsRefPtr<nsXULPrototypeScript> script = new nsXULPrototypeScript(0, 0);
rv = aStream->ReadBoolean(&script->mOutOfLine);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
if (! script->mOutOfLine) {
if (!script->mOutOfLine) {
rv = script->Deserialize(aStream, aProtoDoc, aDocumentURI,
aNodeInfos);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
@ -2368,7 +2367,8 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
rv = script->DeserializeOutOfLine(aStream, aProtoDoc);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
}
// If we failed to deserialize, consider deleting 'script'?
child = script.forget();
break;
}
default: