tor-browser

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

test_nsScriptErrorWithStack.html (1823B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>Test for 814497</title>
      4 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      5 <div id="log"></div>
      6 <script>
      7  var c = Cc;
      8 
      9  SimpleTest.waitForExplicitFinish();
     10  SimpleTest.expectUncaughtException();
     11 
     12  // /!\ Line number is important in this test,
     13  //     we are asserting the following functions line #
     14  function failingStack() {
     15    nestedFunction();
     16  }
     17  function nestedFunction() {
     18    // eslint-disable-next-line no-undef
     19    doesntExistsAndThrow();
     20  }
     21 
     22  var TestObserver = {
     23    QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
     24 
     25    observe: function test_observe(aSubject)
     26    {
     27      if (!(aSubject instanceof Ci.nsIScriptError)) {
     28        return;
     29      }
     30      dump("stack: "+aSubject.stack+"\n");
     31 
     32      // Main assertions
     33      var s = aSubject.stack;
     34      ok(!!s, "has first frame");
     35      ok(s.source.includes("test_nsScriptErrorWithStack.html"), "source is correct");
     36      is(s.line, 19, "line is correct");
     37      is(s.column, 5, "column is correct");
     38      is(s.functionDisplayName, "nestedFunction");
     39      s = s.parent;
     40      ok(!!s, "has second frame");
     41      ok(s.source.includes("test_nsScriptErrorWithStack.html"), "source is correct");
     42      is(s.line, 15, "line is correct");
     43      is(s.column, 5, "column is correct");
     44      is(s.functionDisplayName, "failingStack");
     45      // We shouldn't have any more frame as we used setTimeout
     46      ok(!s.parent, "has no more frames");
     47 
     48      // Cleanup
     49      Services.console.unregisterListener(TestObserver);
     50      SimpleTest.finish();
     51    }
     52  };
     53 
     54  Services.console.registerListener(TestObserver);
     55 
     56  // use setTimeout in order to prevent throwing from test frame
     57  // and so have a clean stack frame with just our method calls
     58  setTimeout(failingStack, 0);
     59 </script>