PrettyPrinter handles objects with invalid toString implementations

This commit is contained in:
Elliot Nelson
2019-05-20 09:01:10 -04:00
parent e04d3d8a62
commit 9f704b6f3a
2 changed files with 29 additions and 0 deletions

View File

@@ -266,6 +266,12 @@ getJasmineRequireObj().pp = function(j$) {
};
PrettyPrinter.prototype.append = function(value) {
// This check protects us from the rare case where an object has overriden
// `toString()` with an invalid implementation (returning a non-string).
if (typeof value !== 'string') {
value = Object.prototype.toString.call(value);
}
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
this.length += result.value.length;
this.stringParts.push(result.value);