added nsGetNativeThis(), which searches the prototype chain for the first object that is tagged as having an nsISupports in its private field.

This commit is contained in:
beard%netscape.com 1999-05-14 20:27:00 +00:00
Родитель 5faa1390e3
Коммит 9b8efc19a5
2 изменённых файлов: 21 добавлений и 0 удалений

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

@ -439,3 +439,21 @@ nsJSUtils::nsGenericResolve(JSContext* aContext,
return JS_TRUE;
}
/**
* due to some prototype chain hackery, we may have to walk the prototype chain
* until we find an object that has an nsISupports in its private field.
*/
NS_EXPORT nsISupports*
nsJSUtils::nsGetNativeThis(JSContext* aContext, JSObject* aObj)
{
while (aObj != nsnull) {
JSClass* js_class = JS_GetClass(aContext, aObj);
if (js_class != nsnull &&
(js_class->flags & JSCLASS_HAS_PRIVATE) &&
(js_class->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS))
return (nsISupports*) JS_GetPrivate(aContext, aObj);
aObj = JS_GetPrototype(aContext, aObj);
}
return nsnull;
}

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

@ -99,6 +99,9 @@ public:
static NS_EXPORT JSBool nsGenericResolve(JSContext* aContext,
JSObject* aObj,
jsval aId);
static NS_EXPORT nsISupports* nsGetNativeThis(JSContext* aContext,
JSObject* aObj);
};
#endif /* nsJSUtils_h__ */