dom/workers/test/threadTimeouts_worker.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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;
     9 function timeoutFunc() {
    10   if (++gTimeoutCount > 1) {
    11     throw new Error("Timeout called more than once!");
    12   }
    13   postMessage("timeoutFinished");
    14 }
    16 function intervalFunc() {
    17   if (++gIntervalCount == 2) {
    18     postMessage("intervalFinished");
    19   }
    20 }
    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 }
    44 addEventListener("message", messageListener, false);

mercurial