--- a/devtools/shared/builtin-modules.js
+++ b/devtools/shared/builtin-modules.js
@@ -208,17 +208,17 @@ defineLazyGetter(exports.modules, "FileR
let sandbox
= Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
{wantGlobalProperties: ["FileReader"]});
return sandbox.FileReader;
});
// List of all custom globals exposed to devtools modules.
// Changes here should be mirrored to devtools/.eslintrc.
-const globals = exports.globals = {
+exports.globals = {
isWorker: false,
reportError: Cu.reportError,
atob: atob,
btoa: btoa,
URL,
loader: {
lazyGetter: defineLazyGetter,
lazyImporter: defineLazyModuleGetter,
@@ -249,40 +249,58 @@ const globals = exports.globals = {
// });
//
// 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);
},
};
+// 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) {
+ defineLazyGetter(globals, name, getter);
+ Object.defineProperty(exports.globals, name, {
+ get: function () {
+ return globals[name];
+ },
+ configurable: true,
+ enumerable: true
+ });
+}
// Lazily define a few things so that the corresponding jsms are only loaded
// when used.
-defineLazyGetter(globals, "console", () => {
+lazyGlobal("console", () => {
return Cu.import("resource://gre/modules/Console.jsm", {}).console;
});
-defineLazyGetter(globals, "clearTimeout", () => {
+lazyGlobal("clearTimeout", () => {
return Cu.import("resource://gre/modules/Timer.jsm", {}).clearTimeout;
});
-defineLazyGetter(globals, "setTimeout", () => {
+lazyGlobal("setTimeout", () => {
return Cu.import("resource://gre/modules/Timer.jsm", {}).setTimeout;
});
-defineLazyGetter(globals, "clearInterval", () => {
+lazyGlobal("clearInterval", () => {
return Cu.import("resource://gre/modules/Timer.jsm", {}).clearInterval;
});
-defineLazyGetter(globals, "setInterval", () => {
+lazyGlobal("setInterval", () => {
return Cu.import("resource://gre/modules/Timer.jsm", {}).setInterval;
});
-defineLazyGetter(globals, "CSSRule", () => Ci.nsIDOMCSSRule);
-defineLazyGetter(globals, "DOMParser", () => {
+lazyGlobal("CSSRule", () => Ci.nsIDOMCSSRule);
+lazyGlobal("DOMParser", () => {
return CC("@mozilla.org/xmlextras/domparser;1", "nsIDOMParser");
});
-defineLazyGetter(globals, "CSS", () => {
+lazyGlobal("CSS", () => {
let sandbox
= Cu.Sandbox(CC("@mozilla.org/systemprincipal;1", "nsIPrincipal")(),
{wantGlobalProperties: ["CSS"]});
return sandbox.CSS;
});
-defineLazyGetter(globals, "WebSocket", () => {
+lazyGlobal("WebSocket", () => {
return Services.appShell.hiddenDOMWindow.WebSocket;
});
-lazyRequireGetter(globals, "indexedDB", "sdk/indexed-db", true);
+lazyGlobal("indexedDB", () => {
+ return require("sdk/indexed-db").indexedDB;
+});