1 // Check to see if the worker handles pending events. Messages after close() will not be sent to the parent page, so we use exceptions instead to report failures after close().
2 onmessage = function(evt)
4 if (evt.data == "closeWithPendingEvents") {
5 // Set a timer to generate an event - minimum timeout is 1ms.
6 setTimeout(function() {
7 postMessage("pending event processed");
8 throw "should not be executed";
10 var start = new Date().getTime();
11 // Loop for 10 ms so the timer is ready to fire
12 while (new Date().getTime() - start < 100)
14 // Now close - timer should not fire
16 } else if (evt.data == "typeofClose") {
17 postMessage("typeof close: " + (typeof close));
18 } else if (evt.data == "close") {
20 postMessage("Should be delivered");
21 } else if (evt.data == "ping") {
23 } else if (evt.data == "throw") {
24 throw "should never be executed";
25 } else if (evt.data == "closeWithError") {
27 nonExistentFunction(); // Undefined function - throws exception
28 } else if (evt.data == "close_post_loop") {
30 postMessage("closed");
31 while(true) {} // Should loop forever.
32 } else if (evt.data == "take_port") {
33 messagePort = evt.ports[0];
34 messagePort.onmessage = function(event) {
36 postMessage("echo_" + event.data);
38 } else if (evt.data == "start_port") {
41 postMessage("FAIL: Unknown message type: " + evt.data);