Added nsJSUtils::nsConvertJSValtoXPCObject to handle 'in xpidl' parameters.

git-svn-id: svn://10.0.0.236/trunk@29380 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
waterson%netscape.com
1999-04-27 04:17:17 +00:00
parent 6babea46d6
commit e1308f27fe
2 changed files with 41 additions and 0 deletions

View File

@@ -219,6 +219,42 @@ nsJSUtils::nsConvertJSValToObject(nsISupports** aSupports,
return JS_TRUE;
}
NS_EXPORT PRBool
nsJSUtils::nsConvertJSValToXPCObject(nsISupports** aSupports,
REFNSIID aIID,
JSContext* aContext,
jsval aValue)
{
*aSupports = nsnull;
if (JSVAL_IS_NULL(aValue)) {
return JS_TRUE;
}
else if (JSVAL_IS_OBJECT(aValue)) {
nsresult rv;
NS_WITH_SERVICE(nsIXPConnect, xpc, kXPConnectCID, &rv);
if (NS_FAILED(rv)) return JS_FALSE;
nsIXPConnectWrappedNative* wrapper;
rv = xpc->GetWrappedNativeOfJSObject(aContext, JSVAL_TO_OBJECT(aValue), &wrapper);
if (NS_FAILED(rv)) return JS_FALSE;
nsISupports* native;
rv = wrapper->GetNative(&native);
NS_RELEASE(wrapper);
if (NS_FAILED(rv)) return JS_FALSE;
rv = native->QueryInterface(aIID, (void**) aSupports);
NS_RELEASE(native);
if (NS_FAILED(rv)) return JS_FALSE;
return JS_TRUE;
}
else {
return JS_FALSE;
}
}
NS_EXPORT void
nsJSUtils::nsConvertJSValToString(nsString& aString,
JSContext* aContext,

View File

@@ -68,6 +68,11 @@ public:
JSContext* aContext,
jsval aValue);
static NS_EXPORT PRBool nsConvertJSValToXPCObject(nsISupports** aSupports,
REFNSIID aIID,
JSContext* aContext,
jsval aValue);
static NS_EXPORT void nsConvertJSValToString(nsString& aString,
JSContext* aContext,
jsval aValue);