<commit_before>/* 
==================================================================================================
  Jasy - JavaScript Tooling Framework
  Copyright 2010-2011 <NAME>
==================================================================================================
*/

/**
 * @require {fix.DocumentHead}
 */
(function(global)
{
	var doc = global.document;

	// All loaded scripts
	var completed = {};
	var loading = {};

	// the following is a feature sniff for the ability to set async=false on dynamically created script elements, as proposed to the W3C
	// RE: http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
	var supportsScriptAsync = doc.createElement("script").async === true;
	var dynamicUri = "?r=" + Date.now();


	/**
	 *
	 *
	 */
	var hasLoaded = function(uris) 
	{
		for (var i=0, l=uris.length; i<l; i++) 
		{
			if (!completed[uris[i]]) {
				return false;
			}
		}
		
		return true;
	};
	

	/**
	 * Creates and appends script tag for given URI
	 *
	 * @param uri {String} URI to load
	 * @param onload {Function} Callback function to execute when script was loaded
	 * @param nocache {Boolean?false} Whether we should inject a dynamic part to the URL to omit caching
	 */
	var createScriptTag = function(uri, onload, nocache)
	{
		var elem = doc.createElement("script");
		
		// load script via 'src' attribute, set onload/onreadystatechange listeners
		elem.onload = elem.onerror = elem.onreadystatechange = function(e) {
			onload((e?e:event).type, uri, elem);
		};
		
		elem.src = nocache ? uri + dynamicUri : uri;
		
		if (supportsScriptAsync) {
			elem.async = false;
		}
		
		doc.head.insertBefore(elem, doc.head.firstChild);
	};
	
	
	/**
	 * Returns a custom onload routine for script elements. 
	 *
	 * * Supports wait list of numerous scripts which needs to be loaded
	 * * Executes the given callback method (when single script or all scripts have been loaded)
	 *
	 * @param callback {Function?} Callback function to execute
	 * @param context {Object?} Context in which the callback function should be executed
	 * @param uris {Array} List of sources which should be waited for
	 */
	var getOnLoad = function(callback, context, uris)
	{
		// Load listener local registry of uris we wait for until we execute the callback
		var waitingScripts = {};
		if (uris)
		{
			for (var i=0, l=uris.length; i<l; i++) 
			{
				var currentUri = uris[i];
				if (!completed[currentUri]) {
					waitingScripts[currentUri] = true;
				}
			}
		}
		
		return function(type, uri, elem)
		{
			var isErrornous = type == "error";
			if (!isErrornous) 
			{
				var readyState = elem.readyState;
				if (readyState && readyState !== "complete" && readyState !== "loaded") {
					return;
				}
			}
			
			// Prevent memory leaks
			elem.onload = elem.onerror = elem.onreadystatechange = null;
			
			// Clear entry from local waiting registry
			delete waitingScripts[uri];

			// Delete from shared activity registry
			delete loading[uri];
			
			// Add to shared loaded registry
			completed[uri] = true;
			
			if (callback) 
			{
				// Check whether there are more local scripts we need to wait for
				for (var uri in waitingScripts) {
					return;
				}

				callback.call(context||global);
			}
			
			if (isErrornous) {
				throw new Error("Could not load script: " + uri);
			}
		};
	};


	/** {Array} List of function, context where each entry consumes two array fields */
	var cachedCallbacks = [];

	/**
	 * Flushes the cached callbacks as soon as no more active scripts are detected.
	 * This methods is called by the different complete scenarios from the loader functions.
	 */
	var flushCallbacks = function()
	{
		// Check whether all known scripts are loaded
		for (var uri in loading) {
			return;
		}
		
		// Then execute all callbacks (copy to protect loop from follow-up changes)
		var todo = cachedCallbacks.concat();
		cachedCallbacks.length = 0;
		for (var i=0, l=todo.length; i<l; i+=2) {
			todo[i].call(todo[i+1]);
		}
	};

	
	// Firefox(prior to Firefox 4) & Opera preserve execution order with script tags automatically,<commit_msg>Minor changes<commit_after>/* 
==================================================================================================
  Jasy - JavaScript Tooling Framework
  Copyright 2010-2011 <NAME>
==================================================================================================
*/

/**
 * @require {fix.DocumentHead}
 */
(function(global)
{
	var doc = global.document;

	// All loaded scripts
	var completed = {};
	var loading = {};

	// the following is a feature sniff for the ability to set async=false on dynamically created script elements, as proposed to the W3C
	// RE: http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
	var supportsScriptAsync = doc.createElement("script").async === true;
	
	// Dynamic URI can be shared because we do not support reloading files
	var dynamicUri = "?r=" + Date.now();


	/**
	 *
	 *
	 */
	var hasLoaded = function(uris) 
	{
		for (var i=0, l=uris.length; i<l; i++) 
		{
			if (!completed[uris[i]]) {
				return false;
			}
		}
		
		return true;
	};
	

	/**
	 * Creates and appends script tag for given URI
	 *
	 * @param uri {String} URI to load
	 * @param onload {Function} Callback function to execute when script was loaded
	 * @param nocache {Boolean?false} Whether we should inject a dynamic part to the URL to omit caching
	 */
	var createScriptTag = function(uri, onload, nocache)
	{
		var elem = doc.createElement("script");
		
		// load script via 'src' attribute, set onload/onreadystatechange listeners
		elem.onload = elem.onerror = elem.onreadystatechange = function(e) {
			onload((e?e:event).type, uri, elem);
		};
		
		elem.src = nocache ? uri + dynamicUri : uri;
		
		if (supportsScriptAsync) {
			elem.async = false;
		}
		
		doc.head.insertBefore(elem, doc.head.firstChild);
	};
	
	
	/**
	 * Returns a custom onload routine for script elements. 
	 *
	 * * Supports wait list of numerous scripts which needs to be loaded
	 * * Executes the given callback method (when single script or all scripts have been loaded)
	 *
	 * @param callback {Function?} Callback function to execute
	 * @param context {Object?} Context in which the callback function should be executed
	 * @param uris {Array} List of sources which should be waited for
	 */
	var getOnLoad = function(callback, context, uris)
	{
		// Load listener local registry of uris we wait for until we execute the callback
		var waitingScripts = {};
		if (uris)
		{
			for (var i=0, l=uris.length; i<l; i++) 
			{
				var currentUri = uris[i];
				if (!completed[currentUri]) {
					waitingScripts[currentUri] = true;
				}
			}
		}
		
		return function(type, uri, elem)
		{
			var isErrornous = type == "error";
			if (!isErrornous) 
			{
				var readyState = elem.readyState;
				if (readyState && readyState !== "complete" && readyState !== "loaded") {
					return;
				}
			}
			
			// Prevent memory leaks
			elem.onload = elem.onerror = elem.onreadystatechange = null;
			
			// Clear entry from local waiting registry
			delete waitingScripts[uri];

			// Delete from shared activity registry
			delete loading[uri];
			
			// Add to shared loaded registry
			completed[uri] = true;
			
			if (callback) 
			{
				// Check whether there are more local scripts we need to wait for
				for (var uri in waitingScripts) {
					return;
				}

				callback.call(context||global);
			}
			
			if (isErrornous) {
				throw new Error("Could not load script: " + uri);
			}
		};
	};


	/** {Array} List of function, context where each entry consumes two array fields */
	var cachedCallbacks = [];

	/**
	 * Flushes the cached callbacks as soon as no more active scripts are detected.
	 * This methods is called by the different complete scenarios from the loader functions.
	 */
	var flushCallbacks = function()
	{
		// Check whether all known scripts are loaded
		for (var uri in loading) {
			return;
		}
		
		// Then execute all callbacks (copy to protect loop from follow-up changes)
		var todo = cachedCallbacks.concat();
		cachedCallbacks.length = 0;
		for (var i=0, l=todo.length; i<l; i+=2) {
			todo[i].call(todo[i+1]);
		}
	};




	
	// Firefox(prior to Firefox 4) & Opera preserve execution order with script tags automatically,
{'fraction_non_alphanumeric': 0.15295396882928597, 'fraction_numerical': 0.0038661350730941164, 'mean_word_length': 3.2473063109286815, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '1862488', 'n_tokens_mistral': 2857, 'n_tokens_neox': 2368, 'n_words': 836}