Bug 1240494 - AMD support for DevTools loaders. r=jwalker,Honza

MozReview-Commit-ID: 7IemsaijHNc
This commit is contained in:
J. Ryan Stinnett 2016-02-16 19:50:12 -06:00
parent 714d7bcaa9
commit ebf98a48dd
2 changed files with 32 additions and 5 deletions

View File

@ -110,11 +110,22 @@ function BrowserLoader(baseURI, window) {
// Allow modules to use the window's console to ensure logs appear in a
// tab toolbox, if one exists, instead of just the browser console.
console: window.console,
// Make sure 'define' function exists. This allows reusing AMD modules.
define: function(callback) {
callback(this.require, this.exports, this.module);
return this.exports;
}
// 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);
},
}
};

View File

@ -394,6 +394,22 @@ DevToolsLoader.prototype = {
id: this.id,
main: this.main
},
// 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);
},
};
// Lazy define console in order to load Console.jsm only when it is used
XPCOMUtils.defineLazyGetter(this._provider.globals, "console", () => {