From e880402830cbdefe3bff42b90ed10162071a4691 Mon Sep 17 00:00:00 2001 From: "mccabe%netscape.com" Date: Wed, 12 May 1999 02:05:48 +0000 Subject: [PATCH] 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. --- dom/tools/JSStubGen.cpp | 2 +- js/src/jsapi.h | 1 + js/src/xpconnect/src/xpcconvert.cpp | 30 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/dom/tools/JSStubGen.cpp b/dom/tools/JSStubGen.cpp index b3f140234368..3112398a10ed 100644 --- a/dom/tools/JSStubGen.cpp +++ b/dom/tools/JSStubGen.cpp @@ -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" diff --git a/js/src/jsapi.h b/js/src/jsapi.h index fad609a61008..54741b71d606 100644 --- a/js/src/jsapi.h +++ b/js/src/jsapi.h @@ -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. */ diff --git a/js/src/xpconnect/src/xpcconvert.cpp b/js/src/xpconnect/src/xpcconvert.cpp index be33562b8320..6c574d84ed69 100644 --- a/js/src/xpconnect/src/xpcconvert.cpp +++ b/js/src/xpconnect/src/xpcconvert.cpp @@ -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