2011-07-17 12:09:13 -07:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
2009-01-13 10:43:23 -08:00
|
|
|
// Try no args. This shouldn't do anything.
|
|
|
|
importScripts();
|
|
|
|
|
2008-09-08 10:48:14 -07:00
|
|
|
// This caused security exceptions in the past, make sure it doesn't!
|
|
|
|
var constructor = {}.constructor;
|
|
|
|
|
2008-11-05 22:41:52 -08:00
|
|
|
importScripts("importScripts_worker_imported1.js");
|
2008-09-08 10:48:14 -07:00
|
|
|
|
|
|
|
// Try to call a function defined in the imported script.
|
|
|
|
importedScriptFunction();
|
|
|
|
|
|
|
|
function tryBadScripts() {
|
|
|
|
var badScripts = [
|
|
|
|
// Has a syntax error
|
|
|
|
"importScripts_worker_imported3.js",
|
|
|
|
// Throws an exception
|
|
|
|
"importScripts_worker_imported4.js",
|
|
|
|
// Shouldn't exist!
|
2012-03-08 04:31:20 -08:00
|
|
|
"http://example.com/non-existing/importScripts_worker_foo.js",
|
2008-09-08 10:48:14 -07:00
|
|
|
// Not a valid url
|
2012-03-08 04:31:20 -08:00
|
|
|
"http://notadomain::notafile aword"
|
2008-09-08 10:48:14 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
for (var i = 0; i < badScripts.length; i++) {
|
|
|
|
var caughtException = false;
|
|
|
|
var url = badScripts[i];
|
|
|
|
try {
|
2008-11-05 22:41:52 -08:00
|
|
|
importScripts(url);
|
2008-09-08 10:48:14 -07:00
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
caughtException = true;
|
|
|
|
}
|
|
|
|
if (!caughtException) {
|
|
|
|
throw "Bad script didn't throw exception: " + url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-04 10:57:42 -07:00
|
|
|
const url = "data:text/plain,const startResponse = 'started';";
|
|
|
|
importScripts(url);
|
|
|
|
|
2010-11-22 00:13:37 -08:00
|
|
|
onmessage = function(event) {
|
|
|
|
switch (event.data) {
|
|
|
|
case 'start':
|
|
|
|
importScripts("importScripts_worker_imported2.js");
|
|
|
|
importedScriptFunction2();
|
|
|
|
tryBadScripts();
|
2011-11-04 10:57:42 -07:00
|
|
|
postMessage(startResponse);
|
2010-11-22 00:13:37 -08:00
|
|
|
break;
|
|
|
|
case 'stop':
|
|
|
|
tryBadScripts();
|
|
|
|
postMessage('stopped');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error("Bad message: " + event.data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-08 10:48:14 -07:00
|
|
|
tryBadScripts();
|