1 onmessage = function(evt
) {
2 if (evt
.data
== "port") {
4 postMessage("PASS: Received message port");
5 evt
.ports
[0].onmessage
= pingBack
;
8 postMessage("FAIL: Did not receive expected MessagePort");
10 } else if (evt
.data
== "noport") {
11 if (!evt
.ports
|| evt
.ports
.length
) {
12 postMessage("FAIL: Received message port or null ports array");
14 postMessage("PASS: evt.ports = [] as expected");
16 } else if (evt
.data
== "spam") {
17 for (var i
= 0 ; i
< 1000 ; i
++) {
18 evt
.ports
[0].postMessage(i
);
20 postMessage("spamDone");
21 } else if (evt
.data
== "getport") {
22 var channel
= new MessageChannel();
23 postMessage("port", [channel
.port1
]);
24 channel
.port2
.onmessage
= pingBack
;
25 channel
.port2
.start();
27 postMessage("Unknown message:" + evt
.data
);
32 function pingBack(evt
) {
33 // Make sure we got the expected data and send a return message over
35 if (evt
.data
== "ping") {
36 evt
.target
.postMessage("pong");
38 postMessage("FAIL: unknown message: " + evt
.data
);