michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // This function should never run on a too much recursion error. michael@0: onerror = function(event) { michael@0: postMessage(event.message); michael@0: }; michael@0: michael@0: // Pure JS recursion michael@0: function recurse() { michael@0: recurse(); michael@0: } michael@0: michael@0: // JS -> C++ -> JS -> C++ recursion michael@0: function recurse2() { michael@0: var xhr = new XMLHttpRequest(); michael@0: xhr.onreadystatechange = function() { michael@0: xhr.open("GET", "nonexistent.file"); michael@0: } michael@0: xhr.open("GET", "nonexistent.file"); michael@0: } michael@0: michael@0: var messageCount = 0; michael@0: onmessage = function(event) { michael@0: switch (++messageCount) { michael@0: case 2: michael@0: recurse2(); michael@0: michael@0: // An exception thrown from an event handler like xhr.onreadystatechange michael@0: // should not leave an exception pending in the code that generated the michael@0: // event. michael@0: postMessage("Done"); michael@0: return; michael@0: michael@0: case 1: michael@0: recurse(); michael@0: throw "Exception should have prevented us from getting here!"; michael@0: michael@0: default: michael@0: throw "Weird number of messages: " + messageCount; michael@0: } michael@0: michael@0: throw "Impossible to get here!"; michael@0: }