Bug 761695 - Make Xray traits inherit from a common superclass and give them a singleton instance. r=peterv
authorBobby Holley <bobbyholley@gmail.com>
Fri, 05 Oct 2012 18:59:22 +0200
changeset 109390 8d62ef879869f54b2c7c5ee6155a64924a41619f
parent 109389 cf00f8f3f80dc41c497ce3d5715365784aa6c132
child 109391 9af31b39e3f794fb0481559cca258992cb90720f
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 - Make Xray traits inherit from a common superclass and give them a singleton instance. r=peterv There's some code that can be shared between different Xray traits, but can't (yet) be hoisted into XrayWrapper, because it needs to be callable from outside XrayWrapper where we don't have the appropriate template parameters. Moreover, this code benefits from virtual function specialization. The use case here is illuminated in the next patch. For the moment, we skip converting the bulk of the traits calls to virtual methods, because they're working just fine.
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -326,17 +326,21 @@ ResolvingId::getResolvingIdFromWrapper(J
 class ResolvingIdDummy
 {
 public:
     ResolvingIdDummy(JSObject *wrapper, jsid id)
     {
     }
 };
 
-class XPCWrappedNativeXrayTraits
+class XrayTraits
+{
+};
+
+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,
                                    JSObject *holder, jsid id, bool set,
                                    JSPropertyDescriptor *desc);
     static bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
@@ -352,24 +356,26 @@ public:
 
     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;
 
+    static XPCWrappedNativeXrayTraits singleton;
+
 private:
     static JSObject* getHolderObject(JSObject *wrapper)
     {
         return &js::GetProxyExtra(wrapper, 0).toObject();
     }
 };
 
-class ProxyXrayTraits
+class ProxyXrayTraits : 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,
                                    JSObject *holder, jsid id, bool set,
                                    JSPropertyDescriptor *desc);
     static bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
@@ -388,32 +394,34 @@ public:
 
     static bool isResolving(JSContext *cx, JSObject *holder, jsid id)
     {
         return false;
     }
 
     typedef ResolvingIdDummy ResolvingIdImpl;
 
+    static ProxyXrayTraits singleton;
+
 private:
     static JSObject* getHolderObject(JSContext *cx, JSObject *wrapper,
                                      bool createHolder)
     {
         if (!js::GetProxyExtra(wrapper, 0).isUndefined())
             return &js::GetProxyExtra(wrapper, 0).toObject();
 
         if (!createHolder)
             return nullptr;
 
         return createHolderObject(cx, wrapper);
     }
     static JSObject* createHolderObject(JSContext *cx, JSObject *wrapper);
 };
 
-class DOMXrayTraits
+class DOMXrayTraits : 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,
                                    JSObject *holder, jsid id, bool set,
                                    JSPropertyDescriptor *desc);
     static bool defineProperty(JSContext *cx, JSObject *wrapper, jsid id,
@@ -432,31 +440,37 @@ public:
 
     static bool isResolving(JSContext *cx, JSObject *holder, jsid id)
     {
         return false;
     }
 
     typedef ResolvingIdDummy ResolvingIdImpl;
 
+    static DOMXrayTraits singleton;
+
 private:
     static JSObject* getHolderObject(JSContext *cx, JSObject *wrapper,
                                      bool createHolder)
     {
         if (!js::GetProxyExtra(wrapper, 0).isUndefined())
             return &js::GetProxyExtra(wrapper, 0).toObject();
 
         if (!createHolder)
             return nullptr;
 
         return createHolderObject(cx, wrapper);
     }
     static JSObject* createHolderObject(JSContext *cx, JSObject *wrapper);
 };
 
+XPCWrappedNativeXrayTraits XPCWrappedNativeXrayTraits::singleton;
+ProxyXrayTraits ProxyXrayTraits::singleton;
+DOMXrayTraits DOMXrayTraits::singleton;
+
 static JSObject *
 GetHolder(JSObject *obj)
 {
     return &js::GetProxyExtra(obj, 0).toObject();
 }
 
 static XPCWrappedNative *
 GetWrappedNative(JSObject *obj)