globals.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. module.metadata = {
  6. "stability": "unstable"
  7. };
  8. let { Cc, Ci, CC } = require('chrome');
  9. let { PlainTextConsole } = require('../console/plain-text');
  10. let { stdout } = require('../system');
  11. let ScriptError = CC('@mozilla.org/scripterror;1', 'nsIScriptError');
  12. let consoleService = Cc['@mozilla.org/consoleservice;1'].getService().
  13. QueryInterface(Ci.nsIConsoleService);
  14. // On windows dump does not writes into stdout so cfx can't read thous dumps.
  15. // To workaround this issue we write to a special file from which cfx will
  16. // read and print to the console.
  17. // For more details see: bug-673383
  18. exports.dump = stdout.write;
  19. exports.console = new PlainTextConsole();
  20. // Provide CommonJS `define` to allow authoring modules in a format that can be
  21. // loaded both into jetpack and into browser via AMD loaders.
  22. Object.defineProperty(exports, 'define', {
  23. // `define` is provided as a lazy getter that binds below defined `define`
  24. // function to the module scope, so that require, exports and module
  25. // variables remain accessible.
  26. configurable: true,
  27. get: function() {
  28. let sandbox = this;
  29. return function define(factory) {
  30. factory = Array.slice(arguments).pop();
  31. factory.call(sandbox, sandbox.require, sandbox.exports, sandbox.module);
  32. }
  33. }
  34. });