|
1 // Used to test XHR in the worker. |
|
2 onconnect = function(e) { |
|
3 let port = e.ports[0]; |
|
4 let req; |
|
5 try { |
|
6 importScripts("relative_import.js"); |
|
7 // the import should have exposed "testVar" and "testFunc" from the module. |
|
8 if (testVar != "oh hai" || testFunc() != "oh hai") { |
|
9 port.postMessage({topic: "done", result: "import worked but global is not available"}); |
|
10 return; |
|
11 } |
|
12 |
|
13 // causeError will cause a script error, so that we can check the |
|
14 // error location for importScripts'ed files is correct. |
|
15 try { |
|
16 causeError(); |
|
17 } catch(e) { |
|
18 let fileName = e.fileName; |
|
19 if (fileName.startsWith("http") && |
|
20 fileName.endsWith("/relative_import.js") && |
|
21 e.lineNumber == 4) |
|
22 port.postMessage({topic: "done", result: "ok"}); |
|
23 else |
|
24 port.postMessage({topic: "done", result: "invalid error location: " + fileName + ":" + e.lineNumber}); |
|
25 return; |
|
26 } |
|
27 } catch(e) { |
|
28 port.postMessage({topic: "done", result: "FAILED to importScripts, " + e.toString() }); |
|
29 return; |
|
30 } |
|
31 port.postMessage({topic: "done", result: "FAILED to importScripts, no exception" }); |
|
32 } |