diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/tests/xpcshell/test_safeErrorString.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/tests/xpcshell/test_safeErrorString.js')
-rw-r--r-- | devtools/shared/tests/xpcshell/test_safeErrorString.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/devtools/shared/tests/xpcshell/test_safeErrorString.js b/devtools/shared/tests/xpcshell/test_safeErrorString.js new file mode 100644 index 0000000000..1d2e5431ed --- /dev/null +++ b/devtools/shared/tests/xpcshell/test_safeErrorString.js @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Test DevToolsUtils.safeErrorString + +function run_test() { + test_with_error(); + test_with_tricky_error(); + test_with_string(); + test_with_thrower(); + test_with_psychotic(); +} + +function test_with_error() { + const s = DevToolsUtils.safeErrorString(new Error("foo bar")); + // Got the message. + Assert.ok(s.includes("foo bar")); + // Got the stack. + Assert.ok(s.includes("test_with_error")); + Assert.ok(s.includes("test_safeErrorString.js")); + // Got the lineNumber and columnNumber. + Assert.ok(s.includes("Line")); + Assert.ok(s.includes("column")); +} + +function test_with_tricky_error() { + const e = new Error("batman"); + e.stack = { toString: Object.create(null) }; + const s = DevToolsUtils.safeErrorString(e); + // Still got the message, despite a bad stack property. + Assert.ok(s.includes("batman")); +} + +function test_with_string() { + const s = DevToolsUtils.safeErrorString("not really an error"); + // Still get the message. + Assert.ok(s.includes("not really an error")); +} + +function test_with_thrower() { + const s = DevToolsUtils.safeErrorString({ + toString: () => { + throw new Error("Muahahaha"); + }, + }); + // Still don't fail, get string back. + Assert.equal(typeof s, "string"); +} + +function test_with_psychotic() { + const s = DevToolsUtils.safeErrorString({ + toString: () => Object.create(null), + }); + // Still get a string out, and no exceptions thrown + Assert.equal(typeof s, "string"); + Assert.equal(s, "[object Object]"); +} |