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

Commit d666c99

Browse files
Now status messages include config values (#177)
Now if a status message referes to a configuration option the syntax `configname=configvalue` will be used to specify the configuration option's name as well as its value. Also deleted the item at the `DATA_LIMIT_MESSAGE_INDEX` index in the `MESSAGE_TABLE` since it is no longer needed. PR-URL: [177](#177)
1 parent 36d9a7b commit d666c99

File tree

2 files changed

+56
-38
lines changed

2 files changed

+56
-38
lines changed

lib/state.js

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,6 @@ var NATIVE_PROPERTY_MESSAGE_INDEX = 1;
4040
var GETTER_MESSAGE_INDEX = 2;
4141
var ARG_LOCAL_LIMIT_MESSAGE_INDEX = 3;
4242
var STRING_LIMIT_MESSAGE_INDEX = 4;
43-
var DATA_LIMIT_MESSAGE_INDEX = 5;
44-
45-
var MESSAGE_TABLE = [];
46-
MESSAGE_TABLE[BUFFER_FULL_MESSAGE_INDEX] =
47-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
48-
'Max data size reached', true) };
49-
MESSAGE_TABLE[NATIVE_PROPERTY_MESSAGE_INDEX] =
50-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
51-
'Native properties are not available', true) };
52-
MESSAGE_TABLE[GETTER_MESSAGE_INDEX] =
53-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
54-
'Properties with getters are not available', true) };
55-
MESSAGE_TABLE[ARG_LOCAL_LIMIT_MESSAGE_INDEX] =
56-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
57-
'Locals and arguments are only displayed for the ' +
58-
'top `config.capture.maxExpandFrames` stack frames.',
59-
true) };
60-
MESSAGE_TABLE[STRING_LIMIT_MESSAGE_INDEX] =
61-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
62-
'Only first `config.capture.maxStringLength` chars' +
63-
' were captured.',
64-
false) };
65-
MESSAGE_TABLE[DATA_LIMIT_MESSAGE_INDEX] =
66-
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
67-
'Truncating the results because the cap of ' +
68-
'`config.capture.maxDataSize` has been reached.',
69-
false) };
7043

7144
/**
7245
* Captures the stack and current execution state.
@@ -128,8 +101,32 @@ function StateResolver(execState, expressions, config, v8) {
128101
this.evaluatedExpressions_ = [];
129102
this.totalSize_ = 0;
130103

131-
this.resolvedVariableTable_ = util._extend([], MESSAGE_TABLE);
132-
this.rawVariableTable_ = MESSAGE_TABLE.map(function() { return null; });
104+
this.messageTable_ = [];
105+
this.messageTable_[BUFFER_FULL_MESSAGE_INDEX] =
106+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
107+
'Max data size reached', true) };
108+
this.messageTable_[NATIVE_PROPERTY_MESSAGE_INDEX] =
109+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
110+
'Native properties are not available', true) };
111+
this.messageTable_[GETTER_MESSAGE_INDEX] =
112+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
113+
'Properties with getters are not available', true) };
114+
this.messageTable_[ARG_LOCAL_LIMIT_MESSAGE_INDEX] =
115+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
116+
'Locals and arguments are only displayed for the ' +
117+
'top `config.capture.maxExpandFrames=' +
118+
config.capture.maxExpandFrames +
119+
'` stack frames.',
120+
true) };
121+
this.messageTable_[STRING_LIMIT_MESSAGE_INDEX] =
122+
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
123+
'Only first `config.capture.maxStringLength=' +
124+
config.capture.maxStringLength +
125+
'` chars were captured.',
126+
false) };
127+
128+
this.resolvedVariableTable_ = util._extend([], this.messageTable_);
129+
this.rawVariableTable_ = this.messageTable_.map(function() { return null; });
133130
}
134131

135132

@@ -167,7 +164,7 @@ StateResolver.prototype.capture_ = function() {
167164
var frames = that.resolveFrames_();
168165

169166
// Now resolve the variables
170-
var index = MESSAGE_TABLE.length; // skip the sentinel values
167+
var index = this.messageTable_.length; // skip the sentinel values
171168
var noLimit = that.config_.capture.maxDataSize === 0;
172169
while (index < that.rawVariableTable_.length && // NOTE: length changes in loop
173170
(that.totalSize_ < that.config_.capture.maxDataSize || noLimit)) {
@@ -201,12 +198,13 @@ StateResolver.prototype.capture_ = function() {
201198
StateResolver.prototype.trimVariableTable_ = function(fromIndex, frames) {
202199
this.resolvedVariableTable_.splice(fromIndex); // remove the remaining entries
203200

201+
var that = this;
204202
var processBufferFull = function(variables) {
205203
variables.forEach(function (variable) {
206204
if (variable.varTableIndex && variable.varTableIndex >= fromIndex) {
207205
// make it point to the sentinel 'buffer full' value
208206
variable.varTableIndex = BUFFER_FULL_MESSAGE_INDEX;
209-
variable.status = MESSAGE_TABLE[BUFFER_FULL_MESSAGE_INDEX].status;
207+
variable.status = that.messageTable_[BUFFER_FULL_MESSAGE_INDEX].status;
210208
}
211209
if (variable.members) {
212210
processBufferFull(variable.members);
@@ -463,7 +461,7 @@ StateResolver.prototype.resolveVariable_ = function(name, value) {
463461
var maxLength = this.config_.capture.maxStringLength;
464462
if (maxLength && maxLength < data.value.length) {
465463
data.value = data.value.substring(0, maxLength) + '...';
466-
data.status = MESSAGE_TABLE[STRING_LIMIT_MESSAGE_INDEX].status;
464+
data.status = this.messageTable_[STRING_LIMIT_MESSAGE_INDEX].status;
467465
}
468466

469467
} else if (value.isFunction()) {
@@ -533,8 +531,9 @@ StateResolver.prototype.resolveMirrorSlow_ = function(mirror) {
533531
return that.resolveMirrorProperty_(mirror.property(prop));
534532
});
535533
if (truncate) {
536-
members.push({name: 'Only first `config.capture.maxProperties` ' +
537-
'properties were captured'});
534+
members.push({name: 'Only first `config.capture.maxProperties=' +
535+
this.config_.capture.maxProperties +
536+
'` properties were captured'});
538537
}
539538

540539
var mirrorVal = mirror.value();
@@ -558,7 +557,9 @@ StateResolver.prototype.resolveMirrorFast_ = function(mirror) {
558557
}
559558
var members = properties.map(this.resolveMirrorProperty_.bind(this));
560559
if (truncate) {
561-
members.push({name: 'Only first maxProperties properties were captured'});
560+
members.push({name: 'Only first `config.capture.maxProperties=' +
561+
this.config_.capture.maxProperties +
562+
'` properties were captured'});
562563
}
563564
return {
564565
value: mirror.toText(),

test/test-v8debugapi.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,23 @@ describe('v8debugapi', function() {
544544
assert.ifError(err);
545545
assert.ok(bp.stackFrames);
546546
assert.ok(bp.variableTable);
547-
548547
var topFrame = bp.stackFrames[0];
549548
assert.ok(topFrame);
550549
assert.equal(topFrame['function'], 'foo');
551550
assert.equal(topFrame.arguments.length, 1);
552551
var argsVal = bp.variableTable[topFrame.arguments[0].varTableIndex];
553552
assert(argsVal.status.isError);
553+
assert(argsVal.status.description.format.indexOf(
554+
'Locals and arguments are only displayed') !== -1);
555+
assert(argsVal.status.description.format.indexOf(
556+
'config.capture.maxExpandFrames=0') !== -1);
554557
assert.equal(topFrame.locals.length, 1);
555558
var localsVal = bp.variableTable[topFrame.locals[0].varTableIndex];
556559
assert(localsVal.status.isError);
560+
assert(localsVal.status.description.format.indexOf(
561+
'Locals and arguments are only displayed') !== -1);
562+
assert(localsVal.status.description.format.indexOf(
563+
'config.capture.maxExpandFrames=0') !== -1);
557564
api.clear(bp);
558565
config.capture.maxExpandFrames = oldCount;
559566
done();
@@ -732,9 +739,15 @@ describe('v8debugapi', function() {
732739
assert.ifError(err);
733740
var hasGetter = bp.evaluatedExpressions[0];
734741
var getterVal = bp.variableTable[hasGetter.varTableIndex];
735-
assert(getterVal.members.some(function(m) {
742+
var stringItems = getterVal.members.filter(function(m) {
736743
return m.value === 'hel...';
737-
}));
744+
});
745+
assert(stringItems.length === 1);
746+
747+
var item = stringItems[0];
748+
assert(item.status.description.format.indexOf('Only first') !== -1);
749+
assert(item.status.description.format.indexOf(
750+
'config.capture.maxStringLength=3') !== -1);
738751

739752
api.clear(bp);
740753
config.capture.maxDataSize = oldMaxData;
@@ -762,6 +775,8 @@ describe('v8debugapi', function() {
762775
// should have 1 element + truncation message.
763776
assert.equal(fooVal.members.length, 2);
764777
assert(fooVal.members[1].name.indexOf('Only first') !== -1);
778+
assert(fooVal.members[1].name.indexOf(
779+
'config.capture.maxProperties=1') !== -1);
765780

766781
api.clear(bp);
767782
config.capture.maxProperties = oldMax;
@@ -788,6 +803,8 @@ describe('v8debugapi', function() {
788803
// should have 1 element + truncation message
789804
assert.equal(fooVal.members.length, 2);
790805
assert(fooVal.members[1].name.indexOf('Only first') !== -1);
806+
assert(fooVal.members[1].name.indexOf(
807+
'config.capture.maxProperties=1') !== -1);
791808

792809
api.clear(bp);
793810
config.capture.maxProperties = oldMax;

0 commit comments

Comments
 (0)