Bug 859372 - Refactor DevToolsUtils.js;r=past
authorEddy Bruel <ejpbruel@mozilla.com
Thu, 10 Apr 2014 20:44:54 +0200
changeset 178035 5c505089af347bb51fb5bb1dcc433985a0182eca
parent 178034 a9dbe97ba4049bcefc9fd56b07327437a41870ed
child 178036 d41e6e32df811fa2e5dbd62fc65d961241b12f90
push id42151
push userryanvm@gmail.com
push dateFri, 11 Apr 2014 02:15:47 +0000
treeherdermozilla-inbound@783c5013dbec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs859372
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 859372 - Refactor DevToolsUtils.js;r=past
toolkit/devtools/DevToolsUtils.js
toolkit/devtools/Loader.jsm
--- a/toolkit/devtools/DevToolsUtils.js
+++ b/toolkit/devtools/DevToolsUtils.js
@@ -1,19 +1,23 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 /* General utilities used throughout devtools. */
-const { Ci, Cu } = require("chrome");
 
-let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
-let { setTimeout, clearTimeout } = Cu.import("resource://gre/modules/Timer.jsm", {});
+// hasChrome is provided as a global by the loader. It is true if we are running
+// on the main thread, and false if we are running on a worker thread.
+if (hasChrome) {
+  var { Ci, Cu } = require("chrome");
+  var Services = require("Services");
+  var setTimeout = Cu.import("resource://gre/modules/Timer.jsm", {}).setTimeout;
+}
 
 /**
  * Turn the error |aError| into a string, without fail.
  */
 exports.safeErrorString = function safeErrorString(aError) {
   try {
     let errorString = aError.toString();
     if (typeof errorString == "string") {
--- a/toolkit/devtools/Loader.jsm
+++ b/toolkit/devtools/Loader.jsm
@@ -29,16 +29,17 @@ this.EXPORTED_SYMBOLS = ["DevToolsLoader
 
 /**
  * Providers are different strategies for loading the devtools.
  */
 
 let loaderGlobals = {
   btoa: btoa,
   console: console,
+  hasChrome: true,
   promise: promise,
   _Iterator: Iterator,
   ChromeWorker: ChromeWorker,
   loader: {
     lazyGetter: XPCOMUtils.defineLazyGetter.bind(XPCOMUtils),
     lazyImporter: XPCOMUtils.defineLazyModuleGetter.bind(XPCOMUtils),
     lazyServiceGetter: XPCOMUtils.defineLazyServiceGetter.bind(XPCOMUtils)
   }