Support for magically detecting whether an argument to an XPConnect'ed function is a dom node with a native nsISupports, and unwrapping it properly.

This'll go live as soon as I can persuade joki or vidur to rebuild the DOM stubs.
This commit is contained in:
mccabe%netscape.com 1999-05-12 02:05:48 +00:00
Родитель b7cd7d8010
Коммит e880402830
3 изменённых файлов: 32 добавлений и 1 удалений

Просмотреть файл

@ -1210,7 +1210,7 @@ static const char *kJSClassStr =
"//\n"
"JSClass %sClass = {\n"
" \"%s\", \n"
" JSCLASS_HAS_PRIVATE,\n"
" JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS,\n"
" JS_PropertyStub,\n"
" JS_PropertyStub,\n"
" Get%sProperty,\n"

Просмотреть файл

@ -389,6 +389,7 @@ struct JSClass {
#define JSCLASS_HAS_PRIVATE 0x01 /* class instances have private slot */
#define JSCLASS_NEW_ENUMERATE 0x02 /* class has JSNewEnumerateOp method */
#define JSCLASS_NEW_RESOLVE 0x04 /* class has JSNewResolveOp method */
#define JSCLASS_PRIVATE_IS_NSISUPPORTS 0x08 /* private slot is nsISupports* */
struct JSObjectOps {
/* Mandatory non-null function pointer members. */

Просмотреть файл

@ -286,6 +286,26 @@ XPCConvert::NativeData2JS(JSContext* cx, jsval* d, const void* s,
return JS_TRUE;
}
static JSBool
GetISupportsFromJSObject(JSContext* cx, JSObject* obj, nsISupports** iface)
{
JSClass* jsclass =
#ifdef JS_THREADSAFE
JS_GetClass(cx, obj);
#else
JS_GetClass(obj);
#endif
NS_ASSERTION(jsclass, "obj has no class");
if(jsclass &&
(jsclass->flags & JSCLASS_HAS_PRIVATE) &&
(jsclass->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS))
{
*iface = (nsISupports*) JS_GetPrivate(cx, obj);
return JS_TRUE;
}
return JS_FALSE;
}
/***************************************************************************/
// static
JSBool
@ -523,6 +543,16 @@ XPCConvert::JSData2Native(JSContext* cx, void* d, jsval s,
else
iface->QueryInterface(*iid, (void**)&iface);
}
else if(GetISupportsFromJSObject(cx, obj, &iface))
{
if(iface)
iface->QueryInterface(*iid, (void**)&iface);
else
{
*((nsISupports**)d) = NULL;
return JS_TRUE;
}
}
else
{
// lets try to build a wrapper around the JSObject