1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/common/tests/unit/test_utils_stackTrace.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +_("Define some functions in well defined line positions for the test"); 1.8 +function foo(v) bar(v + 1); // line 2 1.9 +function bar(v) baz(v + 1); // line 3 1.10 +function baz(v) { throw new Error(v + 1); } // line 4 1.11 + 1.12 +_("Make sure lazy constructor calling/assignment works"); 1.13 +Cu.import("resource://services-common/utils.js"); 1.14 + 1.15 +function run_test() { 1.16 + _("Make sure functions, arguments, files are pretty printed in the trace"); 1.17 + let trace = ""; 1.18 + try { 1.19 + foo(0); 1.20 + } 1.21 + catch(ex) { 1.22 + trace = CommonUtils.stackTrace(ex); 1.23 + } 1.24 + _("Got trace:", trace); 1.25 + do_check_neq(trace, ""); 1.26 + 1.27 + let bazPos = trace.indexOf("baz@test_utils_stackTrace.js:7"); 1.28 + let barPos = trace.indexOf("bar@test_utils_stackTrace.js:6"); 1.29 + let fooPos = trace.indexOf("foo@test_utils_stackTrace.js:5"); 1.30 + _("String positions:", bazPos, barPos, fooPos); 1.31 + 1.32 + _("Make sure the desired messages show up"); 1.33 + do_check_true(bazPos >= 0); 1.34 + do_check_true(barPos > bazPos); 1.35 + do_check_true(fooPos > barPos); 1.36 +}