2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
7 var gIntervalCount = 0;
9 function timeoutFunc() {
10 if (++gTimeoutCount > 1) {
11 throw new Error("Timeout called more than once!");
13 postMessage("timeoutFinished");
16 function intervalFunc() {
17 if (++gIntervalCount == 2) {
18 postMessage("intervalFinished");
22 function messageListener(event) {
25 gTimeoutId = setTimeout(timeoutFunc, 2000);
26 clearTimeout(gTimeoutId);
27 gTimeoutId = setTimeout(timeoutFunc, 2000);
30 gTimeoutId = setInterval(intervalFunc, 2000);
32 case "cancelInterval":
33 clearInterval(gTimeoutId);
34 postMessage("intervalCanceled");
36 case "startExpression":
37 // eslint-disable-next-line no-implied-eval
38 setTimeout("this.postMessage('expressionFinished');", 2000);
41 throw "Bad message: " + event.data;
45 addEventListener("message", messageListener, false);