Bug 753518. Add an explicit way for GetParentObject to return an (nsISupports*,nsWrapperCache*) pair. r=peterv

This commit is contained in:
Boris Zbarsky 2012-05-10 15:24:59 -04:00
Родитель da473c61df
Коммит bf718df018
1 изменённых файлов: 46 добавлений и 5 удалений

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

@ -418,6 +418,47 @@ GetWrapperCache(void* p)
return NULL;
}
struct ParentObject {
template<class T>
ParentObject(T* aObject) :
mObject(aObject),
mWrapperCache(GetWrapperCache(aObject))
{}
template<class T, template<class> class SmartPtr>
ParentObject(const SmartPtr<T>& aObject) :
mObject(aObject.get()),
mWrapperCache(GetWrapperCache(aObject.get()))
{}
ParentObject(nsISupports* aObject, nsWrapperCache* aCache) :
mObject(aObject),
mWrapperCache(aCache)
{}
nsISupports* const mObject;
nsWrapperCache* const mWrapperCache;
};
inline nsWrapperCache*
GetWrapperCache(const ParentObject& aParentObject)
{
return aParentObject.mWrapperCache;
}
template<class T>
inline nsISupports*
GetParentPointer(T* aObject)
{
return aObject;
}
inline nsISupports*
GetParentPointer(const ParentObject& aObject)
{
return aObject.mObject;
}
// Only set allowNativeWrapper to false if you really know you need it, if in
// doubt use true. Setting it to false disables security wrappers.
bool
@ -488,18 +529,18 @@ WrapObject<JSObject>(JSContext* cx, JSObject* scope, JSObject* p, JS::Value* vp)
return true;
}
template<class T>
template<typename T>
static inline JSObject*
WrapNativeParent(JSContext* cx, JSObject* scope, T* p)
WrapNativeParent(JSContext* cx, JSObject* scope, const T& p)
{
if (!p)
if (!GetParentPointer(p))
return scope;
nsWrapperCache* cache = GetWrapperCache(p);
JSObject* obj;
if (cache && (obj = cache->GetWrapper())) {
#ifdef DEBUG
qsObjectHelper helper(p, cache);
qsObjectHelper helper(GetParentPointer(p), cache);
JS::Value debugVal;
bool ok = XPCOMObjectToJsval(cx, scope, helper, NULL, false, &debugVal);
@ -509,7 +550,7 @@ WrapNativeParent(JSContext* cx, JSObject* scope, T* p)
return obj;
}
qsObjectHelper helper(p, cache);
qsObjectHelper helper(GetParentPointer(p), cache);
JS::Value v;
return XPCOMObjectToJsval(cx, scope, helper, NULL, false, &v) ?
JSVAL_TO_OBJECT(v) :