Bug 761695 - Hoist call and construct traps into Traits, since the current implementations are XPCWN-specific. r=peterv
authorBobby Holley <bobbyholley@gmail.com>
Fri, 05 Oct 2012 18:59:22 +0200
changeset 109393 f5225ec3579517e083d62a5ea6161368ee1d6bae
parent 109392 317a3211dfad1e17310c3a427892a354fde2b394
child 109394 03667c5bc77b2eea5e3faf521282ee0d30486716
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 call and construct traps into Traits, since the current implementations are XPCWN-specific. r=peterv
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -332,31 +332,46 @@ public:
 };
 
 class XrayTraits
 {
 public:
     static JSObject* getTargetObject(JSObject *wrapper) {
         return js::UnwrapObject(wrapper, /* stopAtOuter = */ false);
     }
+
+
+    static bool call(JSContext *cx, JSObject *wrapper, unsigned argc, Value *vp)
+    {
+        MOZ_NOT_REACHED("Call trap currently implemented only for XPCWNs");
+    }
+    static bool construct(JSContext *cx, JSObject *wrapper, unsigned argc,
+                          Value *argv, Value *rval)
+    {
+        MOZ_NOT_REACHED("Call trap currently implemented only for XPCWNs");
+    }
 };
 
 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,
                                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 bool call(JSContext *cx, JSObject *wrapper, unsigned argc, Value *vp);
+    static bool construct(JSContext *cx, JSObject *wrapper, unsigned argc,
+                          Value *argv, Value *rval);
+
     static JSObject* getHolderObject(JSContext *cx, JSObject *wrapper)
     {
         return getHolderObject(wrapper);
     }
 
     static bool isResolving(JSContext *cx, JSObject *holder, jsid id);
 
     static bool resolveDOMCollectionProperty(JSContext *cx, JSObject *wrapper, JSObject *holder,
@@ -1094,16 +1109,69 @@ XPCWrappedNativeXrayTraits::enumerateNam
             return false;
         if (hasProp)
             props.append(id);
     }
     return true;
 }
 
 bool
+XPCWrappedNativeXrayTraits::call(JSContext *cx, JSObject *wrapper,
+                                 unsigned argc, Value *vp)
+{
+    JSObject *holder = GetHolder(wrapper);
+    XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
+
+    // Run the resolve hook of the wrapped native.
+    if (NATIVE_HAS_FLAG(wn, WantCall)) {
+        XPCCallContext ccx(JS_CALLER, cx, wrapper, nullptr, JSID_VOID, argc,
+                           vp + 2, vp);
+        if (!ccx.IsValid())
+            return false;
+        bool ok = true;
+        nsresult rv = wn->GetScriptableInfo()->GetCallback()->Call(wn, cx, wrapper,
+                                                                   argc, vp + 2, vp, &ok);
+        if (NS_FAILED(rv)) {
+            if (ok)
+                XPCThrower::Throw(rv, cx);
+            return false;
+        }
+    }
+
+    return true;
+
+}
+
+bool
+XPCWrappedNativeXrayTraits::construct(JSContext *cx, JSObject *wrapper,
+                                      unsigned argc, Value *argv, Value *rval)
+{
+    JSObject *holder = GetHolder(wrapper);
+    XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
+
+    // Run the resolve hook of the wrapped native.
+    if (NATIVE_HAS_FLAG(wn, WantConstruct)) {
+        XPCCallContext ccx(JS_CALLER, cx, wrapper, nullptr, JSID_VOID, argc, argv, rval);
+        if (!ccx.IsValid())
+            return false;
+        bool ok = true;
+        nsresult rv = wn->GetScriptableInfo()->GetCallback()->Construct(wn, cx, wrapper,
+                                                                        argc, argv, rval, &ok);
+        if (NS_FAILED(rv)) {
+            if (ok)
+                XPCThrower::Throw(rv, cx);
+            return false;
+        }
+    }
+
+    return true;
+
+}
+
+bool
 ProxyXrayTraits::resolveNativeProperty(JSContext *cx, JSObject *wrapper, JSObject *holder,
                                        jsid id, bool set, JSPropertyDescriptor *desc)
 {
     JSObject *obj = getTargetObject(wrapper);
     return js::GetProxyHandler(obj)->getPropertyDescriptor(cx, wrapper, id, set, desc);
 }
 
 bool
@@ -1654,62 +1722,25 @@ XrayWrapper<Base, Traits>::iterate(JSCon
     // Skip our Base if it isn't already ProxyHandler.
     return BaseProxyHandler::iterate(cx, wrapper, flags, vp);
 }
 
 template <typename Base, typename Traits>
 bool
 XrayWrapper<Base, Traits>::call(JSContext *cx, JSObject *wrapper, unsigned argc, js::Value *vp)
 {
-    JSObject *holder = GetHolder(wrapper);
-    XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
-
-    // Run the resolve hook of the wrapped native.
-    if (NATIVE_HAS_FLAG(wn, WantCall)) {
-        XPCCallContext ccx(JS_CALLER, cx, wrapper, nullptr, JSID_VOID, argc,
-                           vp + 2, vp);
-        if (!ccx.IsValid())
-            return false;
-        bool ok = true;
-        nsresult rv = wn->GetScriptableInfo()->GetCallback()->Call(wn, cx, wrapper,
-                                                                   argc, vp + 2, vp, &ok);
-        if (NS_FAILED(rv)) {
-            if (ok)
-                XPCThrower::Throw(rv, cx);
-            return false;
-        }
-    }
-
-    return true;
+    return Traits::call(cx, wrapper, argc, vp);
 }
 
 template <typename Base, typename Traits>
 bool
 XrayWrapper<Base, Traits>::construct(JSContext *cx, JSObject *wrapper, unsigned argc,
                                      js::Value *argv, js::Value *rval)
 {
-    JSObject *holder = GetHolder(wrapper);
-    XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
-
-    // Run the resolve hook of the wrapped native.
-    if (NATIVE_HAS_FLAG(wn, WantConstruct)) {
-        XPCCallContext ccx(JS_CALLER, cx, wrapper, nullptr, JSID_VOID, argc, argv, rval);
-        if (!ccx.IsValid())
-            return false;
-        bool ok = true;
-        nsresult rv = wn->GetScriptableInfo()->GetCallback()->Construct(wn, cx, wrapper,
-                                                                        argc, argv, rval, &ok);
-        if (NS_FAILED(rv)) {
-            if (ok)
-                XPCThrower::Throw(rv, cx);
-            return false;
-        }
-    }
-
-    return true;
+    return Traits::construct(cx, wrapper, argc, argv, rval);
 }
 
 
 #define XRAY XrayWrapper<CrossCompartmentSecurityWrapper, XPCWrappedNativeXrayTraits >
 template <> XRAY XRAY::singleton(0);
 template class XRAY;
 #undef XRAY