1 onmessage = function(event) {
2 if (event.data == "noport") {
3 if (event.ports && !event.ports.length)
4 testPassed("event.ports is non-null and zero length when no port sent");
6 testFailed("event.ports is null or non-zero length when no port sent");
7 } else if (event.data == "zero ports") {
8 if (event.ports && !event.ports.length)
9 testPassed("event.ports is non-null and zero length when empty array sent");
11 testFailed("event.ports is null or non-zero length when empty array sent");
12 } else if (event.data == "two ports") {
14 testFailed("event.ports should be non-null when ports sent");
17 if (event.ports.length == 2)
18 testPassed("event.ports contains two ports when two ports sent");
20 testFailed("event.ports contained " + event.ports.length + " when two ports sent");
21 } else if (event.data == "failed ports") {
22 if (event.ports.length == 2)
23 testPassed("event.ports contains two ports when two ports re-sent after error");
25 testFailed("event.ports contained " + event.ports.length + " when two ports re-sent after error");
26 } else if (event.data == "done") {
28 event.ports[0].postMessage("done");
29 } else if (event.data == "noargs") {
32 testFailed("postMessage() did not throw");
34 testPassed("postMessage() threw exception: " + e);
37 testFailed("Received unexpected message: " + event.data);
40 function testPassed(msg)
42 postMessage("PASS"+msg);
45 function testFailed(msg)
47 postMessage("FAIL"+msg);