test_async_setTimeout_stack.html (1710B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1142577 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 1142577 - Async stacks for setTimeout</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1142577">Mozilla Bug 1142577</a> 14 <pre id="stack"></pre> 15 <script type="application/javascript"> 16 SimpleTest.waitForExplicitFinish(); 17 SimpleTest.requestFlakyTimeout("Testing async stacks across setTimeout"); 18 19 function getFunctionName(frame) { 20 return frame.slice(0, frame.indexOf("@")); 21 } 22 23 function a() { b() } 24 function b() { c() } 25 function c() { setTimeout(d, 1) } 26 function d() { e() } 27 function e() { f() } 28 function f() { setTimeout(g, 1) } 29 function g() { h() } 30 function h() { i() } 31 function i() { 32 var stackString = Error().stack; 33 document.getElementById("stack").textContent = stackString; 34 35 var frames = stackString 36 .split("\n") 37 .map(getFunctionName) 38 .filter(function (name) { return !!name; }); 39 40 is(frames[0], "i"); 41 is(frames[1], "h"); 42 is(frames[2], "g"); 43 is(frames[3], "setTimeout handler*SimpleTest_setTimeoutShim"); 44 is(frames[4], "f"); 45 is(frames[5], "e"); 46 is(frames[6], "d"); 47 is(frames[7], "setTimeout handler*SimpleTest_setTimeoutShim"); 48 is(frames[8], "c"); 49 is(frames[9], "b"); 50 is(frames[10], "a"); 51 52 SimpleTest.finish(); 53 } 54 55 SpecialPowers.pushPrefEnv( 56 {"set": [['javascript.options.asyncstack_capture_debuggee_only', false]]}, 57 a); 58 </script> 59 </body> 60 </html>