From 074f97cf4c81003a281f68bcf83dc059b0e6d295 Mon Sep 17 00:00:00 2001 From: Andrew McCreight Date: Mon, 3 Aug 2015 11:47:00 -0400 Subject: [PATCH] Bug 1190436 - Part 1: Use more smart pointers in XPConnect. r=gabor --- js/xpconnect/src/XPCComponents.cpp | 11 +++-------- js/xpconnect/src/XPCConvert.cpp | 10 ++++------ js/xpconnect/src/XPCWrappedJSClass.cpp | 5 ++--- js/xpconnect/src/nsXPConnect.cpp | 23 ++++++++++------------- 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index c91a73101fb2..dd65e72bd225 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -58,20 +58,15 @@ JSValIsInterfaceOfType(JSContext* cx, HandleValue v, REFNSIID iid) nsCOMPtr wn; nsCOMPtr sup; - nsISupports* iface; + nsCOMPtr iface; if (v.isPrimitive()) return false; nsXPConnect* xpc = nsXPConnect::XPConnect(); RootedObject obj(cx, &v.toObject()); - if (NS_SUCCEEDED(xpc->GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wn))) && wn && - NS_SUCCEEDED(wn->Native()->QueryInterface(iid, (void**)&iface)) && iface) - { - NS_RELEASE(iface); - return true; - } - return false; + return NS_SUCCEEDED(xpc->GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wn))) && wn && + NS_SUCCEEDED(wn->Native()->QueryInterface(iid, getter_AddRefs(iface))) && iface; } char* diff --git a/js/xpconnect/src/XPCConvert.cpp b/js/xpconnect/src/XPCConvert.cpp index f960b13d1349..1ad1159bc858 100644 --- a/js/xpconnect/src/XPCConvert.cpp +++ b/js/xpconnect/src/XPCConvert.cpp @@ -932,8 +932,8 @@ XPCConvert::JSObject2NativeInterface(void** dest, HandleObject src, // else... - nsXPCWrappedJS* wrapper; - nsresult rv = nsXPCWrappedJS::GetNewOrUsed(src, *iid, &wrapper); + nsRefPtr wrapper; + nsresult rv = nsXPCWrappedJS::GetNewOrUsed(src, *iid, getter_AddRefs(wrapper)); if (pErr) *pErr = rv; if (NS_SUCCEEDED(rv) && wrapper) { @@ -951,7 +951,6 @@ XPCConvert::JSObject2NativeInterface(void** dest, HandleObject src, wrapper->QueryInterface(*iid, dest); if (pErr) *pErr = rv; - NS_RELEASE(wrapper); return NS_SUCCEEDED(rv); } @@ -1160,18 +1159,17 @@ XPCConvert::JSValToXPCException(MutableHandleValue s, else { // XXX all this nsISupportsDouble code seems a little redundant // now that we're storing the Value in the exception... - nsISupportsDouble* data; + nsCOMPtr data; nsCOMPtr cm; if (NS_FAILED(NS_GetComponentManager(getter_AddRefs(cm))) || !cm || NS_FAILED(cm->CreateInstanceByContractID(NS_SUPPORTS_DOUBLE_CONTRACTID, nullptr, NS_GET_IID(nsISupportsDouble), - (void**)&data))) + getter_AddRefs(data)))) return NS_ERROR_FAILURE; data->SetData(number); rv = ConstructException(NS_ERROR_XPC_JS_THREW_NUMBER, nullptr, ifaceName, methodName, data, exceptn, cx, s.address()); - NS_RELEASE(data); return rv; } } diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index 572a0e7e33f7..100ed38856d5 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -568,14 +568,13 @@ nsXPCWrappedJSClass::DelegatedQueryInterface(nsXPCWrappedJS* self, // Instead, simply do the nsXPCWrappedJS part of // XPConvert::JSObject2NativeInterface() here to make sure we // get a new (or used) nsXPCWrappedJS. - nsXPCWrappedJS* wrapper; - nsresult rv = nsXPCWrappedJS::GetNewOrUsed(jsobj, aIID, &wrapper); + nsRefPtr wrapper; + nsresult rv = nsXPCWrappedJS::GetNewOrUsed(jsobj, aIID, getter_AddRefs(wrapper)); if (NS_SUCCEEDED(rv) && wrapper) { // We need to go through the QueryInterface logic to make // this return the right thing for the various 'special' // interfaces; e.g. nsIPropertyBag. rv = wrapper->QueryInterface(aIID, aInstancePtr); - NS_RELEASE(wrapper); return rv; } } diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 26ae533daa69..42ea26904dcc 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -860,33 +860,30 @@ nsXPConnect::DebugDumpObject(nsISupports* p, int16_t depth) return NS_OK; } - nsIXPConnect* xpc; - nsIXPCWrappedJSClass* wjsc; - nsIXPConnectWrappedNative* wn; - nsIXPConnectWrappedJS* wjs; + nsCOMPtr xpc; + nsCOMPtr wjsc; + nsCOMPtr wn; + nsCOMPtr wjs; if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnect), - (void**)&xpc))) { + getter_AddRefs(xpc)))) { XPC_LOG_ALWAYS(("Dumping a nsIXPConnect...")); xpc->DebugDump(depth); - NS_RELEASE(xpc); } else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPCWrappedJSClass), - (void**)&wjsc))) { + getter_AddRefs(wjsc)))) { XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedJSClass...")); wjsc->DebugDump(depth); - NS_RELEASE(wjsc); } else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedNative), - (void**)&wn))) { + getter_AddRefs(wn)))) { XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedNative...")); wn->DebugDump(depth); - NS_RELEASE(wn); } else if (NS_SUCCEEDED(p->QueryInterface(NS_GET_IID(nsIXPConnectWrappedJS), - (void**)&wjs))) { + getter_AddRefs(wjs)))) { XPC_LOG_ALWAYS(("Dumping a nsIXPConnectWrappedJS...")); wjs->DebugDump(depth); - NS_RELEASE(wjs); - } else + } else { XPC_LOG_ALWAYS(("*** Could not dump the nsISupports @ %x", p)); + } #endif return NS_OK; }