Bug 1190436 - Part 1: Use more smart pointers in XPConnect. r=gabor

This commit is contained in:
Andrew McCreight 2015-08-03 11:47:00 -04:00
parent f2d723c01e
commit 074f97cf4c
4 changed files with 19 additions and 30 deletions

View File

@ -58,20 +58,15 @@ JSValIsInterfaceOfType(JSContext* cx, HandleValue v, REFNSIID iid)
nsCOMPtr<nsIXPConnectWrappedNative> wn; nsCOMPtr<nsIXPConnectWrappedNative> wn;
nsCOMPtr<nsISupports> sup; nsCOMPtr<nsISupports> sup;
nsISupports* iface; nsCOMPtr<nsISupports> iface;
if (v.isPrimitive()) if (v.isPrimitive())
return false; return false;
nsXPConnect* xpc = nsXPConnect::XPConnect(); nsXPConnect* xpc = nsXPConnect::XPConnect();
RootedObject obj(cx, &v.toObject()); RootedObject obj(cx, &v.toObject());
if (NS_SUCCEEDED(xpc->GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wn))) && wn && return NS_SUCCEEDED(xpc->GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wn))) && wn &&
NS_SUCCEEDED(wn->Native()->QueryInterface(iid, (void**)&iface)) && iface) NS_SUCCEEDED(wn->Native()->QueryInterface(iid, getter_AddRefs(iface))) && iface;
{
NS_RELEASE(iface);
return true;
}
return false;
} }
char* char*

View File

@ -932,8 +932,8 @@ XPCConvert::JSObject2NativeInterface(void** dest, HandleObject src,
// else... // else...
nsXPCWrappedJS* wrapper; nsRefPtr<nsXPCWrappedJS> wrapper;
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(src, *iid, &wrapper); nsresult rv = nsXPCWrappedJS::GetNewOrUsed(src, *iid, getter_AddRefs(wrapper));
if (pErr) if (pErr)
*pErr = rv; *pErr = rv;
if (NS_SUCCEEDED(rv) && wrapper) { if (NS_SUCCEEDED(rv) && wrapper) {
@ -951,7 +951,6 @@ XPCConvert::JSObject2NativeInterface(void** dest, HandleObject src,
wrapper->QueryInterface(*iid, dest); wrapper->QueryInterface(*iid, dest);
if (pErr) if (pErr)
*pErr = rv; *pErr = rv;
NS_RELEASE(wrapper);
return NS_SUCCEEDED(rv); return NS_SUCCEEDED(rv);
} }
@ -1160,18 +1159,17 @@ XPCConvert::JSValToXPCException(MutableHandleValue s,
else { else {
// XXX all this nsISupportsDouble code seems a little redundant // XXX all this nsISupportsDouble code seems a little redundant
// now that we're storing the Value in the exception... // now that we're storing the Value in the exception...
nsISupportsDouble* data; nsCOMPtr<nsISupportsDouble> data;
nsCOMPtr<nsIComponentManager> cm; nsCOMPtr<nsIComponentManager> cm;
if (NS_FAILED(NS_GetComponentManager(getter_AddRefs(cm))) || !cm || if (NS_FAILED(NS_GetComponentManager(getter_AddRefs(cm))) || !cm ||
NS_FAILED(cm->CreateInstanceByContractID(NS_SUPPORTS_DOUBLE_CONTRACTID, NS_FAILED(cm->CreateInstanceByContractID(NS_SUPPORTS_DOUBLE_CONTRACTID,
nullptr, nullptr,
NS_GET_IID(nsISupportsDouble), NS_GET_IID(nsISupportsDouble),
(void**)&data))) getter_AddRefs(data))))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
data->SetData(number); data->SetData(number);
rv = ConstructException(NS_ERROR_XPC_JS_THREW_NUMBER, nullptr, rv = ConstructException(NS_ERROR_XPC_JS_THREW_NUMBER, nullptr,
ifaceName, methodName, data, exceptn, cx, s.address()); ifaceName, methodName, data, exceptn, cx, s.address());
NS_RELEASE(data);
return rv; return rv;
} }
} }

View File

@ -568,14 +568,13 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self,
// Instead, simply do the nsXPCWrappedJS part of // Instead, simply do the nsXPCWrappedJS part of
// XPConvert::JSObject2NativeInterface() here to make sure we // XPConvert::JSObject2NativeInterface() here to make sure we
// get a new (or used) nsXPCWrappedJS. // get a new (or used) nsXPCWrappedJS.
nsXPCWrappedJS* wrapper; nsRefPtr<nsXPCWrappedJS> wrapper;
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(jsobj, aIID, &wrapper); nsresult rv = nsXPCWrappedJS::GetNewOrUsed(jsobj, aIID, getter_AddRefs(wrapper));
if (NS_SUCCEEDED(rv) && wrapper) { if (NS_SUCCEEDED(rv) && wrapper) {
// We need to go through the QueryInterface logic to make // We need to go through the QueryInterface logic to make
// this return the right thing for the various 'special' // this return the right thing for the various 'special'
// interfaces; e.g. nsIPropertyBag. // interfaces; e.g. nsIPropertyBag.
rv = wrapper->QueryInterface(aIID, aInstancePtr); rv = wrapper->QueryInterface(aIID, aInstancePtr);
NS_RELEASE(wrapper);
return rv; return rv;
} }
} }

View File

@ -860,33 +860,30 @@ nsXPConnect::DebugDumpObject(nsISupports* p, int16_t depth)
return NS_OK; return NS_OK;
} }
nsIXPConnect* xpc; nsCOMPtr<nsIXPConnect> xpc;
nsIXPCWrappedJSClass* wjsc; nsCOMPtr<nsIXPCWrappedJSClass> wjsc;
nsIXPConnectWrappedNative* wn; nsCOMPtr<nsIXPConnectWrappedNative> wn;
nsIXPConnectWrappedJS* wjs; nsCOMPtr<nsIXPConnectWrappedJS> wjs;
if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnect), if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnect),
(void**)&xpc))) { getter_AddRefs(xpc)))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPConnect...")); XPC_LOG_ALWAYS(("Dumping a nsIXPConnect..."));
xpc->DebugDump(depth); xpc->DebugDump(depth);
NS_RELEASE(xpc);
} else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPCWrappedJSClass), } else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPCWrappedJSClass),
(void**)&wjsc))) { getter_AddRefs(wjsc)))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedJSClass...")); XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedJSClass..."));
wjsc->DebugDump(depth); wjsc->DebugDump(depth);
NS_RELEASE(wjsc);
} else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedNative), } else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedNative),
(void**)&wn))) { getter_AddRefs(wn)))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedNative...")); XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedNative..."));
wn->DebugDump(depth); wn->DebugDump(depth);
NS_RELEASE(wn);
} else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedJS), } else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedJS),
(void**)&wjs))) { getter_AddRefs(wjs)))) {
XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedJS...")); XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedJS..."));
wjs->DebugDump(depth); wjs->DebugDump(depth);
NS_RELEASE(wjs); } else {
} else
XPC_LOG_ALWAYS(("*** Could not dump the nsISupports @ %x", p)); XPC_LOG_ALWAYS(("*** Could not dump the nsISupports @ %x", p));
}
#endif #endif
return NS_OK; return NS_OK;
} }