Created
September 14, 2009 01:14
-
-
Save eligrey/186413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* importScripts.es5 | |
* Requires ECMAScript 5 or JavaScript 1.9 | |
* 2010-07-21 | |
* | |
* By Eli Grey, http://eligrey.com | |
* | |
* Implements HTML5 web workers' importScripts() function using synchronous XMLHttpRequests. | |
* This is very useful for debugging worker scripts outside of a worker context. | |
* | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ | |
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, | |
regexp: true, strict: true, newcap: true, immed: true */ | |
if (!importScripts) { | |
var importScripts = (function () { | |
var xhr = new XMLHttpRequest; | |
return function importScripts () { | |
var | |
args = Array.prototype.slice.call(arguments) | |
,len = args.length | |
,i = 0 | |
,meta | |
,data | |
,content | |
; | |
for (; i < len; i++) { | |
if (args[i].substr(0, 5).toLowerCase() === "data:") { | |
data = args[i]; | |
content = data.indexOf(","); | |
meta = data.substr(5, content).toLowerCase(); | |
data = decodeURIComponent(data.substr(content + 1)); | |
if (/;\s*base64\s*[;,]/.test(meta)) { | |
data = atob(data); // decode base64 | |
} | |
if (/;\s*charset=[uU][tT][fF]-?8\s*[;,]/.test(meta)) { | |
data = decodeURIComponent(escape(data)); // decode UTF-8 | |
} | |
} else { | |
xhr.open("GET", args[i], false); | |
xhr.send(null); | |
data = xhr.responseText; | |
} | |
eval(data); | |
} | |
}; | |
}()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* importScripts.js | |
* 2010-07-21 | |
* | |
* By Eli Grey, http://eligrey.com | |
* | |
* Implements HTML5 web workers' importScripts() function using synchronous XMLHttpRequests. | |
* This is very useful for debugging worker scripts outside of a worker context. | |
* | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ | |
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, | |
regexp: true, strict: true, newcap: true, immed: true */ | |
"use strict"; | |
if (!importScripts) { | |
var importScripts = (function (globalEval) { | |
var xhr = new XMLHttpRequest; | |
return function importScripts () { | |
var | |
args = Array.prototype.slice.call(arguments) | |
,len = args.length | |
,i = 0 | |
,meta | |
,data | |
,content | |
; | |
for (; i < len; i++) { | |
if (args[i].substr(0, 5).toLowerCase() === "data:") { | |
data = args[i]; | |
content = data.indexOf(","); | |
meta = data.substr(5, content).toLowerCase(); | |
data = decodeURIComponent(data.substr(content + 1)); | |
if (/;\s*base64\s*[;,]/.test(meta)) { | |
data = atob(data); // decode base64 | |
} | |
if (/;\s*charset=[uU][tT][fF]-?8\s*[;,]/.test(meta)) { | |
data = decodeURIComponent(escape(data)); // decode UTF-8 | |
} | |
} else { | |
xhr.open("GET", args[i], false); | |
xhr.send(null); | |
data = xhr.responseText; | |
} | |
globalEval(data); | |
} | |
}; | |
}(eval)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* importScripts.js18 | |
* Requires JavaScript 1.8 | |
* 2010-07-21 | |
* | |
* By Eli Grey, http://eligrey.com | |
* | |
* Implements HTML5 web workers' importScripts() function using synchronous XMLHttpRequests. | |
* This is very useful for debugging worker scripts outside of a worker context. | |
* | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ | |
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, | |
regexp: true, strict: true, newcap: true, immed: true */ | |
"use strict"; | |
importScripts: let (globalEval = eval) { | |
if (importScripts) { | |
break importScripts; | |
} | |
let xhr = new XMLHttpRequest; | |
var importScripts = function importScripts () { | |
let args = Array.slice(arguments); | |
for (let i = 0, len = args.length; i < len; i++) { | |
let data; | |
if (args[i].substr(0, 5).toLowerCase() === "data:") { | |
data = args[i]; | |
let | |
content = data.indexOf(",") | |
,meta = data.substr(5, content).toLowerCase() | |
; | |
data = decodeURIComponent(data.substr(content + 1)); | |
if (/;\s*base64\s*[;,]/.test(meta)) { | |
data = atob(data); // decode base64 | |
} | |
if (/;\s*charset=[uU][tT][fF]-?8\s*[;,]/.test(meta)) { | |
data = decodeURIComponent(escape(data)); // decode UTF-8 | |
} | |
} else { | |
xhr.open("GET", args[i], false); | |
xhr.send(null); | |
data = xhr.responseText; | |
} | |
globalEval(data); | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* importScripts.js19 | |
* Requires JavaScript 1.9 | |
* 2010-07-21 | |
* | |
* By Eli Grey, http://eligrey.com | |
* | |
* Implements HTML5 web workers' importScripts() function using synchronous XMLHttpRequests. | |
* This is very useful for debugging worker scripts outside of a worker context. | |
* | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ | |
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, | |
regexp: true, strict: true, newcap: true, immed: true */ | |
"use strict"; | |
importScripts: { | |
if (importScripts) { | |
break importScripts; | |
} | |
let xhr = new XMLHttpRequest; | |
var importScripts = function importScripts () { | |
let args = Array.slice(arguments); | |
for (let i = 0, len = args.length; i < len; i++) { | |
let data; | |
if (args[i].substr(0, 5).toLowerCase() === "data:") { | |
data = args[i]; | |
let | |
content = data.indexOf(",") | |
,meta = data.substr(5, content).toLowerCase() | |
; | |
data = decodeURIComponent(data.substr(content + 1)); | |
if (/;\s*base64\s*[;,]/.test(meta)) { | |
data = atob(data); // decode base64 | |
} | |
if (/;\s*charset=[uU][tT][fF]-?8\s*[;,]/.test(meta)) { | |
data = decodeURIComponent(escape(data)); // decode UTF-8 | |
} | |
} else { | |
xhr.open("GET", args[i], false); | |
xhr.send(null); | |
data = xhr.responseText; | |
} | |
eval(data); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment