dom/workers/test/recursion_worker.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /**
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 // This function should never run on a too much recursion error.
     7 onerror = function(event) {
     8   postMessage(event.message);
     9 };
    11 // Pure JS recursion
    12 function recurse() {
    13   recurse();
    14 }
    16 // JS -> C++ -> JS -> C++ recursion
    17 function recurse2() {
    18   var xhr = new XMLHttpRequest();
    19   xhr.onreadystatechange = function() {
    20     xhr.open("GET", "nonexistent.file");
    21   }
    22   xhr.open("GET", "nonexistent.file");
    23 }
    25 var messageCount = 0;
    26 onmessage = function(event) {
    27   switch (++messageCount) {
    28     case 2:
    29       recurse2();
    31       // An exception thrown from an event handler like xhr.onreadystatechange
    32       // should not leave an exception pending in the code that generated the
    33       // event.
    34       postMessage("Done");
    35       return;
    37     case 1:
    38       recurse();
    39       throw "Exception should have prevented us from getting here!";
    41     default:
    42       throw "Weird number of messages: " + messageCount;
    43   }
    45   throw "Impossible to get here!";
    46 }

mercurial