зеркало из https://github.com/mozilla/gecko-dev.git
Bug 966681: improve robustness of error reporting. r=Unfocused
This commit is contained in:
Родитель
7e7788903b
Коммит
453d6a09c2
|
@ -57,9 +57,21 @@ function truncate(text, newLength = kTruncateLength) {
|
|||
}
|
||||
|
||||
function getMessage(error) {
|
||||
return truncate(JSON.stringify(error.actual, replacer)) + " " +
|
||||
(error.operator ? error.operator + " " : "") +
|
||||
truncate(JSON.stringify(error.expected, replacer));
|
||||
let actual, expected;
|
||||
// Wrap calls to JSON.stringify in try...catch blocks, as they may throw. If
|
||||
// so, fall back to toString().
|
||||
try {
|
||||
actual = JSON.stringify(error.actual, replacer);
|
||||
} catch (ex) {
|
||||
actual = Object.prototype.toString.call(error.actual);
|
||||
}
|
||||
try {
|
||||
expected = JSON.stringify(error.expected, replacer);
|
||||
} catch (ex) {
|
||||
expected = Object.prototype.toString.call(error.expected);
|
||||
}
|
||||
return truncate(actual) + " " + (error.operator ? error.operator + " " : "") +
|
||||
truncate(expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -288,4 +288,15 @@ function run_test() {
|
|||
deepEqual(/a/igm, /a/igm, "deep equal should work on RegExp");
|
||||
deepEqual({a: 4, b: "1"}, {b: "1", a: 4}, "deep equal should work on regular Object");
|
||||
deepEqual(a1, a2, "deep equal should work on Array with Object properties");
|
||||
|
||||
// Test robustness of reporting:
|
||||
equal(new ns.Assert.AssertionError({
|
||||
actual: {
|
||||
toJSON: function() {
|
||||
throw "bam!";
|
||||
}
|
||||
},
|
||||
expected: "foo",
|
||||
operator: "="
|
||||
}).message, "[object Object] = \"foo\"");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче