Bug 761695 - Hoist getInnerObject into XrayTraits. r=peterv
authorBobby Holley <bobbyholley@gmail.com>
Fri, 05 Oct 2012 18:59:22 +0200
changeset 109391 9af31b39e3f794fb0481559cca258992cb90720f
parent 109390 8d62ef879869f54b2c7c5ee6155a64924a41619f
child 109392 317a3211dfad1e17310c3a427892a354fde2b394
push id16008
push userbobbyholley@gmail.com
push dateFri, 05 Oct 2012 16:59:43 +0000
treeherdermozilla-inbound@3b4562fd4f20 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs761695
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 761695 - Hoist getInnerObject into XrayTraits. r=peterv The only special handling here with wrapped natives is to make sure that we bypass outer windows. But we can do this with js::UnwrapObject.
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -328,16 +328,20 @@ class ResolvingIdDummy
 public:
     ResolvingIdDummy(JSObject *wrapper, jsid id)
     {
     }
 };
 
 class XrayTraits
 {
+public:
+    static JSObject* getInnerObject(JSObject *wrapper) {
+        return js::UnwrapObject(wrapper, /* stopAtOuter = */ false);
+    }
 };
 
 class XPCWrappedNativeXrayTraits : public XrayTraits
 {
 public:
     static bool resolveNativeProperty(JSContext *cx, JSObject *wrapper, JSObject *holder, jsid id,
                                       bool set, JSPropertyDescriptor *desc);
     static bool resolveOwnProperty(JSContext *cx, js::Wrapper &jsWrapper, JSObject *wrapper,
@@ -347,17 +351,16 @@ public:
                                JSPropertyDescriptor *desc);
     static bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
     static bool enumerateNames(JSContext *cx, JSObject *wrapper, unsigned flags,
                                JS::AutoIdVector &props);
     static JSObject* getHolderObject(JSContext *cx, JSObject *wrapper)
     {
         return getHolderObject(wrapper);
     }
-    static JSObject* getInnerObject(JSObject *wrapper);
 
     static bool isResolving(JSContext *cx, JSObject *holder, jsid id);
 
     static bool resolveDOMCollectionProperty(JSContext *cx, JSObject *wrapper, JSObject *holder,
                                              jsid id, bool set, PropertyDescriptor *desc);
 
     typedef ResolvingId ResolvingIdImpl;
 
@@ -382,20 +385,16 @@ public:
                                JSPropertyDescriptor *desc);
     static bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
     static bool enumerateNames(JSContext *cx, JSObject *wrapper, unsigned flags,
                                JS::AutoIdVector &props);
     static JSObject* getHolderObject(JSContext *cx, JSObject *wrapper)
     {
         return getHolderObject(cx, wrapper, true);
     }
-    static JSObject* getInnerObject(JSObject *wrapper)
-    {
-        return &js::GetProxyPrivate(wrapper).toObject();
-    }
 
     static bool isResolving(JSContext *cx, JSObject *holder, jsid id)
     {
         return false;
     }
 
     typedef ResolvingIdDummy ResolvingIdImpl;
 
@@ -428,20 +427,16 @@ public:
                                JSPropertyDescriptor *desc);
     static bool delete_(JSContext *cx, JSObject *wrapper, jsid id, bool *bp);
     static bool enumerateNames(JSContext *cx, JSObject *wrapper, unsigned flags,
                                JS::AutoIdVector &props);
     static JSObject* getHolderObject(JSContext *cx, JSObject *wrapper)
     {
         return getHolderObject(cx, wrapper, true);
     }
-    static JSObject* getInnerObject(JSObject *wrapper)
-    {
-        return &js::GetProxyPrivate(wrapper).toObject();
-    }
 
     static bool isResolving(JSContext *cx, JSObject *holder, jsid id)
     {
         return false;
     }
 
     typedef ResolvingIdDummy ResolvingIdImpl;
 
@@ -479,17 +474,17 @@ GetWrappedNative(JSObject *obj)
     return static_cast<XPCWrappedNative *>(js::GetObjectPrivate(obj));
 }
 
 static XPCWrappedNative *
 GetWrappedNativeFromHolder(JSObject *holder)
 {
     MOZ_ASSERT(js::GetObjectJSClass(holder) == &HolderClass);
     JSObject *wrapper = &js::GetReservedSlot(holder, JSSLOT_WRAPPER).toObject();
-    return GetWrappedNative(js::UnwrapObject(wrapper, /* stopAtOuter = */ false));
+    return GetWrappedNative(XrayTraits::getInnerObject(wrapper));
 }
 
 static JSObject *
 GetWrappedNativeObjectFromHolder(JSObject *holder)
 {
     return GetWrappedNativeFromHolder(holder)->GetFlatJSObject();
 }
 
@@ -507,22 +502,16 @@ FindWrapper(JSContext *cx, JSObject *wra
                 return nullptr;
         }
         // NB: we must eventually hit our wrapper.
     }
 
     return wrapper;
 }
 
-JSObject*
-XPCWrappedNativeXrayTraits::getInnerObject(JSObject *wrapper)
-{
-    return GetWrappedNativeObjectFromHolder(getHolderObject(wrapper));
-}
-
 bool
 XPCWrappedNativeXrayTraits::isResolving(JSContext *cx, JSObject *holder,
                                         jsid id)
 {
     return ResolvingId::getResolvingId(holder)->isResolving(id);
 }
 
 // Some DOM objects have shared properties that don't have an explicit