Bug 1151413 - Set async caller in DevToolsUtils.executeSoon r=ejpbruel draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Fri, 18 Dec 2015 14:53:25 -0600
changeset 316426 8869a2dba7d8154df602f2685c022cb44e679383
parent 316017 a9eaed26451a0381ed8a599597aa1c8629a2f3d1
child 512165 0db2cb75d0f94daed3a3fdf32a649d4e789577d2
push id8552
push userjryans@gmail.com
push dateFri, 18 Dec 2015 20:53:57 +0000
reviewersejpbruel
bugs1151413
milestone46.0a1
Bug 1151413 - Set async caller in DevToolsUtils.executeSoon r=ejpbruel
devtools/shared/DevToolsUtils.js
devtools/shared/tests/unit/test_executeSoon.js
devtools/shared/tests/unit/xpcshell.ini
--- a/devtools/shared/DevToolsUtils.js
+++ b/devtools/shared/DevToolsUtils.js
@@ -178,18 +178,22 @@ exports.compose = function compose(...fu
 
 /**
  * Waits for the next tick in the event loop to execute a callback.
  */
 exports.executeSoon = function executeSoon(aFn) {
   if (isWorker) {
     setImmediate(aFn);
   } else {
+    let stack = components.stack;
+    let executor = () => {
+      Cu.callFunctionWithAsyncStack(aFn, stack, "DevToolsUtils.executeSoon");
+    };
     Services.tm.mainThread.dispatch({
-      run: exports.makeInfallible(aFn)
+      run: exports.makeInfallible(executor)
     }, Ci.nsIThread.DISPATCH_NORMAL);
   }
 };
 
 /**
  * Waits for the next tick in the event loop.
  *
  * @return Promise
new file mode 100644
--- /dev/null
+++ b/devtools/shared/tests/unit/test_executeSoon.js
@@ -0,0 +1,47 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Client request stacks should span the entire process from before making the
+ * request to handling the reply from the server.  The server frames are not
+ * included, nor can they be in most cases, since the server can be a remote
+ * device.
+ */
+
+var { executeSoon } = require("devtools/shared/DevToolsUtils");
+var promise = require("promise");
+var Services = require("Services");
+
+var asyncStackEnabled =
+  Services.prefs.getBoolPref("javascript.options.asyncstack");
+
+do_register_cleanup(() => {
+  Services.prefs.setBoolPref("javascript.options.asyncstack",
+                             asyncStackEnabled);
+});
+
+add_task(function*() {
+  Services.prefs.setBoolPref("javascript.options.asyncstack", true);
+
+  yield waitForTick();
+
+  let stack = Components.stack;
+  while (stack) {
+    do_print(stack.name);
+    if (stack.name == "waitForTick") {
+      // Reached back to outer function before executeSoon
+      ok(true, "Complete stack");
+      return;
+    }
+    stack = stack.asyncCaller || stack.caller;
+  }
+  ok(false, "Incomplete stack");
+});
+
+function waitForTick() {
+  let deferred = promise.defer();
+  executeSoon(deferred.resolve);
+  return deferred.promise;
+}
--- a/devtools/shared/tests/unit/xpcshell.ini
+++ b/devtools/shared/tests/unit/xpcshell.ini
@@ -19,8 +19,9 @@ support-files =
 [test_defineLazyPrototypeGetter.js]
 [test_async-utils.js]
 [test_consoleID.js]
 [test_cssColor.js]
 [test_prettifyCSS.js]
 [test_require_lazy.js]
 [test_require.js]
 [test_stack.js]
+[test_executeSoon.js]