addon-sdk/source/lib/sdk/system/globals.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/lib/sdk/system/globals.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +module.metadata = {
    1.11 +  "stability": "unstable"
    1.12 +};
    1.13 +
    1.14 +let { Cc, Ci, CC } = require('chrome');
    1.15 +let { PlainTextConsole } = require('../console/plain-text');
    1.16 +let { stdout } = require('../system');
    1.17 +let ScriptError = CC('@mozilla.org/scripterror;1', 'nsIScriptError');
    1.18 +let consoleService = Cc['@mozilla.org/consoleservice;1'].getService().
    1.19 +                     QueryInterface(Ci.nsIConsoleService);
    1.20 +
    1.21 +// On windows dump does not writes into stdout so cfx can't read thous dumps.
    1.22 +// To workaround this issue we write to a special file from which cfx will
    1.23 +// read and print to the console.
    1.24 +// For more details see: bug-673383
    1.25 +exports.dump = stdout.write;
    1.26 +
    1.27 +exports.console = new PlainTextConsole();
    1.28 +
    1.29 +// Provide CommonJS `define` to allow authoring modules in a format that can be
    1.30 +// loaded both into jetpack and into browser via AMD loaders.
    1.31 +Object.defineProperty(exports, 'define', {
    1.32 +  // `define` is provided as a lazy getter that binds below defined `define`
    1.33 +  // function to the module scope, so that require, exports and module
    1.34 +  // variables remain accessible.
    1.35 +  configurable: true,
    1.36 +  get: function() {
    1.37 +    let sandbox = this;
    1.38 +    return function define(factory) {
    1.39 +      factory = Array.slice(arguments).pop();
    1.40 +      factory.call(sandbox, sandbox.require, sandbox.exports, sandbox.module);
    1.41 +    }
    1.42 +  }
    1.43 +});

mercurial