dom/workers/test/threadTimeouts_worker.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:22efda73fd96
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
5 var gTimeoutId;
6 var gTimeoutCount = 0;
7 var gIntervalCount = 0;
8
9 function timeoutFunc() {
10 if (++gTimeoutCount > 1) {
11 throw new Error("Timeout called more than once!");
12 }
13 postMessage("timeoutFinished");
14 }
15
16 function intervalFunc() {
17 if (++gIntervalCount == 2) {
18 postMessage("intervalFinished");
19 }
20 }
21
22 function messageListener(event) {
23 switch (event.data) {
24 case "startTimeout":
25 gTimeoutId = setTimeout(timeoutFunc, 2000);
26 clearTimeout(gTimeoutId);
27 gTimeoutId = setTimeout(timeoutFunc, 2000);
28 break;
29 case "startInterval":
30 gTimeoutId = setInterval(intervalFunc, 2000);
31 break;
32 case "cancelInterval":
33 clearInterval(gTimeoutId);
34 postMessage("intervalCanceled");
35 break;
36 case "startExpression":
37 setTimeout("this.postMessage('expressionFinished');", 2000);
38 break;
39 default:
40 throw "Bad message: " + event.data;
41 }
42 }
43
44 addEventListener("message", messageListener, false);

mercurial