bug 580128 - Fix getting doubled wrapped objects in XPConnect. r=mrbkap
authorJohnny Stenback <jst@mozilla.org>
Sun, 10 Oct 2010 15:42:04 -0700
changeset 55662 b50c20e24ebe27aa496c72a79f39fbc97db18418
parent 55661 53c20ebc3c52e451d0b2c95b4559567747d7eb03
child 55663 0dab28765beb072901783324b0bf772a4a4b4c8d
push idunknown
push userunknown
push dateunknown
reviewersmrbkap
bugs580128
milestone2.0b8pre
bug 580128 - Fix getting doubled wrapped objects in XPConnect. r=mrbkap
js/src/xpconnect/loader/mozJSComponentLoader.cpp
js/src/xpconnect/src/xpcwrappednativejsops.cpp
--- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp
@@ -1358,19 +1358,30 @@ mozJSComponentLoader::Import(const nsACS
         if (!targetObject) {
             NS_ERROR("null calling object");
             return NS_ERROR_FAILURE;
         }
 
         targetObject = JS_GetGlobalForObject(cx, targetObject);
     }
  
+    JSAutoEnterCompartment ac;
+    if (!ac.enter(cx, targetObject)) {
+        NS_ERROR("can't enter compartment");
+        return NS_ERROR_FAILURE;
+    }
+
     JSObject *globalObj = nsnull;
     rv = ImportInto(registryLocation, targetObject, cc, &globalObj);
 
+    if (!JS_WrapObject(cx, &globalObj)) {
+        NS_ERROR("can't wrap return value");
+        return NS_ERROR_FAILURE;
+    }
+
     jsval *retval = nsnull;
     cc->GetRetValPtr(&retval);
     if (retval)
         *retval = OBJECT_TO_JSVAL(globalObj);
 
     return rv;
 }
 
--- a/js/src/xpconnect/src/xpcwrappednativejsops.cpp
+++ b/js/src/xpconnect/src/xpcwrappednativejsops.cpp
@@ -181,16 +181,20 @@ GetDoubleWrappedJSObject(XPCCallContext&
     if(underware)
     {
         JSObject* mainObj = nsnull;
         if(NS_SUCCEEDED(underware->GetJSObject(&mainObj)) && mainObj)
         {
             jsid id = ccx.GetRuntime()->
                     GetStringID(XPCJSRuntime::IDX_WRAPPED_JSOBJECT);
 
+            JSAutoEnterCompartment ac;
+            if(!ac.enter(ccx, mainObj))
+                return NULL;
+
             jsval val;
             if(JS_GetPropertyById(ccx, mainObj, id, &val) &&
                !JSVAL_IS_PRIMITIVE(val))
             {
                 obj = JSVAL_TO_OBJECT(val);
             }
         }
     }
@@ -253,17 +257,17 @@ XPC_WN_DoubleWrappedGetter(JSContext *cx
                               wrapper->GetSecurityInfoAddr())))
             {
                 // The SecurityManager should have set an exception.
                 return JS_FALSE;
             }
         }
     }
     *vp = OBJECT_TO_JSVAL(realObject);
-    return JS_TRUE;
+    return JS_WrapValue(cx, vp);
 }
 
 /***************************************************************************/
 
 // This is our shared function to define properties on our JSObjects.
 
 /*
  * NOTE: