|
1 /* -*- Mode: js; js-indent-level: 2; -*- */ |
|
2 /* Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
4 |
|
5 // Test DevToolsUtils.safeErrorString |
|
6 |
|
7 function run_test() { |
|
8 test_with_error(); |
|
9 test_with_tricky_error(); |
|
10 test_with_string(); |
|
11 test_with_thrower(); |
|
12 test_with_psychotic(); |
|
13 } |
|
14 |
|
15 function test_with_error() { |
|
16 let s = DevToolsUtils.safeErrorString(new Error("foo bar")); |
|
17 // Got the message. |
|
18 do_check_true(s.contains("foo bar")); |
|
19 // Got the stack. |
|
20 do_check_true(s.contains("test_with_error")) |
|
21 do_check_true(s.contains("test_safeErrorString.js")); |
|
22 // Got the lineNumber and columnNumber. |
|
23 do_check_true(s.contains("Line")); |
|
24 do_check_true(s.contains("column")); |
|
25 } |
|
26 |
|
27 function test_with_tricky_error() { |
|
28 let e = new Error("batman"); |
|
29 e.stack = { toString: Object.create(null) }; |
|
30 let s = DevToolsUtils.safeErrorString(e); |
|
31 // Still got the message, despite a bad stack property. |
|
32 do_check_true(s.contains("batman")); |
|
33 } |
|
34 |
|
35 function test_with_string() { |
|
36 let s = DevToolsUtils.safeErrorString("not really an error"); |
|
37 // Still get the message. |
|
38 do_check_true(s.contains("not really an error")); |
|
39 } |
|
40 |
|
41 function test_with_thrower() { |
|
42 let s = DevToolsUtils.safeErrorString({ |
|
43 toString: () => { |
|
44 throw new Error("Muahahaha"); |
|
45 } |
|
46 }); |
|
47 // Still don't fail, get string back. |
|
48 do_check_eq(typeof s, "string"); |
|
49 } |
|
50 |
|
51 function test_with_psychotic() { |
|
52 let s = DevToolsUtils.safeErrorString({ |
|
53 toString: () => Object.create(null) |
|
54 }); |
|
55 // Still get a string out, and no exceptions thrown |
|
56 do_check_eq(typeof s, "string"); |
|
57 } |