Bug 1193086 - Remove some null checks of infallible new code in XUL. r=baku
authorAndrew McCreight <continuation@gmail.com>
Thu, 13 Aug 2015 14:24:59 -0700
changeset 257733 283c4c10df55bd006d6377fe8786525e45e9d0e8
parent 257732 47e0a4c1d10980f7a61ce25341134a8716d418d3
child 257734 96f6f2f2ed32b5eed203f849b50a43223916b11e
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
bugs1193086
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 1193086 - Remove some null checks of infallible new code in XUL. r=baku
dom/xul/XULDocument.cpp
dom/xul/nsXULCommandDispatcher.cpp
dom/xul/nsXULControllers.cpp
dom/xul/nsXULPrototypeDocument.cpp
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -235,19 +235,16 @@ XULDocument::~XULDocument()
 nsresult
 NS_NewXULDocument(nsIXULDocument** result)
 {
     NS_PRECONDITION(result != nullptr, "null ptr");
     if (! result)
         return NS_ERROR_NULL_POINTER;
 
     XULDocument* doc = new XULDocument();
-    if (! doc)
-        return NS_ERROR_OUT_OF_MEMORY;
-
     NS_ADDREF(doc);
 
     nsresult rv;
     if (NS_FAILED(rv = doc->Init())) {
         NS_RELEASE(doc);
         return rv;
     }
 
@@ -444,18 +441,16 @@ XULDocument::StartDocumentLoad(const cha
         // Set up the right principal on ourselves.
         SetPrincipal(proto->DocumentPrincipal());
 
         // We need a listener, even if proto is not yet loaded, in which
         // event the listener's OnStopRequest method does nothing, and all
         // the interesting work happens below XULDocument::EndLoad, from
         // the call there to mCurrentPrototype->NotifyLoadDone().
         *aDocListener = new CachedChromeStreamListener(this, loaded);
-        if (! *aDocListener)
-            return NS_ERROR_OUT_OF_MEMORY;
     }
     else {
         bool useXULCache = nsXULPrototypeCache::GetInstance()->IsEnabled();
         bool fillXULCache = (useXULCache && IsChromeURI(mDocumentURI));
 
 
         // It's just a vanilla document load. Create a parser to deal
         // with the stream n' stuff.
@@ -1630,19 +1625,16 @@ XULDocument::AddElementToDocumentPre(Ele
     bool listener, resolved;
     rv = CheckBroadcasterHookup(aElement, &listener, &resolved);
     if (NS_FAILED(rv)) return rv;
 
     // If it's not there yet, we may be able to defer hookup until
     // later.
     if (listener && !resolved && (mResolutionPhase != nsForwardReference::eDone)) {
         BroadcasterHookup* hookup = new BroadcasterHookup(this, aElement);
-        if (! hookup)
-            return NS_ERROR_OUT_OF_MEMORY;
-
         rv = AddForwardReference(hookup);
         if (NS_FAILED(rv)) return rv;
     }
 
     return NS_OK;
 }
 
 nsresult
@@ -1663,19 +1655,16 @@ XULDocument::AddElementToDocumentPost(El
     if (needsHookup) {
         if (mResolutionPhase == nsForwardReference::eDone) {
             rv = CreateTemplateBuilder(aElement);
             if (NS_FAILED(rv))
                 return rv;
         }
         else {
             TemplateBuilderHookup* hookup = new TemplateBuilderHookup(aElement);
-            if (! hookup)
-                return NS_ERROR_OUT_OF_MEMORY;
-
             rv = AddForwardReference(hookup);
             if (NS_FAILED(rv))
                 return rv;
         }
     }
 
     return NS_OK;
 }
@@ -1870,17 +1859,16 @@ XULDocument::Clone(mozilla::dom::NodeInf
 nsresult
 XULDocument::Init()
 {
     nsresult rv = XMLDocument::Init();
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Create our command dispatcher and hook it up.
     mCommandDispatcher = new nsXULCommandDispatcher(this);
-    NS_ENSURE_TRUE(mCommandDispatcher, NS_ERROR_OUT_OF_MEMORY);
 
     if (gRefCnt++ == 0) {
         // ensure that the XUL prototype cache is instantiated successfully,
         // so that we can use nsXULPrototypeCache::GetInstance() without
         // null-checks in the rest of the class.
         nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
         if (!cache) {
           NS_ERROR("Could not instantiate nsXULPrototypeCache");
@@ -2002,17 +1990,16 @@ XULDocument::PrepareToLoadPrototype(nsIU
         mMasterPrototype = mCurrentPrototype;
         // Set our principal based on the master proto.
         SetPrincipal(aDocumentPrincipal);
     }
 
     // Create a XUL content sink, a parser, and kick off a load for
     // the overlay.
     nsRefPtr<XULContentSinkImpl> sink = new XULContentSinkImpl();
-    if (!sink) return NS_ERROR_OUT_OF_MEMORY;
 
     rv = sink->Init(this, mCurrentPrototype);
     NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to initialize datasource sink");
     if (NS_FAILED(rv)) return rv;
 
     nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
     NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create parser");
     if (NS_FAILED(rv)) return rv;
@@ -2190,19 +2177,16 @@ XULDocument::ContextStack::~ContextStack
     }
 }
 
 nsresult
 XULDocument::ContextStack::Push(nsXULPrototypeElement* aPrototype,
                                 nsIContent* aElement)
 {
     Entry* entry = new Entry;
-    if (! entry)
-        return NS_ERROR_OUT_OF_MEMORY;
-
     entry->mPrototype = aPrototype;
     entry->mElement   = aElement;
     NS_IF_ADDREF(entry->mElement);
     entry->mIndex     = 0;
 
     entry->mNext = mTop;
     mTop = entry;
 
@@ -2647,19 +2631,16 @@ XULDocument::LoadOverlayInternal(nsIURI*
         if (! listener)
             return NS_ERROR_UNEXPECTED;
 
         // Add an observer to the parser; this'll get called when
         // Necko fires its On[Start|Stop]Request() notifications,
         // and will let us recover from a missing overlay.
         ParserObserver* parserObserver =
             new ParserObserver(this, mCurrentPrototype);
-        if (! parserObserver)
-            return NS_ERROR_OUT_OF_MEMORY;
-
         NS_ADDREF(parserObserver);
         parser->Parse(aURI, parserObserver);
         NS_RELEASE(parserObserver);
 
         nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
         nsCOMPtr<nsIChannel> channel;
         // Set the owner of the channel to be our principal so
         // that the overlay's JSObjects etc end up being created
@@ -3627,18 +3608,16 @@ XULDocument::CreateOverlayElement(nsXULP
     nsresult rv;
 
     nsRefPtr<Element> element;
     rv = CreateElementFromPrototype(aPrototype, getter_AddRefs(element), false);
     if (NS_FAILED(rv)) return rv;
 
     OverlayForwardReference* fwdref =
         new OverlayForwardReference(this, element);
-    if (! fwdref)
-        return NS_ERROR_OUT_OF_MEMORY;
 
     // transferring ownership to ya...
     rv = AddForwardReference(fwdref);
     if (NS_FAILED(rv)) return rv;
 
     element.forget(aResult);
     return NS_OK;
 }
--- a/dom/xul/nsXULCommandDispatcher.cpp
+++ b/dom/xul/nsXULCommandDispatcher.cpp
@@ -305,21 +305,17 @@ nsXULCommandDispatcher::AddCommandUpdate
            ("xulcmd[%p] add     %p(events=%s targets=%s)",
             this, aElement,
             aeventsC.get(),
             atargetsC.get()));
   }
 #endif
 
   // If we get here, this is a new updater. Append it to the list.
-  updater = new Updater(aElement, aEvents, aTargets);
-  if (! updater)
-      return NS_ERROR_OUT_OF_MEMORY;
-
-  *link = updater;
+  *link = new Updater(aElement, aEvents, aTargets);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULCommandDispatcher::RemoveCommandUpdater(nsIDOMElement* aElement)
 {
   NS_PRECONDITION(aElement != nullptr, "null ptr");
   if (! aElement)
--- a/dom/xul/nsXULControllers.cpp
+++ b/dom/xul/nsXULControllers.cpp
@@ -47,19 +47,16 @@ nsXULControllers::DeleteControllers()
 nsresult
 NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
   NS_PRECONDITION(aOuter == nullptr, "no aggregation");
   if (aOuter)
     return NS_ERROR_NO_AGGREGATION;
 
   nsXULControllers* controllers = new nsXULControllers();
-  if (! controllers)
-    return NS_ERROR_OUT_OF_MEMORY;
-  
   nsresult rv;
   NS_ADDREF(controllers);
   rv = controllers->QueryInterface(aIID, aResult);
   NS_RELEASE(controllers);
   return rv;
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULControllers)
@@ -116,17 +113,16 @@ nsXULControllers::GetControllerForComman
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULControllers::InsertControllerAt(uint32_t aIndex, nsIController *controller)
 {
   nsXULControllerData*  controllerData = new nsXULControllerData(++mCurControllerID, controller);
-  if (!controllerData) return NS_ERROR_OUT_OF_MEMORY;
 #ifdef DEBUG
   nsXULControllerData** inserted =
 #endif
   mControllers.InsertElementAt(aIndex, controllerData);
   NS_ASSERTION(inserted != nullptr, "Insertion of controller failed");
   return NS_OK;
 }
 
@@ -160,17 +156,16 @@ nsXULControllers::GetControllerAt(uint32
   return controllerData->GetController(_retval);   // does the addref  
 }
 
 NS_IMETHODIMP
 nsXULControllers::AppendController(nsIController *controller)
 {
   // This assigns controller IDs starting at 1 so we can use 0 to test if an ID was obtained
   nsXULControllerData*  controllerData = new nsXULControllerData(++mCurControllerID, controller);
-  if (!controllerData) return NS_ERROR_OUT_OF_MEMORY;
 
 #ifdef DEBUG
   nsXULControllerData** appended =
 #endif
   mControllers.AppendElement(controllerData);
   NS_ASSERTION(appended != nullptr, "Appending controller failed");
   return NS_OK;
 }
--- a/dom/xul/nsXULPrototypeDocument.cpp
+++ b/dom/xul/nsXULPrototypeDocument.cpp
@@ -49,18 +49,16 @@ nsXULPrototypeDocument::nsXULPrototypeDo
     ++gRefCnt;
 }
 
 
 nsresult
 nsXULPrototypeDocument::Init()
 {
     mNodeInfoManager = new nsNodeInfoManager();
-    NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_OUT_OF_MEMORY);
-
     return mNodeInfoManager->Init(nullptr);
 }
 
 nsXULPrototypeDocument::~nsXULPrototypeDocument()
 {
     if (mRoot)
         mRoot->ReleaseSubtree();
 }
@@ -144,18 +142,16 @@ nsXULPrototypeDocument::Read(nsIObjectIn
     principal = do_QueryInterface(supports);
     if (NS_FAILED(tmp)) {
       rv = tmp;
     }
     // Better safe than sorry....
     mNodeInfoManager->SetDocumentPrincipal(principal);
 
     mRoot = new nsXULPrototypeElement();
-    if (! mRoot)
-       return NS_ERROR_OUT_OF_MEMORY;
 
     // mozilla::dom::NodeInfo table
     nsTArray<nsRefPtr<mozilla::dom::NodeInfo>> nodeInfos;
 
     tmp = aStream->Read32(&count);
     if (NS_FAILED(tmp)) {
       rv = tmp;
     }
@@ -203,20 +199,16 @@ nsXULPrototypeDocument::Read(nsIObjectIn
     while (NS_SUCCEEDED(rv)) {
         tmp = aStream->Read32(&type);
         if (NS_FAILED(tmp)) {
           rv = tmp;
         }
 
         if ((nsXULPrototypeNode::Type)type == nsXULPrototypeNode::eType_PI) {
             nsRefPtr<nsXULPrototypePI> pi = new nsXULPrototypePI();
-            if (! pi) {
-               rv = NS_ERROR_OUT_OF_MEMORY;
-               break;
-            }
 
             tmp = pi->Deserialize(aStream, this, mURI, &nodeInfos);
             if (NS_FAILED(tmp)) {
               rv = tmp;
             }
             tmp = AddProcessingInstruction(pi);
             if (NS_FAILED(tmp)) {
               rv = tmp;