Stop serializing objects after hitting jasmine.MAX_PRETTY_PRINT_CHARS
This commit is contained in:
@@ -57,6 +57,10 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
} else {
|
||||
this.emitScalar(value.toString());
|
||||
}
|
||||
} catch (e) {
|
||||
if (this.ppNestLevel_ > 1 || !(e instanceof MaxCharsReachedError)) {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
this.ppNestLevel_--;
|
||||
}
|
||||
@@ -236,22 +240,31 @@ getJasmineRequireObj().pp = function(j$) {
|
||||
};
|
||||
|
||||
StringPrettyPrinter.prototype.append = function(value) {
|
||||
if (this.length < j$.MAX_PRETTY_PRINT_CHARS) {
|
||||
value = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||
this.length += value.length;
|
||||
this.stringParts.push(value);
|
||||
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||
this.length += result.value.length;
|
||||
this.stringParts.push(result.value);
|
||||
|
||||
if (result.truncated) {
|
||||
throw new MaxCharsReachedError();
|
||||
}
|
||||
};
|
||||
|
||||
function truncate(s, maxlen) {
|
||||
if (s.length <= maxlen) {
|
||||
return s;
|
||||
return { value: s, truncated: false };
|
||||
}
|
||||
|
||||
s = s.substring(0, maxlen - 4);
|
||||
return s + ' ...';
|
||||
s = s.substring(0, maxlen - 4) + ' ...';
|
||||
return { value: s, truncated: true };
|
||||
}
|
||||
|
||||
function MaxCharsReachedError() {
|
||||
this.message = 'Exceeded ' + j$.MAX_PRETTY_PRINT_CHARS +
|
||||
' characters while pretty-printing a value';
|
||||
}
|
||||
|
||||
MaxCharsReachedError.prototype = new Error();
|
||||
|
||||
function keys(obj, isArray) {
|
||||
var allKeys = Object.keys ? Object.keys(obj) :
|
||||
(function(o) {
|
||||
|
||||
Reference in New Issue
Block a user