Bug 1193572, part 4 - Make script element ownership more direct. r=baku
authorAndrew McCreight <continuation@gmail.com>
Thu, 13 Aug 2015 14:24:59 -0700
changeset 257737 1fd45ba4bf7991a2b3939f2b30dea554d6177ef0
parent 257736 35bb18f835956149f7377cd44c39421f719ef832
child 257738 0051268bfb18723c6deb0875a5f656d6bafe8472
push id29226
push userryanvm@gmail.com
push dateFri, 14 Aug 2015 13:01:14 +0000
treeherdermozilla-central@1b2402247429 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1193572
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
dom/xul/nsXULElement.cpp
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -2345,35 +2345,35 @@ nsXULPrototypeElement::Deserialize(nsIOb
             case eType_PI:
                 child = new nsXULPrototypePI();
                 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.
-                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;
                 } else {
                     nsCOMPtr<nsISupports> supports;
                     rv = aStream->ReadObject(true, getter_AddRefs(supports));
                     if (NS_WARN_IF(NS_FAILED(rv))) return rv;
                     script->mSrcURI = do_QueryInterface(supports);
 
                     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:
                 MOZ_ASSERT(false, "Unexpected child type!");
                 return NS_ERROR_UNEXPECTED;
             }
 
             MOZ_ASSERT(child, "Don't append null to mChildren");