From a9121164a8e82f48f1373f4fc5bf0d564dab9fda Mon Sep 17 00:00:00 2001 From: "mrbkap%gmail.com" Date: Sat, 21 Jul 2007 01:03:55 +0000 Subject: [PATCH] Don't double-wrap objects when getting them out of an XPCVariant. bug 384632, r=peterv sr=jst git-svn-id: svn://10.0.0.236/trunk@230407 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/src/xpconnect/src/xpcvariant.cpp | 36 ++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/mozilla/js/src/xpconnect/src/xpcvariant.cpp b/mozilla/js/src/xpconnect/src/xpcvariant.cpp index 69455c2ee3a..7749f474ee6 100644 --- a/mozilla/js/src/xpconnect/src/xpcvariant.cpp +++ b/mozilla/js/src/xpconnect/src/xpcvariant.cpp @@ -634,10 +634,38 @@ VARIANT_DONE: } else { - success = XPCConvert::NativeData2JS(ccx, pJSVal, - (const void*)&xpctvar.val, - xpctvar.type, - &iid, scope, pErr); + // Last ditch check to prevent us from double-wrapping a regular JS + // object. This allows us to unwrap regular JS objects (since we + // normally can't double wrap them). See bug 384632. + *pJSVal = JSVAL_VOID; + if(type == nsIDataType::VTYPE_INTERFACE || + type == nsIDataType::VTYPE_INTERFACE_IS) + { + nsISupports *src = NS_REINTERPRET_CAST(nsISupports *, xpctvar.val.p); + if(nsXPCWrappedJSClass::IsWrappedJS(src)) + { + // First QI the wrapper to the right interface. + nsCOMPtr wrapper; + nsresult rv = src->QueryInterface(iid, getter_AddRefs(wrapper)); + NS_ENSURE_SUCCESS(rv, JS_FALSE); + + // Now, get the actual JS object out of the wrapper. + nsCOMPtr holder = + do_QueryInterface(wrapper); + NS_ENSURE_TRUE(holder, JS_FALSE); + + JSObject *obj; + holder->GetJSObject(&obj); + *pJSVal = OBJECT_TO_JSVAL(obj); + } + } + if(!JSVAL_IS_OBJECT(*pJSVal)) + { + success = XPCConvert::NativeData2JS(ccx, pJSVal, + (const void*)&xpctvar.val, + xpctvar.type, + &iid, scope, pErr); + } } if(xpctvar.IsValAllocated())