Bug 761695 - Hoist Xray identification machinery into XrayWrapper, and use it for trait identification. r=peterv

We don't currently have a good way of selecting the traits used by a given Xray
wrapper. This lets us do that.

Note: We add a call to js::UnwrapObject to GetXrayType while hoisting it. When
it was used only in WrapperFactory, this was unnecessary, because |obj| was
always unwrapped. But for our new purposes, it might not be. Aside from that,
there are no changes to the function.
This commit is contained in:
Bobby Holley 2012-10-05 18:59:23 +02:00
Родитель 79702a4c27
Коммит 9b34e0d88e
3 изменённых файлов: 46 добавлений и 25 удалений

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

@ -292,31 +292,6 @@ GetWrappedNative(JSContext *cx, JSObject *obj)
: nullptr;
}
enum XrayType {
XrayForDOMObject,
XrayForDOMProxyObject,
XrayForWrappedNative,
NotXray
};
static XrayType
GetXrayType(JSObject *obj)
{
if (mozilla::dom::IsDOMObject(obj))
return XrayForDOMObject;
if (mozilla::dom::oldproxybindings::instanceIsProxy(obj))
return XrayForDOMProxyObject;
js::Class* clasp = js::GetObjectClass(obj);
if (IS_WRAPPER_CLASS(clasp) || clasp->ext.innerObject) {
NS_ASSERTION(clasp->ext.innerObject || IS_WN_WRAPPER_OBJECT(obj),
"We forgot to Morph a slim wrapper!");
return XrayForWrappedNative;
}
return NotXray;
}
JSObject *
WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSObject *parent,
unsigned flags)

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

@ -44,6 +44,25 @@ JSClass HolderClass = {
using namespace XrayUtils;
XrayType
GetXrayType(JSObject *obj)
{
obj = js::UnwrapObject(obj, /* stopAtOuter = */ false);
if (mozilla::dom::IsDOMObject(obj))
return XrayForDOMObject;
if (mozilla::dom::oldproxybindings::instanceIsProxy(obj))
return XrayForDOMProxyObject;
js::Class* clasp = js::GetObjectClass(obj);
if (IS_WRAPPER_CLASS(clasp) || clasp->ext.innerObject) {
NS_ASSERTION(clasp->ext.innerObject || IS_WN_WRAPPER_OBJECT(obj),
"We forgot to Morph a slim wrapper!");
return XrayForWrappedNative;
}
return NotXray;
}
ResolvingId::ResolvingId(JSObject *wrapper, jsid id)
: mId(id),
mHolder(getHolderObject(wrapper)),
@ -219,6 +238,21 @@ XPCWrappedNativeXrayTraits XPCWrappedNativeXrayTraits::singleton;
ProxyXrayTraits ProxyXrayTraits::singleton;
DOMXrayTraits DOMXrayTraits::singleton;
XrayTraits*
GetXrayTraits(JSObject *obj)
{
switch (GetXrayType(obj)) {
case XrayForDOMObject:
return &DOMXrayTraits::singleton;
case XrayForDOMProxyObject:
return &ProxyXrayTraits::singleton;
case XrayForWrappedNative:
return &XPCWrappedNativeXrayTraits::singleton;
default:
return nullptr;
}
}
/*
* Xray expando handling.
*

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

@ -38,10 +38,22 @@ GetNativePropertiesObject(JSContext *cx, JSObject *wrapper);
}
class XrayTraits;
class XPCWrappedNativeXrayTraits;
class ProxyXrayTraits;
class DOMXrayTraits;
enum XrayType {
XrayForDOMObject,
XrayForDOMProxyObject,
XrayForWrappedNative,
NotXray
};
XrayType GetXrayType(JSObject *obj);
XrayTraits* GetXrayTraits(JSObject *obj);
// NB: Base *must* derive from JSProxyHandler
template <typename Base, typename Traits = XPCWrappedNativeXrayTraits >
class XrayWrapper : public Base {