test_executeSoon.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Client request stacks should span the entire process from before making the
  6. * request to handling the reply from the server. The server frames are not
  7. * included, nor can they be in most cases, since the server can be a remote
  8. * device.
  9. */
  10. var { executeSoon } = require("devtools/shared/DevToolsUtils");
  11. var promise = require("promise");
  12. var defer = require("devtools/shared/defer");
  13. var Services = require("Services");
  14. var asyncStackEnabled =
  15. Services.prefs.getBoolPref("javascript.options.asyncstack");
  16. do_register_cleanup(() => {
  17. Services.prefs.setBoolPref("javascript.options.asyncstack",
  18. asyncStackEnabled);
  19. });
  20. add_task(function* () {
  21. Services.prefs.setBoolPref("javascript.options.asyncstack", true);
  22. yield waitForTick();
  23. let stack = Components.stack;
  24. while (stack) {
  25. do_print(stack.name);
  26. if (stack.name == "waitForTick") {
  27. // Reached back to outer function before executeSoon
  28. ok(true, "Complete stack");
  29. return;
  30. }
  31. stack = stack.asyncCaller || stack.caller;
  32. }
  33. ok(false, "Incomplete stack");
  34. });
  35. function waitForTick() {
  36. let deferred = defer();
  37. executeSoon(deferred.resolve);
  38. return deferred.promise;
  39. }