services/common/tests/unit/test_utils_stackTrace.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:89e5d24740e0
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 _("Define some functions in well defined line positions for the test");
5 function foo(v) bar(v + 1); // line 2
6 function bar(v) baz(v + 1); // line 3
7 function baz(v) { throw new Error(v + 1); } // line 4
8
9 _("Make sure lazy constructor calling/assignment works");
10 Cu.import("resource://services-common/utils.js");
11
12 function run_test() {
13 _("Make sure functions, arguments, files are pretty printed in the trace");
14 let trace = "";
15 try {
16 foo(0);
17 }
18 catch(ex) {
19 trace = CommonUtils.stackTrace(ex);
20 }
21 _("Got trace:", trace);
22 do_check_neq(trace, "");
23
24 let bazPos = trace.indexOf("baz@test_utils_stackTrace.js:7");
25 let barPos = trace.indexOf("bar@test_utils_stackTrace.js:6");
26 let fooPos = trace.indexOf("foo@test_utils_stackTrace.js:5");
27 _("String positions:", bazPos, barPos, fooPos);
28
29 _("Make sure the desired messages show up");
30 do_check_true(bazPos >= 0);
31 do_check_true(barPos > bazPos);
32 do_check_true(fooPos > barPos);
33 }

mercurial