Backed out changeset 713114c0331a (bug 1938707) by developer request CLOSED TREE
[gecko.git] / js / xpconnect / tests / chrome / test_nsScriptErrorWithStack.html
blob99a47277568684205e9fa73390cba92ccecb8901
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;
9 SimpleTest.waitForExplicitFinish();
10 SimpleTest.expectUncaughtException();
12 // /!\ Line number is important in this test,
13 // we are asserting the following functions line #
14 function failingStack() {
15 nestedFunction();
17 function nestedFunction() {
18 // eslint-disable-next-line no-undef
19 doesntExistsAndThrow();
22 var TestObserver = {
23 QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),
25 observe: function test_observe(aSubject)
27 if (!(aSubject instanceof Ci.nsIScriptError)) {
28 return;
30 dump("stack: "+aSubject.stack+"\n");
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");
48 // Cleanup
49 Services.console.unregisterListener(TestObserver);
50 SimpleTest.finish();
54 Services.console.registerListener(TestObserver);
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>