зеркало из https://github.com/mozilla/gecko-dev.git
Bug 774245 - Add WrapperFactory and XrayWrapper machinery to allow same-compartment Xray wrapping. r=mrbkap
This commit is contained in:
Родитель
1ce355561c
Коммит
77a1ce457f
|
@ -540,4 +540,40 @@ WrapperFactory::WrapComponentsObject(JSContext *cx, JSObject *obj)
|
|||
return wrapperObj;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
WrapperFactory::WrapForSameCompartmentXray(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
// We should be same-compartment here.
|
||||
MOZ_ASSERT(js::IsObjectInContextCompartment(obj, cx));
|
||||
|
||||
// Sort out what kind of Xray we can do. If we can't Xray, bail.
|
||||
XrayType type = GetXrayType(obj);
|
||||
if (type == NotXray)
|
||||
return NULL;
|
||||
|
||||
// Select the appropriate proxy handler.
|
||||
Wrapper *wrapper = NULL;
|
||||
if (type == XrayForWrappedNative)
|
||||
wrapper = &XrayWrapper<DirectWrapper>::singleton;
|
||||
else if (type == XrayForDOMProxyObject)
|
||||
wrapper = &XrayWrapper<DirectWrapper, ProxyXrayTraits>::singleton;
|
||||
else if (type == XrayForDOMObject)
|
||||
wrapper = &XrayWrapper<DirectWrapper, DOMXrayTraits>::singleton;
|
||||
else
|
||||
MOZ_NOT_REACHED("Bad Xray type");
|
||||
|
||||
// Make the Xray.
|
||||
JSObject *parent = JS_GetGlobalForObject(cx, obj);
|
||||
JSObject *wrapperObj = Wrapper::New(cx, obj, NULL, parent, wrapper);
|
||||
if (!wrapperObj)
|
||||
return NULL;
|
||||
|
||||
// Make the holder.
|
||||
JSObject *xrayHolder = XrayUtils::createHolder(cx, obj, parent);
|
||||
if (!xrayHolder)
|
||||
return nsnull;
|
||||
js::SetProxyExtra(wrapperObj, 0, js::ObjectValue(*xrayHolder));
|
||||
return wrapperObj;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -88,6 +88,9 @@ class WrapperFactory {
|
|||
|
||||
// Wrap a (same compartment) Components object.
|
||||
static JSObject *WrapComponentsObject(JSContext *cx, JSObject *obj);
|
||||
|
||||
// Wrap a same-compartment object for Xray inspection.
|
||||
static JSObject *WrapForSameCompartmentXray(JSContext *cx, JSObject *obj);
|
||||
};
|
||||
|
||||
extern js::DirectWrapper XrayWaiver;
|
||||
|
|
|
@ -1618,4 +1618,21 @@ template <> XRAY XRAY::singleton(0);
|
|||
template class XRAY;
|
||||
#undef XRAY
|
||||
|
||||
/* Same-compartment non-filtering versions. */
|
||||
|
||||
#define XRAY XrayWrapper<DirectWrapper, XPCWrappedNativeXrayTraits >
|
||||
template <> XRAY XRAY::singleton(0);
|
||||
template class XRAY;
|
||||
#undef XRAY
|
||||
|
||||
#define XRAY XrayWrapper<DirectWrapper, ProxyXrayTraits >
|
||||
template <> XRAY XRAY::singleton(0);
|
||||
template class XRAY;
|
||||
#undef XRAY
|
||||
|
||||
#define XRAY XrayWrapper<DirectWrapper, DOMXrayTraits >
|
||||
template <> XRAY XRAY::singleton(0);
|
||||
template class XRAY;
|
||||
#undef XRAY
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче