Bug 1019191 part 23. Eliminate the ppArgRef argument of xpc_qsUnwrapArgImpl and UnwrapArg, since we're now always handing out a ref in ppArg. r=peterv

This commit is contained in:
Boris Zbarsky 2014-10-22 11:40:51 -04:00
parent a688f3fefc
commit 0929eae5cc
5 changed files with 22 additions and 48 deletions

View File

@ -827,10 +827,8 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
// Switch this to UnwrapDOMObjectToISupports once our global objects are
// using new bindings.
nsISupports* native = nullptr;
nsCOMPtr<nsISupports> nativeRef;
UnwrapArg<nsISupports>(cx, obj, &native,
static_cast<nsISupports**>(getter_AddRefs(nativeRef)));
nsCOMPtr<nsISupports> native;
UnwrapArg<nsISupports>(cx, obj, getter_AddRefs(native));
if (!native) {
return Throw(cx, NS_ERROR_FAILURE);
}
@ -843,10 +841,9 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
}
nsIJSID* iid;
SelfRef iidRef;
nsCOMPtr<nsIJSID> iid;
obj = &args[0].toObject();
if (NS_FAILED(UnwrapArg<nsIJSID>(cx, obj, &iid, &iidRef.ptr))) {
if (NS_FAILED(UnwrapArg<nsIJSID>(cx, obj, getter_AddRefs(iid)))) {
return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
}
MOZ_ASSERT(iid);

View File

@ -40,8 +40,8 @@ class nsIJSID;
class nsPIDOMWindow;
extern nsresult
xpc_qsUnwrapArgImpl(JSContext* cx, JS::Handle<JSObject*> src, const nsIID& iid, void** ppArg,
nsISupports** ppArgRef);
xpc_qsUnwrapArgImpl(JSContext* cx, JS::Handle<JSObject*> src, const nsIID& iid,
void** ppArg);
namespace mozilla {
namespace dom {
@ -57,16 +57,12 @@ struct SelfRef
};
/** Convert a jsval to an XPCOM pointer. */
template <class Interface, class StrongRefType>
template <class Interface>
inline nsresult
UnwrapArg(JSContext* cx, JS::Handle<JSObject*> src, Interface** ppArg,
StrongRefType** ppArgRef)
UnwrapArg(JSContext* cx, JS::Handle<JSObject*> src, Interface** ppArg)
{
nsISupports* argRef = *ppArgRef;
nsresult rv = xpc_qsUnwrapArgImpl(cx, src, NS_GET_TEMPLATE_IID(Interface),
reinterpret_cast<void**>(ppArg), &argRef);
*ppArgRef = static_cast<StrongRefType*>(argRef);
return rv;
return xpc_qsUnwrapArgImpl(cx, src, NS_GET_TEMPLATE_IID(Interface),
reinterpret_cast<void**>(ppArg));
}
inline const ErrNum

View File

@ -3677,7 +3677,7 @@ class CastableObjectUnwrapper():
// want to be in that compartment for the UnwrapArg call.
JS::Rooted<JSObject*> source(cx, ${source});
JSAutoCompartment ac(cx, ${source});
rv = UnwrapArg<${type}>(cx, source, &objPtr, &objRef.ptr);
rv = UnwrapArg<${type}>(cx, source, getter_AddRefs(objPtr));
}
""")
else:
@ -3685,19 +3685,16 @@ class CastableObjectUnwrapper():
self.substitution["source"] = source
xpconnectUnwrap = (
"JS::Rooted<JSObject*> source(cx, ${source});\n"
"nsresult rv = UnwrapArg<${type}>(cx, source, &objPtr, &objRef.ptr);\n")
"nsresult rv = UnwrapArg<${type}>(cx, source, getter_AddRefs(objPtr));\n")
if descriptor.hasXPConnectImpls:
self.substitution["codeOnFailure"] = string.Template(
"${type} *objPtr;\n"
"SelfRef objRef;\n" +
"nsRefPtr<${type}> objPtr;\n" +
xpconnectUnwrap +
"if (NS_FAILED(rv)) {\n"
"${indentedCodeOnFailure}"
"}\n"
"// We should be castable!\n"
"MOZ_ASSERT(!objRef.ptr);\n"
"// We should have an object, too!\n"
"// We should have an object\n"
"MOZ_ASSERT(objPtr);\n"
"${target} = objPtr;\n"
).substitute(self.substitution,
@ -4766,21 +4763,14 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
holderType = "nsRefPtr<" + typeName + ">"
templateBody += (
"JS::Rooted<JSObject*> source(cx, &${val}.toObject());\n" +
typePtr + " tmp;\n"
"if (NS_FAILED(UnwrapArg<" + typeName + ">(cx, source, &tmp, static_cast<" + typeName + "**>(getter_AddRefs(${holderName}))))) {\n")
"if (NS_FAILED(UnwrapArg<" + typeName + ">(cx, source, getter_AddRefs(${holderName})))) {\n")
templateBody += CGIndenter(onFailureBadType(failureCode,
descriptor.interface.identifier.name)).define()
templateBody += ("}\n"
"MOZ_ASSERT(tmp);\n")
"MOZ_ASSERT(${holderName});\n")
if not isDefinitelyObject and not forceOwningType:
templateBody += dedent("""
// UnwrapArg never sets **ppArg without also setting *ppArgRef
MOZ_ASSERT(${holderName});
""")
# And store our tmp, before it goes out of scope.
templateBody += "${declName} = tmp;\n"
# And store our value in ${declName}
templateBody += "${declName} = ${holderName};\n"
# Just pass failureCode, not onFailureBadType, here, so we'll report the
# thing as not an object as opposed to not implementing whatever our

View File

@ -23,31 +23,26 @@ nsresult
xpc_qsUnwrapArgImpl(JSContext *cx,
HandleObject src,
const nsIID &iid,
void **ppArg,
nsISupports **ppArgRef)
void **ppArg)
{
nsISupports *iface = xpc::UnwrapReflectorToISupports(src);
if (iface) {
if (NS_FAILED(iface->QueryInterface(iid, ppArg))) {
*ppArgRef = nullptr;
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
*ppArgRef = static_cast<nsISupports*>(*ppArg);
return NS_OK;
}
// Create the ccx needed for quick stubs.
XPCCallContext ccx(JS_CALLER, cx);
if (!ccx.IsValid()) {
*ppArgRef = nullptr;
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
nsRefPtr<nsXPCWrappedJS> wrappedJS;
nsresult rv = nsXPCWrappedJS::GetNewOrUsed(src, iid, getter_AddRefs(wrappedJS));
if (NS_FAILED(rv) || !wrappedJS) {
*ppArgRef = nullptr;
return rv;
}
@ -55,11 +50,7 @@ xpc_qsUnwrapArgImpl(JSContext *cx,
// the right thing for the various 'special' interfaces; e.g.
// nsIPropertyBag. We must use AggregatedQueryInterface in cases where
// there is an outer to avoid nasty recursion.
rv = wrappedJS->QueryInterface(iid, ppArg);
if (NS_SUCCEEDED(rv)) {
*ppArgRef = static_cast<nsISupports*>(*ppArg);
}
return rv;
return wrappedJS->QueryInterface(iid, ppArg);
}
namespace xpc {

View File

@ -12,7 +12,7 @@
/* XPCQuickStubs.h - Support functions used only by Web IDL bindings, for now. */
nsresult
xpc_qsUnwrapArgImpl(JSContext *cx, JS::HandleObject src, const nsIID &iid, void **ppArg,
nsISupports **ppArgRef);
xpc_qsUnwrapArgImpl(JSContext *cx, JS::HandleObject src, const nsIID &iid,
void **ppArg);
#endif /* xpcquickstubs_h___ */