Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 4828bee

Browse files
author
Matt Loring
committed
Enable maxStringLength config option
1 parent c0f3350 commit 4828bee

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ module.exports = {
5858
// based on the length of names and values of the properties. This should
5959
// be somewhat proportional to the amount of processing needed to capture
6060
// the data and subsequently the network traffic.
61-
maxDataSize: 20000
61+
maxDataSize: 20000,
6262

6363
// To limit the size of the buffer, we truncate long strings.
6464
// A value of 0 disables truncation.
65-
// TODO: implement
66-
//maxStringLength: 80
65+
maxStringLength: 0
6766
},
6867

6968
// These configuration options are for internal experimentation only.

lib/state.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ StateResolver.prototype.resolveVariable_ = function(name, value) {
314314
if (value.isPrimitive() || value.isRegExp()) {
315315
// primitives: undefined, null, boolean, number, string, symbol
316316
data.value = value.toText();
317+
var maxLength = this.config_.capture.maxStringLength;
318+
if (maxLength) {
319+
data.value = data.value.substring(0, maxLength) + '...';
320+
}
317321

318322
} else if (value.isFunction()) {
319323
data.value = 'function ' + this.resolveFunctionName_(value) + '()';

test/test-v8debugapi.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/*4*/ return n+42;
55
/*5*/}
66
/*6*/function getterObject() {
7-
/*7*/ var hasGetter = { _a: 5, get a() { return this._a; } };
7+
/*7*/ var hasGetter = { _a: 5, get a() { return this._a; }, b: 'hello world' };
88
/*8*/ return hasGetter.a;
99
/*9*/}
1010
/**
@@ -372,6 +372,32 @@ describe('v8debugapi', function() {
372372
});
373373
});
374374

375+
it('should limit string length', function(done) {
376+
var bp = {
377+
id: 'fake-id-124',
378+
location: { path: 'test-v8debugapi.js', line: 8 },
379+
expressions: ['hasGetter']
380+
};
381+
var oldMax = config.capture.maxStringLength;
382+
config.capture.maxStringLength = 3;
383+
api.set(bp, function(err) {
384+
assert.ifError(err);
385+
api.wait(bp, function(err) {
386+
assert.ifError(err);
387+
var hasGetter = bp.evaluatedExpressions[0];
388+
var getterVal = bp.variableTable[hasGetter.varTableIndex];
389+
assert(getterVal.members.some(function(m) {
390+
return m.value === 'hel...';
391+
}));
392+
393+
api.clear(bp);
394+
config.capture.maxStringLength = oldMax;
395+
done();
396+
});
397+
process.nextTick(function() {getterObject();});
398+
});
399+
});
400+
375401
it('should capture without values for invalid watch expressions', function(done) {
376402
// clone a clean breakpointInFoo
377403
var bp = {

0 commit comments

Comments
 (0)