// Like GetWrappedObject, but works on other types of wrappers, too. // See also js_GetWrappedObject in jsobj.h. // TODO Move to XPCWrapper? static inline JSObject * GetWrappedJSObject(JSContext *cx, JSObject *obj) { JSClass *clasp = STOBJ_GET_CLASS(obj); if (!(clasp->flags & JSCLASS_IS_EXTENDED)) { return obj; } JSExtendedClass *xclasp = (JSExtendedClass *)clasp; if (!xclasp->wrappedObject) { if (XPCNativeWrapper::IsNativeWrapper(obj)) { XPCWrappedNative *wn = XPCNativeWrapper::SafeGetWrappedNative(obj); return wn ? wn->GetFlatJSObject() : nsnull; } return obj; } return xclasp->wrappedObject(cx, obj); }
JSBool unwrapAnyObject(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { JSObject *wrapped; JSObject *wrappee = NULL; if (!JS_ConvertArguments(cx, argc, argv, "o", &wrapped)) return JS_FALSE; JSClass *klass = JS_GetClass(cx, wrapped); if (klass && (klass->flags & JSCLASS_IS_EXTENDED)) { JSExtendedClass *eClass = (JSExtendedClass *) klass; if (eClass->wrappedObject != NULL) wrappee = eClass->wrappedObject(cx, wrapped); } if (wrappee) *rval = OBJECT_TO_JSVAL(wrappee); else *rval = JSVAL_NULL; return JS_TRUE; }