michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: // Try no args. This shouldn't do anything. michael@0: importScripts(); michael@0: michael@0: // This caused security exceptions in the past, make sure it doesn't! michael@0: var constructor = {}.constructor; michael@0: michael@0: importScripts("importScripts_worker_imported1.js"); michael@0: michael@0: // Try to call a function defined in the imported script. michael@0: importedScriptFunction(); michael@0: michael@0: function tryBadScripts() { michael@0: var badScripts = [ michael@0: // Has a syntax error michael@0: "importScripts_worker_imported3.js", michael@0: // Throws an exception michael@0: "importScripts_worker_imported4.js", michael@0: // Shouldn't exist! michael@0: "http://example.com/non-existing/importScripts_worker_foo.js", michael@0: // Not a valid url michael@0: "http://notadomain::notafile aword" michael@0: ]; michael@0: michael@0: for (var i = 0; i < badScripts.length; i++) { michael@0: var caughtException = false; michael@0: var url = badScripts[i]; michael@0: try { michael@0: importScripts(url); michael@0: } michael@0: catch (e) { michael@0: caughtException = true; michael@0: } michael@0: if (!caughtException) { michael@0: throw "Bad script didn't throw exception: " + url; michael@0: } michael@0: } michael@0: } michael@0: michael@0: const url = "data:text/plain,const startResponse = 'started';"; michael@0: importScripts(url); michael@0: michael@0: onmessage = function(event) { michael@0: switch (event.data) { michael@0: case 'start': michael@0: importScripts("importScripts_worker_imported2.js"); michael@0: importedScriptFunction2(); michael@0: tryBadScripts(); michael@0: postMessage(startResponse); michael@0: break; michael@0: case 'stop': michael@0: tryBadScripts(); michael@0: postMessage('stopped'); michael@0: break; michael@0: default: michael@0: throw new Error("Bad message: " + event.data); michael@0: break; michael@0: } michael@0: } michael@0: michael@0: tryBadScripts();