Bug 788914 - Generate vanilla cross-compartment wrappers when UniversalXPConnect is enabled. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Fri, 07 Sep 2012 11:28:56 -0700
changeset 104589 b3dfdf56f0262c8e0789ce20723f33a6da302d6d
parent 104588 6d74382e1dad0d2b196a504bfaf1a386226e487d
child 104590 d4d0839c44afd9a59ba34a85b48e35c750d76ae7
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmrbkap
bugs788914
milestone18.0a1
Bug 788914 - Generate vanilla cross-compartment wrappers when UniversalXPConnect is enabled. r=mrbkap
js/xpconnect/src/xpcprivate.h
js/xpconnect/wrappers/WrapperFactory.cpp
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -4375,26 +4375,31 @@ GetCompartmentPrivate(JSObject *object)
 {
     MOZ_ASSERT(object);
     JSCompartment *compartment = js::GetObjectCompartment(object);
 
     MOZ_ASSERT(compartment);
     return GetCompartmentPrivate(compartment);
 }
 
+inline bool IsUniversalXPConnectEnabled(JSCompartment *compartment)
+{
+    CompartmentPrivate *priv =
+      static_cast<CompartmentPrivate*>(JS_GetCompartmentPrivate(compartment));
+    if (!priv)
+        return false;
+    return priv->universalXPConnectEnabled;
+}
+
 inline bool IsUniversalXPConnectEnabled(JSContext *cx)
 {
     JSCompartment *compartment = js::GetContextCompartment(cx);
     if (!compartment)
         return false;
-    CompartmentPrivate *priv =
-      static_cast<CompartmentPrivate*>(JS_GetCompartmentPrivate(compartment));
-    if (!priv)
-        return false;
-    return priv->universalXPConnectEnabled;
+    return IsUniversalXPConnectEnabled(compartment);
 }
 
 inline void EnableUniversalXPConnect(JSContext *cx)
 {
     JSCompartment *compartment = js::GetContextCompartment(cx);
     if (!compartment)
         return;
     CompartmentPrivate *priv =
--- a/js/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/xpconnect/wrappers/WrapperFactory.cpp
@@ -344,16 +344,18 @@ WrapperFactory::Rewrap(JSContext *cx, JS
                     typedef XrayWrapper<CrossCompartmentWrapper> Xray;
                     usingXray = true;
                     wrapper = &Xray::singleton;
                 } else {
                     wrapper = &CrossCompartmentWrapper::singleton;
                 }
             }
         }
+    } else if (xpc::IsUniversalXPConnectEnabled(target)) {
+        wrapper = &CrossCompartmentWrapper::singleton;
     } else if (AccessCheck::isChrome(origin)) {
         JSFunction *fun = JS_GetObjectFunction(obj);
         if (fun) {
             if (JS_IsBuiltinEvalFunction(fun) || JS_IsBuiltinFunctionConstructor(fun)) {
                 JS_ReportError(cx, "Not allowed to access chrome eval or Function from content");
                 return nullptr;
             }
         }