Bug 952840, part 1 - Eliminate goto in XPCWrappedNative::FindTearOff. r=bholley
--- 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,