mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 753518. Add an explicit way for GetParentObject to return an (nsISupports*,nsWrapperCache*) pair. r=peterv
This commit is contained in:
parent
7f2339b775
commit
414c2659a1
@ -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) :
|
||||
|
Loading…
Reference in New Issue
Block a user