services/common/tests/unit/test_utils_stackTrace.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial