Bug 952840, part 1 - Eliminate goto in XPCWrappedNative::FindTearOff. r=bholley
authorAndrew McCreight <continuation@gmail.com>
Mon, 06 Jan 2014 17:32:24 -0800
changeset 162300 2cb3e4d522cc95356636dd9c5fa1ff66c74ab9c5
parent 162299 e21f81181a4165a49bf117c898f8d1850f7bb2e4
child 162301 64cfe4a6eafa2562623b6d793e75df6c3a24bfb9
push idunknown
push userunknown
push dateunknown
reviewersbholley
bugs952840
milestone29.0a1
Bug 952840, part 1 - Eliminate goto in XPCWrappedNative::FindTearOff. r=bholley
js/xpconnect/src/XPCWrappedNative.cpp
--- a/js/xpconnect/src/XPCWrappedNative.cpp
+++ b/js/xpconnect/src/XPCWrappedNative.cpp
@@ -1491,50 +1491,45 @@ XPCWrappedNative::FindTearOff(XPCNativeI
                     // We shouldn't ever be getting here _during_ our
                     // Mark/Sweep cycle, so this should be safe.
                     to->Unmark();
                     if (!ok) {
                         to = nullptr;
                         rv = NS_ERROR_OUT_OF_MEMORY;
                     }
                 }
-                goto return_result;
+                if (pError)
+                    *pError = rv;
+                return to;
             }
             if (!firstAvailable && to->IsAvailable())
                 firstAvailable = to;
         }
     }
 
     to = firstAvailable;
 
     if (!to) {
-        XPCWrappedNativeTearOffChunk* newChunk =
-            new XPCWrappedNativeTearOffChunk();
-        if (!newChunk) {
-            rv = NS_ERROR_OUT_OF_MEMORY;
-            goto return_result;
-        }
+        auto newChunk = new XPCWrappedNativeTearOffChunk();
         lastChunk->mNextChunk = newChunk;
         to = newChunk->mTearOffs;
     }
 
     {
-        // Scope keeps |tearoff| from leaking across the return_result: label
+        // Scope keeps |tearoff| from leaking across the rest of the function.
         AutoMarkingWrappedNativeTearOffPtr tearoff(cx, to);
         rv = InitTearOff(to, aInterface, needJSObject);
         // During shutdown, we don't sweep tearoffs.  So make sure to unmark
         // manually in case the auto-marker marked us.  We shouldn't ever be
         // getting here _during_ our Mark/Sweep cycle, so this should be safe.
         to->Unmark();
         if (NS_FAILED(rv))
             to = nullptr;
     }
 
-return_result:
-
     if (pError)
         *pError = rv;
     return to;
 }
 
 nsresult
 XPCWrappedNative::InitTearOff(XPCWrappedNativeTearOff* aTearOff,
                               XPCNativeInterface* aInterface,