Back out e6761635f9cf (bug 695292) for Android mochitest bustage on a CLOSED TREE
authorPhil Ringnalda <philringnalda@gmail.com>
Thu, 16 Aug 2012 21:35:53 -0700
changeset 105735 83c15a039a0940c4c072207e723e060215c374d8
parent 105734 57c7f49b37b3e996ed9f101eb6b136378570ebed
child 105736 b83bfbfa9b608bc8ee66a3b9a85fadd8ae0ee28d
push id1989
push userakeybl@mozilla.com
push dateTue, 28 Aug 2012 00:20:43 +0000
treeherdermozilla-aurora@a8e95ae10ea7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs695292
milestone17.0a1
backs oute6761635f9cfb220bbc7016d4972fd49b2d97257
Back out e6761635f9cf (bug 695292) for Android mochitest bustage on a CLOSED TREE
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
testing/mochitest/tests/SimpleTest/SimpleTest.js
testing/mochitest/tests/SimpleTest/specialpowersAPI.js
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -113,17 +113,17 @@ interface nsIXPCComponents_utils_Sandbox
 interface ScheduledGCCallback : nsISupports
 {
     void callback();
 };
 
 /**
 * interface of Components.utils
 */
-[scriptable, uuid(25442383-a1f5-440c-9e18-a2a1cdb8a638)]
+[scriptable, uuid(cc7ef3b0-339d-4317-927b-fdc8f0664927)]
 interface nsIXPCComponents_Utils : nsISupports
 {
 
     /* reportError is designed to be called from JavaScript only.
      *
      * It will report a JS Error object to the JS console, and return. It
      * is meant for use in exception handler blocks which want to "eat"
      * an exception, but still want to report it to the console.
@@ -325,24 +325,16 @@ interface nsIXPCComponents_Utils : nsISu
      * Forces a recomputation of all wrappers in and out of the compartment
      * containing |obj|. If |obj| is not an object, all wrappers system-wide
      * are recomputed.
      */
     [implicit_jscontext]
     void recomputeWrappers([optional] in jsval vobj);
 
     /*
-     * Dispatches a runnable to the current/main thread. If |scope| is passed,
-     * the runnable will be dispatch in the compartment of |scope|, which
-     * affects which error reporter gets called.
-     */
-    [implicit_jscontext]
-    void dispatch(in jsval runnable, [optional] in jsval scope);
-
-    /*
      * To be called from JS only.
      *
      * These are the set of JSContext options that privileged script
      * is allowed to control for the purposes of testing.  These
      * options should be kept in sync with what's controllable in the
      * jsshell and by setting prefs in nsJSEnvironment.
      *
      * NB: Assume that getting any of these attributes is relatively
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -4334,43 +4334,16 @@ nsXPCComponents_Utils::RecomputeWrappers
     // Otherwise, recompute wrappers for the given compartment.
     else
         js::RecomputeWrappers(cx, js::SingleCompartment(c), js::AllCompartments()) &&
         js::RecomputeWrappers(cx, js::AllCompartments(), js::SingleCompartment(c));
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXPCComponents_Utils::Dispatch(const jsval &runnable_, const jsval &scope,
-                                JSContext *cx)
-{
-    // Enter the given compartment, if any, and rewrap runnable.
-    JSAutoEnterCompartment ac;
-    js::Value runnable = runnable_;
-    if (scope.isObject()) {
-        JSObject *scopeObj = js::UnwrapObject(&scope.toObject());
-        if (!scopeObj || !ac.enter(cx, scopeObj) || !JS_WrapValue(cx, &runnable))
-            return NS_ERROR_FAILURE;
-    }
-
-    // Get an XPCWrappedJS for |runnable|.
-    if (!runnable.isObject())
-        return NS_ERROR_INVALID_ARG;
-    nsCOMPtr<nsIRunnable> run;
-    nsresult rv = nsXPConnect::GetXPConnect()->WrapJS(cx, &runnable.toObject(),
-                                                      NS_GET_IID(nsIRunnable),
-                                                      getter_AddRefs(run));
-    NS_ENSURE_SUCCESS(rv, rv);
-    MOZ_ASSERT(run);
-
-    // Dispatch.
-    return NS_DispatchToMainThread(run);
-}
-
 /* string canCreateWrapper (in nsIIDPtr iid); */
 NS_IMETHODIMP
 nsXPCComponents_Utils::CanCreateWrapper(const nsIID * iid, char **_retval)
 {
     // We let anyone do this...
     *_retval = xpc_CloneAllAccess();
     return NS_OK;
 }
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -647,18 +647,35 @@ SimpleTest.waitForClipboard = function(a
          }, aFailureFn, "text/unicode");
 }
 
 /**
  * Executes a function shortly after the call, but lets the caller continue
  * working (or finish).
  */
 SimpleTest.executeSoon = function(aFunc) {
-    if ("SpecialPowers" in window) {
-        return SpecialPowers.executeSoon(aFunc, window);
+    // Once SpecialPowers is available in chrome mochitests, we can replace the
+    // body of this function with a call to SpecialPowers.executeSoon().
+    if ("Components" in window && "classes" in window.Components) {
+        try {
+            netscape.security.PrivilegeManager
+              .enablePrivilege("UniversalXPConnect");
+            var tm = Components.classes["@mozilla.org/thread-manager;1"]
+                       .getService(Components.interfaces.nsIThreadManager);
+
+            tm.mainThread.dispatch({
+                run: function() {
+                    aFunc();
+                }
+            }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
+            return;
+        } catch (ex) {
+            // If the above fails (most likely because of enablePrivilege
+            // failing), fall through to the setTimeout path.
+        }
     }
     setTimeout(aFunc, 0);
 }
 
 /**
  * Finishes the tests. This is automatically called, except when
  * SimpleTest.waitForExplicitFinish() has been invoked.
 **/
--- a/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
+++ b/testing/mochitest/tests/SimpleTest/specialpowersAPI.js
@@ -877,26 +877,23 @@ SpecialPowersAPI.prototype = {
     var xulRuntime = Cc["@mozilla.org/xre/app-info;1"]
                         .getService(Components.interfaces.nsIXULAppInfo)
                         .QueryInterface(Components.interfaces.nsIXULRuntime);
 
     this._xpcomabi = xulRuntime.XPCOMABI;
     return this._xpcomabi;
   },
 
-  // The optional aWin parameter allows the caller to specify a given window in
-  // whose scope the runnable should be dispatched. If aFun throws, the
-  // exception will be reported to aWin.
-  executeSoon: function(aFun, aWin) {
-    // Create the runnable in the scope of aWin to avoid running into COWs.
-    var runnable = {};
-    if (aWin)
-        runnable = Cu.createObjectIn(aWin);
-    runnable.run = aFun;
-    Cu.dispatch(runnable, aWin);
+  executeSoon: function(aFunc) {
+    var tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
+    tm.mainThread.dispatch({
+      run: function() {
+        aFunc();
+      }
+    }, Ci.nsIThread.DISPATCH_NORMAL);
   },
 
   _os: null,
 
   get OS() {
     if (this._os != null)
       return this._os;