michael@0: /* -*- Mode: js; js-indent-level: 2; -*- */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test DevToolsUtils.safeErrorString michael@0: michael@0: function run_test() { michael@0: test_with_error(); michael@0: test_with_tricky_error(); michael@0: test_with_string(); michael@0: test_with_thrower(); michael@0: test_with_psychotic(); michael@0: } michael@0: michael@0: function test_with_error() { michael@0: let s = DevToolsUtils.safeErrorString(new Error("foo bar")); michael@0: // Got the message. michael@0: do_check_true(s.contains("foo bar")); michael@0: // Got the stack. michael@0: do_check_true(s.contains("test_with_error")) michael@0: do_check_true(s.contains("test_safeErrorString.js")); michael@0: // Got the lineNumber and columnNumber. michael@0: do_check_true(s.contains("Line")); michael@0: do_check_true(s.contains("column")); michael@0: } michael@0: michael@0: function test_with_tricky_error() { michael@0: let e = new Error("batman"); michael@0: e.stack = { toString: Object.create(null) }; michael@0: let s = DevToolsUtils.safeErrorString(e); michael@0: // Still got the message, despite a bad stack property. michael@0: do_check_true(s.contains("batman")); michael@0: } michael@0: michael@0: function test_with_string() { michael@0: let s = DevToolsUtils.safeErrorString("not really an error"); michael@0: // Still get the message. michael@0: do_check_true(s.contains("not really an error")); michael@0: } michael@0: michael@0: function test_with_thrower() { michael@0: let s = DevToolsUtils.safeErrorString({ michael@0: toString: () => { michael@0: throw new Error("Muahahaha"); michael@0: } michael@0: }); michael@0: // Still don't fail, get string back. michael@0: do_check_eq(typeof s, "string"); michael@0: } michael@0: michael@0: function test_with_psychotic() { michael@0: let s = DevToolsUtils.safeErrorString({ michael@0: toString: () => Object.create(null) michael@0: }); michael@0: // Still get a string out, and no exceptions thrown michael@0: do_check_eq(typeof s, "string"); michael@0: }