tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_async_setTimeout_stack_across_globals.html (1663B)


      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  <iframe id="iframe"></iframe>
     16  <script type="application/javascript">
     17  SimpleTest.waitForExplicitFinish();
     18 
     19  var otherGlobal = document.getElementById("iframe").contentWindow;
     20 
     21  function getFunctionName(frame) {
     22    return frame.slice(0, frame.indexOf("@"));
     23  }
     24 
     25  function a() { b() }
     26  function b() { c() }
     27  function c() { otherGlobal.setTimeout(d, 1) }
     28  function d() { e() }
     29  function e() { f() }
     30  function f() { otherGlobal.setTimeout(g, 1) }
     31  function g() { h() }
     32  function h() { i() }
     33  function i() {
     34    var stackString = Error().stack;
     35    document.getElementById("stack").textContent = stackString;
     36 
     37    var frames = stackString
     38            .split("\n")
     39            .map(getFunctionName)
     40            .filter(function (name) { return !!name; });
     41 
     42    is(frames[0], "i");
     43    is(frames[1], "h");
     44    is(frames[2], "g");
     45    is(frames[3], "setTimeout handler*f");
     46    is(frames[4], "e");
     47    is(frames[5], "d");
     48    is(frames[6], "setTimeout handler*c");
     49    is(frames[7], "b");
     50    is(frames[8], "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>