<commit_before>var System, Loader;
(function (global/*, XMLHttpRequest, globalEval*/) {


	/***** stub ES6 Loader *****/

	/**
	 * Stub ES6 Loader.  Serves as a temporary loader until a shim is in place.
	 * @constructor
	 * @param options
	 * @private
	 */
	function _Loader (parent, options) {
		if (!options) options = {};
		this.global = options.global;
		this.strict = options.strict;
		// TODO: process other options
	}

	_Loader.prototype = {

		global: global,
		strict: true,

		evalAsync: shimCallerAsync('evalAsync'),
		load: shimCallerAsync('load'),
		"import": shimCallerAsync('import'),

		"eval": shimCallerSync('eval'),
		get: shimCallerSync('get'),
		has: shimCallerSync('has'),
		set: shimCallerSync('set'),
		"delete": shimCallerSync('delete')

	};

	// sniff System and Loader
	if (typeof Loader == 'undefined') {
		Loader = _Loader;
	}

	if (typeof System == 'undefined') {
		System = new Loader();
	}

	/***** stuff to load a real ES6 Loader shim *****/

	var getShim, saveShimImpl, shim;

	/**
	 * Gets the shim and calls back.  Uses before advice to modify the getShim
	 * function to instruct any further calls to just queue callbacks.
	 * @function
	 * @param {Function} cb
	 */
	getShim = before(
		function (cb) {
			fetchShim(saveShimImpl);
		},
		function (cb) {
			// rewrite getShim
			getShim = waitForShim;
			// register the first callback as a waiter
			waitForShim(cb);
		}
	);

	/**
	 * Saves the shim implementation.  Uses after advice to modify the getShim
	 * function to stop queueing callbacks and calls them immediately, instead.
	 * All callbacks are called at this point.
	 * @function
	 */
	saveShimImpl = after(
		saveShimProto,
		function (impl) {
			// rewrite getShim
			getShim = callShimNow;
			callShimWaiters(impl);
		}
	);

	shim = {
		impl: null,
		waiters: []
	};

	/**
	 * Creates a function that will call the ES6 Loader shim when it becomes
	 * available and then call back.  This is used to implement async methods
	 * on the ES6 Loader stub.
	 * @private
	 * @param {String} funcName
	 * @return {Function}
	 */
	function shimCallerAsync (funcName) {
		return function callShimAsync () {
			getShim(function (impl) {
				impl[funcName].apply(this, arguments);
			});
		};
	}

	/**
	 * Creates a function that will call the ES6 Loader shim sync or fail
	 * if the shim isn't available, yet.
	 * @private
	 * @param {String} funcName
	 * @return {Function}
	 */
	function shimCallerSync (funcName) {
		return function () {
			if (!shim.impl) failNotReady();
			else return shim.impl[funcName].apply(this, arguments);
		};
	}

	/**
	 * Fetches the Loader shim module and its dependencies.  Then it injects
	 * the dependencies into the shim module's init function to create
	 * the Loader shim.
	 * @private
	 * @param {Function} callback
	 */
	function fetchShim (callback) {
		var ids, modules, count, id, Loader;

		ids = [
			'Deferred',
			'shim/XMLHttpRequest'
		];
		modules = {};
		count = ids.length;

		System._require('./lib/Loader', after(createLoader, countdown));
		while (id = ids.shift()) {
			System._require(
				'./lib/' + id,
				after(createSaverForModule(id), countdown)
			);
		}

		function createLoader (init) {
			Loader = init(modules);
		}
		function createSaverForModule (id) {
			return function (module) { modules[id] = module; };
		}
		function countdown () {
			if (count-- == 0) callback(Loader);
		}
	}

	function waitForShim (callback) {
		shim.waiters.push(callback);
	}

	function callShimWaiters (impl) {
		var waiter;
		while (waiter = shim.waiters.shift()) waiter(impl);
	}

	function saveShimProto (impl) {
		// save the shim's prototype to get at the methods.
		return shim.impl = impl.prototype;
	}

	function callShimNow (cb) { cb(shim.impl); }

	function failNotReady () {
		throw new Error('Cannot access loader before it is fully loaded.');
	}


	/***** simple, temporary AMD for loading local modules *****/

	var definedModules;

	definedModules = {};

	/**
	 * Global define function on System object.  This is a simplified AMD-like
	 * module wrapper to allow us to load some initial modules before a
	 * fully-functional module loader is in place.
	 * @function
	 * @param {Function} factory
	 */
	System._define = function define (factory) {
		var ex, id;
		if ('*' in definedModules) {
			ex = new Error('Duplicate anonymous define() encountered');
		}
		id = getDefinedModuleId() || '*';
		definedModules[id] = new Mctx(factory, ex);
	};

	/**
	 * Simple AMD fetcher.
	 * @param {String} id
	 * @param {Function} callback
	 * @param {Function} [errback]
	 */
	System._require = function simpleAmd (id, callback, errback) {
		var url;
		if (id in definedModules ) {
			callback(definedModules[id] = runFactory(definedModules[id]));
		}
		url = addBaseUrl(baseUrl, ensureExt(id));
		loadScript(
			{ id: id, url: url },
			function success () {
				var key, found, mctx;
				key = '*' in definedModules ? '*' : id;
				found = key in definedModules;
				mctx = definedModules[key];
				delete definedModules['*'];
				if (!found) {
					fail(new Error('define() missing or syntax error'));
				}
				else if (mctx.ex) {
					fail(mctx.ex);
				}
				callback(definedModules[id] = runFactory(mctx));
			},
			fail
		);
		function fail (ex) {
			ex = ex || new Error('Could not load');
			ex.message += ' ' + url;
			if (errback) errback(ex); else throw ex;
		}
	};

	function runFactory (mctx) {
		return mctx instanceof Mctx ? mctx.factory() : mctx;
	}

	/**
	 * Constructs a module definition context. Allows us to use `instanceof`
	 * to positively identify a module that hasn't had its factory run, yet.
	 * @private
	 * @param factory
	 * @param ex
	 * @constructor
	 */
	function Mctx (factory, ex) {
		this.factory = factory;
		if (ex) this.ex = ex;
	}


	/***** script loader *****/

	var doc, loadScript, baseUrl, activeScripts, getDefinedModuleId;

	doc = global.document;

	// node, ringojs, etc.
	if (typeof module != 'undefined' && typeof require == 'function') {
		baseUrl = stripFilePart(module.uri);
		loadScript = createCallbackLoader(require);
		// in node, module.id is bogus, don't try to use it.
		getDefinedModuleId = noop;
	}
	// browser
	else if (doc) {
		activeScripts = {};
		baseUrl = stripFilePart(findScriptPath());
		loadScript = createBrowserScriptLoader(doc);
		getDefinedModuleId = getCurrentScriptId;
	}
	// fail
	else {<commit_msg>Implement basic Loader features for beck modules only.<commit_after>var System, Loader;
(function (global/*, XMLHttpRequest, globalEval*/) {


	/***** stub ES6 Loader *****/

	var cache;

	cache = {};

	/**
	 * Stub ES6 Loader.  Serves as a temporary loader until a shim is in place.
	 * @constructor
	 * @param options
	 * @param options
	 * @private
	 */
	function _Loader (parent, options) {
		// save args to create the real shim when it is loaded
		this._parent = parent;
		this._options = options;
	}

	_Loader.prototype = {

		global: global,
		strict: true,

		evalAsync: shimCallerAsync('evalAsync'),
		load: shimCallerAsync('load'),
		//"import": shimCallerAsync('import'),
		"import": function (idOrArray, callback, errback) {
			var self = this;
			if (typeof idOrArray != 'string' || idOrArray.slice(0, 4) != 'beck') {
				getShim(function (impl) {
					impl['import'].apply(self, [idOrArray, callback, errback]);
				});
			}
			else {
				simpleAmd(idOrArray, callback, errback);
			}
		},

		"eval": shimCallerSync('eval'),
		get: before(function (id) { return cache[id]; }, failIfNotBeckModule),
		has: function (id) { return id in cache; },
		set: before(function (id, value) { return cache[id] = value; }, failIfNotBeckModule),
		"delete": before(function (id) { delete cache[id]; }, failIfNotBeckModule)

	};

	// sniff System and Loader
	if (typeof Loader == 'undefined') {
		Loader = _Loader;
	}

	if (typeof System == 'undefined') {
		System = new Loader();
	}

	function failIfNotBeckModule (id) {
		if (id.slice(0, 4) != 'beck') failNotReady();
	}

	/***** stuff to load a real ES6 Loader shim *****/

	var getShim, saveShimImpl, shim;

	/**
	 * Gets the shim and calls back.  Uses before advice to modify the getShim
	 * function to instruct any further calls to just queue callbacks.
	 * @function
	 * @param {Function} cb
	 */
	getShim = before(
		function (cb) {
			fetchShim(saveShimImpl);
		},
		function (cb) {
			// rewrite getShim
			getShim = waitForShim;
			// register the first callback as a waiter
			waitForShim(cb);
		}
	);

	/**
	 * Saves the shim implementation.  Uses after advice to modify the getShim
	 * function to stop queueing callbacks and calls them immediately, instead.
	 * All callbacks are called at this point.
	 * @function
	 */
	saveShimImpl = after(
		saveShimProto,
		function (impl) {
			// rewrite getShim
			getShim = callShimNow;
			callShimWaiters(impl);
		}
	);

	shim = {
		impl: null,
		waiters: []
	};

	/**
	 * Creates a function that will call the ES6 Loader shim when it becomes
	 * available and then call back.  This is used to implement async methods
	 * on the ES6 Loader stub.
	 * @private
	 * @param {String} funcName
	 * @return {Function}
	 */
	function shimCallerAsync (funcName) {
		return function callShimAsync () {
			var that = this, args = arguments;
			getShim(function (impl) {
				impl[funcName].apply(that, args);
			});
		};
	}

	/**
	 * Creates a function that will call the ES6 Loader shim sync or fail
	 * if the shim isn't available, yet.
	 * @private
	 * @param {String} funcName
	 * @return {Function}
	 */
	function shimCallerSync (funcName) {
		return function () {
			if (!shim.impl) failNotReady();
			else return shim.impl[funcName].apply(this, arguments);
		};
	}

	/**
	 * Fetches the Loader shim module and its dependencies.  Then it injects
	 * the dependencies into the shim module's init function to create
	 * the Loader shim.
	 * @private
	 * @param {Function} callback
	 */
	function fetchShim (callback) {
		var ids, count, id;

		ids = [
			'Deferred',
			'shim/XMLHttpRequest'
		];
		count = ids.length;

		System.import('beck/lib/Loader', after(setLoader, countdown));
		while (id = ids.shift()) {
			System.import('beck/lib/' + id, countdown);
		}

		function countdown () {
			if (count-- == 0) callback(Loader);
		}
	}

	function waitForShim (callback) {
		shim.waiters.push(callback);
	}

	function callShimWaiters (impl) {
		var waiter;
		while (waiter = shim.waiters.shift()) waiter(impl);
	}

	function saveShimProto (impl) {
		// save the shim's prototype to get at the methods.
		return shim.impl = impl.prototype;
	}

	function setLoader (impl) {
		Loader = impl;
	}

	function callShimNow (cb) { cb(shim.impl); }

	function failNotReady () {
		throw new Error('Cannot access loader before it is fully loaded.');
	}


	/***** simple, temporary AMD for loading local modules *****/

	var definedModules;

	definedModules = {};

	/**
	 * Global define function on System object.  This is a simplified AMD-like
	 * module wrapper to allow us to load some initial modules before a
	 * fully-functional module loader is in place.
	 * @function
	 * @param {Function} factory
	 */
	System._define = function define (factory) {
		var ex, id;
		if ('*' in definedModules) {
			ex = new Error('Duplicate anonymous define() encountered');
		}
		id = getDefinedModuleId() || '*';
		definedModules[id] = new Mctx(factory, ex);
	};

	/**
	 * Simple AMD fetcher.
	 * @param {String} id
	 * @param {Function} callback
	 * @param {Function} [errback]
	 */
	function simpleAmd (id, callback, errback) {
		var url;
		if (id in definedModules ) {
			callback(definedModules[id] = runFactory(definedModules[id]));
		}
		url = addBaseUrl(baseUrl, ensureExt(id));
		loadScript(
			{ id: id, url: url },
			function success () {
				var key, found, mctx;
				key = '*' in definedModules ? '*' : id;
				found = key in definedModules;
				mctx = definedModules[key];
				delete definedModules['*'];
				if (!found) {
					fail(new Error('define() missing or syntax error'));
				}
				else if (mctx.ex) {
					fail(mctx.ex);
				}
				callback(definedModules[id] = runFactory(mctx));
			},
			fail
		);
		function fail (ex) {
			ex = ex || new Error('Could not load');
			ex.message += ' ' + url;
			if (errback) errback(ex); else throw ex;
		}
	};

	function runFactory (mctx) {
		return mctx instanceof Mctx ? mctx.factory() : mctx;
	}

	/**
	 * Constructs a module definition context. Allows us to use `instanceof`
	 * to positively identify a module that hasn't had its factory run, yet.
	 * @private
	 * @param factory
	 * @param ex
	 * @constructor
	 */
	function Mctx (factory, ex) {
		this.factory = factory;
		if (ex) this.ex = ex;
	}


	/***** script loader *****/

	var doc, loadScript, baseUrl, activeScripts, getDefinedModuleId;

	doc = global.document;

	// node, ringojs, etc.
	if (typeof module != 'undefined' && typeof require == 'function') {
		baseUrl = stripFilePart(module.uri) + '../';
		loadScript = createCallbackLoader(require);
		// in node, module.id is bogus, don't try to use it.
		getDefinedModuleId = noop;
	}
	// browser
	else if (doc) {
		activeScripts = {};
		baseUrl = stripFilePart(findScriptPath()) + '../';
		loadScript = createBrowserScriptLoader(doc);
		getDefinedModuleId = getCurrentScriptId;
	}
	// fail
	else {
{'fraction_non_alphanumeric': 0.1342652058934643, 'fraction_numerical': 0.0013600302228938422, 'mean_word_length': 3.312805474095797, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4371117', 'n_tokens_mistral': 4861, 'n_tokens_neox': 4279, 'n_words': 1313}