Bug 1268772 (part 4) - Use MOZ_MUST_USE with NS_NewISupportsArray(). r=erahm.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 02 May 2016 09:06:47 +1000
changeset 295704 ca1b48e0c972772ddad2708febc86f3ab10c5c28
parent 295703 a2061ce934cbd547eb692165d819224a40d940c8
child 295705 1d99e6c5a2bf41b983658369b97c5d152649695b
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1268772
milestone49.0a1
Bug 1268772 (part 4) - Use MOZ_MUST_USE with NS_NewISupportsArray(). r=erahm. A few callers of NS_NewISupportsArray() didn't use the return value to detect failure, but instead checked if the |array| argument was null after the call. This is inconsistent with the majority of the calls to NS_NewISupportsArray(). This patch changes them to be checked in the normal way.
embedding/components/printingui/unixshared/nsPrintingPromptService.cpp
embedding/components/printingui/win/nsPrintingPromptService.cpp
layout/inspector/inDOMUtils.cpp
xpcom/ds/nsISupportsArray.idl
xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
--- a/embedding/components/printingui/unixshared/nsPrintingPromptService.cpp
+++ b/embedding/components/printingui/unixshared/nsPrintingPromptService.cpp
@@ -193,33 +193,33 @@ nsPrintingPromptService::DoDialog(mozIDO
 {
     NS_ENSURE_ARG(aParamBlock);
     NS_ENSURE_ARG(aPS);
     NS_ENSURE_ARG(aChromeURL);
 
     if (!mWatcher)
         return NS_ERROR_FAILURE;
 
-    nsresult rv = NS_OK;
-
     // get a parent, if at all possible
     // (though we'd rather this didn't fail, it's OK if it does. so there's
     // no failure or null check.)
     nsCOMPtr<mozIDOMWindowProxy> activeParent;
     if (!aParent) 
     {
         mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
         aParent = activeParent;
     }
 
     // create a nsISupportsArray of the parameters 
     // being passed to the window
     nsCOMPtr<nsISupportsArray> array;
-    NS_NewISupportsArray(getter_AddRefs(array));
-    if (!array) return NS_ERROR_FAILURE;
+    nsresult rv = NS_NewISupportsArray(getter_AddRefs(array));
+    if (NS_FAILED(rv)) {
+      return NS_ERROR_FAILURE;
+    }
 
     nsCOMPtr<nsISupports> psSupports(do_QueryInterface(aPS));
     NS_ASSERTION(psSupports, "PrintSettings must be a supports");
     array->AppendElement(psSupports);
 
     if (aWebBrowserPrint) {
       nsCOMPtr<nsISupports> wbpSupports(do_QueryInterface(aWebBrowserPrint));
       NS_ASSERTION(wbpSupports, "nsIWebBrowserPrint must be a supports");
--- a/embedding/components/printingui/win/nsPrintingPromptService.cpp
+++ b/embedding/components/printingui/win/nsPrintingPromptService.cpp
@@ -243,33 +243,33 @@ nsPrintingPromptService::DoDialog(mozIDO
 {
     NS_ENSURE_ARG(aParamBlock);
     NS_ENSURE_ARG(aPS);
     NS_ENSURE_ARG(aChromeURL);
 
     if (!mWatcher)
         return NS_ERROR_FAILURE;
 
-    nsresult rv = NS_OK;
-
     // get a parent, if at all possible
     // (though we'd rather this didn't fail, it's OK if it does. so there's
     // no failure or null check.)
     nsCOMPtr<mozIDOMWindowProxy> activeParent; // retain ownership for method lifetime
     if (!aParent) 
     {
         mWatcher->GetActiveWindow(getter_AddRefs(activeParent));
         aParent = activeParent;
     }
 
     // create a nsISupportsArray of the parameters 
     // being passed to the window
     nsCOMPtr<nsISupportsArray> array;
-    NS_NewISupportsArray(getter_AddRefs(array));
-    if (!array) return NS_ERROR_FAILURE;
+    nsresult rv = NS_NewISupportsArray(getter_AddRefs(array));
+    if (NS_FAILED(rv)) {
+        return NS_ERROR_FAILURE;
+    }
 
     nsCOMPtr<nsISupports> psSupports(do_QueryInterface(aPS));
     NS_ASSERTION(psSupports, "PrintSettings must be a supports");
     array->AppendElement(psSupports);
 
     nsCOMPtr<nsISupports> blkSupps(do_QueryInterface(aParamBlock));
     NS_ASSERTION(blkSupps, "IOBlk must be a supports");
     array->AppendElement(blkSupps);
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -241,18 +241,20 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
   GetRuleNodeForElement(element, pseudoElt, getter_AddRefs(styleContext), &ruleNode);
   if (!ruleNode) {
     // This can fail for elements that are not in the document or
     // if the document they're in doesn't have a presshell.  Bail out.
     return NS_OK;
   }
 
   nsCOMPtr<nsISupportsArray> rules;
-  NS_NewISupportsArray(getter_AddRefs(rules));
-  if (!rules) return NS_ERROR_OUT_OF_MEMORY;
+  nsresult rv = NS_NewISupportsArray(getter_AddRefs(rules));
+  if (NS_FAILED(rv)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   for ( ; !ruleNode->IsRoot(); ruleNode = ruleNode->GetParent()) {
     RefPtr<Declaration> decl = do_QueryObject(ruleNode->GetRule());
     if (decl) {
       RefPtr<mozilla::css::StyleRule> styleRule =
         do_QueryObject(decl->GetOwningRule());
       if (styleRule) {
         nsCOMPtr<nsIDOMCSSRule> domRule = styleRule->GetDOMRule();
--- a/xpcom/ds/nsISupportsArray.idl
+++ b/xpcom/ds/nsISupportsArray.idl
@@ -76,12 +76,12 @@ interface nsISupportsArray : nsICollecti
 
   [notxpcom] boolean SizeTo(in long aSize);
   
 };
 
 %{C++
 
 // Construct and return a default implementation of nsISupportsArray:
-extern nsresult
+extern MOZ_MUST_USE nsresult
 NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult);
 
 %}
--- a/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
+++ b/xpcom/reflect/xptinfo/xptiInterfaceInfoManager.cpp
@@ -270,19 +270,20 @@ XPTInterfaceInfoManager::GetScriptableIn
         }
     }
 }
 
 NS_IMETHODIMP
 XPTInterfaceInfoManager::EnumerateInterfacesWhoseNamesStartWith(const char *prefix, nsIEnumerator **_retval)
 {
     nsCOMPtr<nsISupportsArray> array;
-    NS_NewISupportsArray(getter_AddRefs(array));
-    if (!array)
-        return NS_ERROR_UNEXPECTED;
+    nsresult rv = NS_NewISupportsArray(getter_AddRefs(array));
+    if (NS_FAILED(rv)) {
+        return rv;
+    }
 
     ReentrantMonitorAutoEnter monitor(mWorkingSet.mTableReentrantMonitor);
     uint32_t length = static_cast<uint32_t>(strlen(prefix));
     for (auto iter = mWorkingSet.mNameTable.Iter(); !iter.Done(); iter.Next()) {
         xptiInterfaceEntry* entry = iter.UserData();
         const char* name = entry->GetTheName();
         if (name != PL_strnstr(name, prefix, length)) {
             continue;