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