Bug 952660, part 1 - Use smart pointer for clazz in nsXPCWrappedJS::GetNewOrUsed. r=bholley

The trickiest thing the goto in GetNewOrUsed does is release clazz in some cases,
so using a smart pointer will simplify things.
This commit is contained in:
Andrew McCreight 2014-01-02 11:33:41 -08:00
parent e21965c2c3
commit af3de44f9b

View File

@ -330,7 +330,7 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
JSObject2WrappedJSMap* map;
nsXPCWrappedJS* root = nullptr;
nsXPCWrappedJS* wrapper = nullptr;
nsXPCWrappedJSClass* clazz = nullptr;
nsRefPtr<nsXPCWrappedJSClass> clazz;
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
bool release_root = false;
@ -340,7 +340,7 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
return NS_ERROR_FAILURE;
}
nsXPCWrappedJSClass::GetNewOrUsed(cx, aIID, &clazz);
nsXPCWrappedJSClass::GetNewOrUsed(cx, aIID, getter_AddRefs(clazz));
if (!clazz)
return NS_ERROR_FAILURE;
// from here on we need to return through 'return_wrapper'
@ -404,9 +404,6 @@ nsXPCWrappedJS::GetNewOrUsed(JS::HandleObject jsObj,
root->mNext = wrapper;
return_wrapper:
if (clazz)
NS_RELEASE(clazz);
if (release_root)
NS_RELEASE(root);