dom/workers/test/recursion_worker.js

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:96edb1199120
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
5
6 // This function should never run on a too much recursion error.
7 onerror = function(event) {
8 postMessage(event.message);
9 };
10
11 // Pure JS recursion
12 function recurse() {
13 recurse();
14 }
15
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 }
24
25 var messageCount = 0;
26 onmessage = function(event) {
27 switch (++messageCount) {
28 case 2:
29 recurse2();
30
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;
36
37 case 1:
38 recurse();
39 throw "Exception should have prevented us from getting here!";
40
41 default:
42 throw "Weird number of messages: " + messageCount;
43 }
44
45 throw "Impossible to get here!";
46 }

mercurial