dom/workers/test/importScripts_worker.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /**
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5 // Try no args. This shouldn't do anything.
michael@0 6 importScripts();
michael@0 7
michael@0 8 // This caused security exceptions in the past, make sure it doesn't!
michael@0 9 var constructor = {}.constructor;
michael@0 10
michael@0 11 importScripts("importScripts_worker_imported1.js");
michael@0 12
michael@0 13 // Try to call a function defined in the imported script.
michael@0 14 importedScriptFunction();
michael@0 15
michael@0 16 function tryBadScripts() {
michael@0 17 var badScripts = [
michael@0 18 // Has a syntax error
michael@0 19 "importScripts_worker_imported3.js",
michael@0 20 // Throws an exception
michael@0 21 "importScripts_worker_imported4.js",
michael@0 22 // Shouldn't exist!
michael@0 23 "http://example.com/non-existing/importScripts_worker_foo.js",
michael@0 24 // Not a valid url
michael@0 25 "http://notadomain::notafile aword"
michael@0 26 ];
michael@0 27
michael@0 28 for (var i = 0; i < badScripts.length; i++) {
michael@0 29 var caughtException = false;
michael@0 30 var url = badScripts[i];
michael@0 31 try {
michael@0 32 importScripts(url);
michael@0 33 }
michael@0 34 catch (e) {
michael@0 35 caughtException = true;
michael@0 36 }
michael@0 37 if (!caughtException) {
michael@0 38 throw "Bad script didn't throw exception: " + url;
michael@0 39 }
michael@0 40 }
michael@0 41 }
michael@0 42
michael@0 43 const url = "data:text/plain,const startResponse = 'started';";
michael@0 44 importScripts(url);
michael@0 45
michael@0 46 onmessage = function(event) {
michael@0 47 switch (event.data) {
michael@0 48 case 'start':
michael@0 49 importScripts("importScripts_worker_imported2.js");
michael@0 50 importedScriptFunction2();
michael@0 51 tryBadScripts();
michael@0 52 postMessage(startResponse);
michael@0 53 break;
michael@0 54 case 'stop':
michael@0 55 tryBadScripts();
michael@0 56 postMessage('stopped');
michael@0 57 break;
michael@0 58 default:
michael@0 59 throw new Error("Bad message: " + event.data);
michael@0 60 break;
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 tryBadScripts();

mercurial