<commit_before>function send(func, payload){
	data = {
		function: func,
		payload: payload
	}
	jsdata = JSON.stringify(data)
	this.postMessage(jsdata);
	return this;
}


function ajax(url, callback, data, type) {
	var data_array, data_string, idx, req, value;
	if (data == null) {
		data = {};
	}
	if (callback == null) {
		callback = function() {};
	}
	if (type == null) {
		//default to a GET request
		type = 'GET';
	}
	data_array = [];
	for (idx in data) {
		value = data[idx];
		data_array.push("" + idx + "=" + value);
	}
	data_string = data_array.join("&");
	req = new XMLHttpRequest();
	req.open(type, url, false);
	req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

	req.onreadystatechange = function() {
		if (req.readyState === 4 && req.status === 200) {
			return callback(req.responseText);
		}
	};
	req.send(data_string);

	return JSON.parse(req);
}


// the listener will automatically call functions by name
self.addEventListener("message", function(event) {
	// convert the payload to an object from it's JSON form
	data = JSON.parse(event.data)

	if (data.payload  === "undefined"){
		// make a call to a function without a payload
		self[data.function]()
	}else{
		// make the call to the function and give it a payload
		self[data.function](data.payload)
	}
}, false);<commit_msg>Update worker.functions.js<commit_after>var sendToFn = function(){
	if(typeof(wid) !== 'undefined'){
		anonMethodName = window[wid]["anonMethodName"];
	}

	callback_details = JSON.stringify({ method: anonMethodName, args: Array.from(arguments) });

	if(typeof(wid) !== 'undefined'){
		window[wid].postMessage(callback_details);
	}else{
		postMessage(callback_details);
	}
	return this;
}

if(typeof(window) !== 'undefined' && typeof(Worker) !== "undefined" && typeof(Proxy) !== 'undefined') {

	Worker.prototype = {};
	Worker.prototype.anonMethodName = null;
	
	// Calls a function in our worker and passes a payload of data to the worker
	Worker.prototype.sendToWorker = sendToFn;

	// auto receiver that handles running a function and passes an object of data to it.
	Worker.prototype.auto = function(func){
		this.onmessage = function(event){
			data = JSON.parse(event.data);
			if(data.method in window && typeof(window[data.method]) == typeof(function(){})){
				window[data.method].apply(this, data.args);
			}
		}

		return this;
	}
	
	function sWorker(jsfile){
		wid = "worker" + (new Date().getTime());
		window[wid] = new Worker(jsfile).auto();
		
		return new Proxy({ id: wid }, {
			get: function(target, name) {
				window[wid]["anonMethodName"] = name;
				
				if (!(name in window[wid])) {
					return window[wid]["sendToWorker"];
				}
				
				return window[wid][name];
			},
			set: function(target, name, value) {
				console.log("I'm sorry, I can not do that Dave.");
				/*if (!(name in target)) {
					console.log("Setting non-existant property '" + name + "', initial value: " + value);
				}
				target[name] = value;*/
			}
		});
	}

}else if(typeof(Worker) !== "undefined" && typeof(Proxy) !== 'undefined'){
	var anonMethodName = null;
	// the listener will automatically call functions by name
	self.addEventListener("message", function(event) {
		data = JSON.parse(event.data);
		this[data.method].apply(this, data.args);
	}, false);
	var req = new Proxy({}, {
		get: function(target, name) {
			anonMethodName = name;
			return sendToFn;
		},
		set: function(target, name, value) {
			console.log("Not implemented");
			/*
			if (!(name in target)) {
				console.log("Setting non-existant property '" + name + "', initial value: " + value);
			}
			target[name] = value;*/
		}
	});

}
{'fraction_non_alphanumeric': 0.16451524306509202, 'fraction_numerical': 0.0010985992859104642, 'mean_word_length': 3.8495339547270304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '5660104', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1181, 'n_words': 305}