<commit_before>/*
 * Extends require.js (by <NAME>) to support loading modules into Firefox extensions
 *
 * Copyright 2011 <NAME> for IBM Corp.
 * This code is released under Firebug's BSD license.
 *
 * Key ideas from securable-modules.js by <NAME> <<EMAIL>>,
 * with enhancements by <NAME> and <NAME> released under BSD license
 * https://bugzilla.mozilla.org/show_bug.cgi?id=614239 accessed on Jan. 8, 2011
 *
 * API influenced by: http://wiki.ecmascript.org/doku.php?id=strawman:module_loaders accessed on Jan. 8, 2011
 */

// allow this file to be loaded via resource url
// eg Components.utils.import("resource://hellomodule/ModuleLoader.js");
var EXPORTED_SYMBOLS = ["ModuleLoader"];

var Ci = Components.interfaces;
var Cc = Components.classes;
var Cu = Components.utils;

var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);


/*
 * @param global: the global object to use for the execution context associated with the module loader.
 * use null for system modules, then {context:<string>} to config (required)
 * use |window| for window modules, config optional
 * @param requirejsConfig: object matching http://requirejs.org/docs/api.html#config
 * @param securityOrigin: a window, URI, or nsIPrincipal. Overrides global as origin URI for scripts in sandbox
 * Operations on the global object in the evaled code must be carefully studied unless
 * the securityOrigin is more restricting.
 */

function ModuleLoader(global, requirejsConfig, securityOrigin) {
    this.config = ModuleLoader.copyProperties({}, requirejsConfig);
    this.global = global;
    this.securityOrigin;

    this.registry = {};
    this.totalEvals = 0;
    this.totalEntries = 0;

    ModuleLoader.instanceCount += 1;
    this.instanceCount = ModuleLoader.instanceCount;

    var self = this;
    this.loadDepsThenCallback  = function() { // during the ctor call, bind a ref to the loader
        return self.prefixWithConfig.apply(self, arguments);  // use the bound ref to call apply with proper |this|
    }
    this.define = this.loadDepsThenCallback;

    ModuleLoader.currentModuleLoader = this;

    if (!ModuleLoader.loaders) {
        ModuleLoader.loaders = [];
    }
    ModuleLoader.loaders.push(this);
}

ModuleLoader.debug = false;

/*
ModuleLoader.checkDefineArguments = function(id, dependencies, definerFunction) {
    var problem = "";
    if (!id || typeof(id) !== 'string')
        problem += "First argument must be an id, a string, was "+id;
    if (!dependencies || !(length in dependencies) )
        problem += "Second argument must be an array of dependencies";
    if (!definerFunction || typeof(definerFunction != "function") )
        problem += "Third argument must function defining the module";
    if (problem)
        throw new Error("ERROR in define() call: "+problem);
}
ModuleLoader.define = function(id, dependencies, definerFunction) {
    ModuleLoader.checkDefineArguments.apply(ModuleLoader, arguments);

    if (!ModuleLoader.modules) {
        ModuleLoader.modules = {}; // indexed by id
    }
    if (id in ModuleLoader.modules) {
        throw new Error("ERROR in define() call: "+id+" already defined");
    }
    ModuleLoader.modules[id] = {dependencies: dependencies, definerFunction: definerFunction};
}

ModuleLoader.require = function(leafs, finalizer) {
    // Load the leafs
    // check deps
    // run finalizer
}
*/
/*
 * @return the current module loader for the current execution context.
 * (XXXjjb: dubious value)
 */
ModuleLoader.current = function getCurrentModuleLoader() {
    return ModuleLoader.currentModuleLoader;
}

ModuleLoader.instanceCount = 0;

ModuleLoader.get = function(name) {
    for (var i = 0; i < ModuleLoader.loaders.length; i++) {
        if (ModuleLoader.loaders[i].getModuleLoaderName() === name) {
            return ModuleLoader.loaders[i];
        }
    }
}
/*
 * @return reference to lhs, overridden by properties of rhs
 * @param lhs left hand side object, properties may be overwritten by rhs
 * @param rhs (optional) right hand side object, properties copied over lhs
 */
ModuleLoader.copyProperties = function(lhs, rhs) {
    for (var p in rhs) {
        try {
            lhs[p] = rhs[p];
        } catch (exc) {
            // On the Mozila platform we get "Operation is not supported"<commit_msg>[modules] remove experimental commented code<commit_after>/*
 * Extends require.js (by <NAME>) to support loading modules into Firefox extensions
 *
 * Copyright 2011 <NAME> for IBM Corp.
 * This code is released under Firebug's BSD license.
 *
 * Key ideas from securable-modules.js by <NAME> <<EMAIL>>,
 * with enhancements by <NAME> and <NAME> released under BSD license
 * https://bugzilla.mozilla.org/show_bug.cgi?id=614239 accessed on Jan. 8, 2011
 *
 * API influenced by: http://wiki.ecmascript.org/doku.php?id=strawman:module_loaders accessed on Jan. 8, 2011
 */

// allow this file to be loaded via resource url
// eg Components.utils.import("resource://hellomodule/ModuleLoader.js");
var EXPORTED_SYMBOLS = ["ModuleLoader"];

var Ci = Components.interfaces;
var Cc = Components.classes;
var Cu = Components.utils;

var consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);


/*
 * @param global: the global object to use for the execution context associated with the module loader.
 * use null for system modules, then {context:<string>} to config (required)
 * use |window| for window modules, config optional
 * @param requirejsConfig: object matching http://requirejs.org/docs/api.html#config
 * @param securityOrigin: a window, URI, or nsIPrincipal. Overrides global as origin URI for scripts in sandbox
 * Operations on the global object in the evaled code must be carefully studied unless
 * the securityOrigin is more restricting.
 */

function ModuleLoader(global, requirejsConfig, securityOrigin) {
    this.config = ModuleLoader.copyProperties({}, requirejsConfig);
    this.global = global;
    this.securityOrigin;

    this.registry = {};
    this.totalEvals = 0;
    this.totalEntries = 0;

    ModuleLoader.instanceCount += 1;
    this.instanceCount = ModuleLoader.instanceCount;

    var self = this;
    this.loadDepsThenCallback  = function() { // during the ctor call, bind a ref to the loader
        return self.prefixWithConfig.apply(self, arguments);  // use the bound ref to call apply with proper |this|
    }
    this.define = this.loadDepsThenCallback;

    ModuleLoader.currentModuleLoader = this;

    if (!ModuleLoader.loaders) {
        ModuleLoader.loaders = [];
    }
    ModuleLoader.loaders.push(this);
}

ModuleLoader.debug = false;

/*
 * @return the current module loader for the current execution context.
 * (XXXjjb: dubious value)
 */
ModuleLoader.current = function getCurrentModuleLoader() {
    return ModuleLoader.currentModuleLoader;
}

ModuleLoader.instanceCount = 0;

ModuleLoader.get = function(name) {
    for (var i = 0; i < ModuleLoader.loaders.length; i++) {
        if (ModuleLoader.loaders[i].getModuleLoaderName() === name) {
            return ModuleLoader.loaders[i];
        }
    }
}
/*
 * @return reference to lhs, overridden by properties of rhs
 * @param lhs left hand side object, properties may be overwritten by rhs
 * @param rhs (optional) right hand side object, properties copied over lhs
 */
ModuleLoader.copyProperties = function(lhs, rhs) {
    for (var p in rhs) {
        try {
            lhs[p] = rhs[p];
        } catch (exc) {
            // On the Mozila platform we get "Operation is not supported"
{'fraction_non_alphanumeric': 0.10735138004246285, 'fraction_numerical': 0.006900212314225053, 'mean_word_length': 3.6467324290998766, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4491793', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2101, 'n_words': 705}