dom/workers/test/recursion_worker.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/test/recursion_worker.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +/**
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +// This function should never run on a too much recursion error.
    1.10 +onerror = function(event) {
    1.11 +  postMessage(event.message);
    1.12 +};
    1.13 +
    1.14 +// Pure JS recursion
    1.15 +function recurse() {
    1.16 +  recurse();
    1.17 +}
    1.18 +
    1.19 +// JS -> C++ -> JS -> C++ recursion
    1.20 +function recurse2() {
    1.21 +  var xhr = new XMLHttpRequest();
    1.22 +  xhr.onreadystatechange = function() {
    1.23 +    xhr.open("GET", "nonexistent.file");
    1.24 +  }
    1.25 +  xhr.open("GET", "nonexistent.file");
    1.26 +}
    1.27 +
    1.28 +var messageCount = 0;
    1.29 +onmessage = function(event) {
    1.30 +  switch (++messageCount) {
    1.31 +    case 2:
    1.32 +      recurse2();
    1.33 +
    1.34 +      // An exception thrown from an event handler like xhr.onreadystatechange
    1.35 +      // should not leave an exception pending in the code that generated the
    1.36 +      // event.
    1.37 +      postMessage("Done");
    1.38 +      return;
    1.39 +
    1.40 +    case 1:
    1.41 +      recurse();
    1.42 +      throw "Exception should have prevented us from getting here!";
    1.43 +
    1.44 +    default:
    1.45 +      throw "Weird number of messages: " + messageCount;
    1.46 +  }
    1.47 +
    1.48 +  throw "Impossible to get here!";
    1.49 +}

mercurial