--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -13,27 +13,46 @@
* they would also miss them.
*/
const { Cu, CC, Cc, Ci } = require("chrome");
const promise = require("resource://gre/modules/Promise.jsm").Promise;
const jsmScope = require("resource://gre/modules/Services.jsm");
const { Services } = jsmScope;
// Steal various globals only available in JSM scope (and not Sandbox one)
-const { ChromeUtils, HeapSnapshot, XMLHttpRequest, console,
- atob, btoa, TextEncoder, TextDecoder } = Cu.getGlobalForObject(jsmScope);
+const {
+ atob,
+ btoa,
+ ChromeUtils,
+ console,
+ HeapSnapshot,
+ TextDecoder,
+ TextEncoder,
+ XMLHttpRequest,
+} = Cu.getGlobalForObject(jsmScope);
// Create a single Sandbox to access global properties needed in this module.
// Sandbox are memory expensive, so we should create as little as possible.
-const { CSS, CSSRule, FileReader, indexedDB, InspectorUtils, URL } =
- Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(), {
- wantGlobalProperties: [
- "CSS", "CSSRule", "FileReader", "indexedDB", "InspectorUtils", "URL",
- ]
- });
+const {
+ CSS,
+ CSSRule,
+ FileReader,
+ indexedDB,
+ InspectorUtils,
+ URL,
+} = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(), {
+ wantGlobalProperties: [
+ "CSS",
+ "CSSRule",
+ "FileReader",
+ "indexedDB",
+ "InspectorUtils",
+ "URL",
+ ]
+});
/**
* Defines a getter on a specified object that will be created upon first use.
*
* @param object
* The object to define the lazy getter on.
* @param name
* The name of the getter to define on object.
@@ -167,26 +186,26 @@ function lazyRequireGetter(obj, property
},
configurable: true,
enumerable: true
});
}
// List of pseudo modules exposed to all devtools modules.
exports.modules = {
- "Services": Object.create(Services),
+ ChromeUtils,
+ FileReader,
+ HeapSnapshot,
+ InspectorUtils,
promise,
// Expose "chrome" Promise, which aren't related to any document
// and so are never frozen, even if the browser loader module which
// pull it is destroyed. See bug 1402779.
Promise,
- ChromeUtils,
- HeapSnapshot,
- InspectorUtils,
- FileReader,
+ Services: Object.create(Services),
};
defineLazyGetter(exports.modules, "Debugger", () => {
// addDebuggerToGlobal only allows adding the Debugger object to a global. The
// this object is not guaranteed to be a global (in particular on B2G, due to
// compartment sharing), so add the Debugger object to a sandbox instead.
let sandbox = Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")());
Cu.evalInSandbox(
@@ -208,57 +227,54 @@ defineLazyGetter(exports.modules, "Timer
defineLazyGetter(exports.modules, "xpcInspector", () => {
return Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector);
});
// List of all custom globals exposed to devtools modules.
// Changes here should be mirrored to devtools/.eslintrc.
exports.globals = {
- isWorker: false,
- reportError: Cu.reportError,
- atob: atob,
- btoa: btoa,
- console: console,
- TextEncoder: TextEncoder,
- TextDecoder: TextDecoder,
- URL,
+ atob,
+ btoa,
+ console,
CSS,
CSSRule,
- loader: {
- lazyGetter: defineLazyGetter,
- lazyImporter: defineLazyModuleGetter,
- lazyServiceGetter: defineLazyServiceGetter,
- lazyRequireGetter: lazyRequireGetter,
- // Defined by Loader.jsm
- id: null
- },
-
- XMLHttpRequest: XMLHttpRequest,
-
- Node: Ci.nsIDOMNode,
- Element: Ci.nsIDOMElement,
- DocumentFragment: Ci.nsIDOMDocumentFragment,
-
// Make sure `define` function exists. This allows defining some modules
// in AMD format while retaining CommonJS compatibility through this hook.
// JSON Viewer needs modules in AMD format, as it currently uses RequireJS
// from a content document and can't access our usual loaders. So, any
// modules shared with the JSON Viewer should include a define wrapper:
//
// // Make this available to both AMD and CJS environments
// define(function(require, exports, module) {
// ... code ...
// });
//
// Bug 1248830 will work out a better plan here for our content module
// loading needs, especially as we head towards devtools.html.
define(factory) {
factory(this.require, this.exports, this.module);
},
+ DocumentFragment: Ci.nsIDOMDocumentFragment,
+ Element: Ci.nsIDOMElement,
+ isWorker: false,
+ loader: {
+ lazyGetter: defineLazyGetter,
+ lazyImporter: defineLazyModuleGetter,
+ lazyServiceGetter: defineLazyServiceGetter,
+ lazyRequireGetter: lazyRequireGetter,
+ // Defined by Loader.jsm
+ id: null
+ },
+ Node: Ci.nsIDOMNode,
+ reportError: Cu.reportError,
+ TextDecoder,
+ TextEncoder,
+ URL,
+ XMLHttpRequest,
};
// SDK loader copy globals property descriptors on each module global object
// so that we have to memoize them from here in order to instanciate each
// global only once.
// `globals` is a cache object on which we put all global values
// and we set getters on `exports.globals` returning `globals` values.
let globals = {};
function lazyGlobal(name, getter) {