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

Commit

Permalink
Now status messages include config values (#177)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
DominicKramer committed Nov 19, 2016
1 parent 36d9a7b commit d666c99
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 38 deletions.
71 changes: 36 additions & 35 deletions lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,6 @@ var NATIVE_PROPERTY_MESSAGE_INDEX = 1;
var GETTER_MESSAGE_INDEX = 2;
var ARG_LOCAL_LIMIT_MESSAGE_INDEX = 3;
var STRING_LIMIT_MESSAGE_INDEX = 4;
var DATA_LIMIT_MESSAGE_INDEX = 5;

var MESSAGE_TABLE = [];
MESSAGE_TABLE[BUFFER_FULL_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Max data size reached', true) };
MESSAGE_TABLE[NATIVE_PROPERTY_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Native properties are not available', true) };
MESSAGE_TABLE[GETTER_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Properties with getters are not available', true) };
MESSAGE_TABLE[ARG_LOCAL_LIMIT_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Locals and arguments are only displayed for the ' +
'top `config.capture.maxExpandFrames` stack frames.',
true) };
MESSAGE_TABLE[STRING_LIMIT_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Only first `config.capture.maxStringLength` chars' +
' were captured.',
false) };
MESSAGE_TABLE[DATA_LIMIT_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Truncating the results because the cap of ' +
'`config.capture.maxDataSize` has been reached.',
false) };

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

this.resolvedVariableTable_ = util._extend([], MESSAGE_TABLE);
this.rawVariableTable_ = MESSAGE_TABLE.map(function() { return null; });
this.messageTable_ = [];
this.messageTable_[BUFFER_FULL_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Max data size reached', true) };
this.messageTable_[NATIVE_PROPERTY_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Native properties are not available', true) };
this.messageTable_[GETTER_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Properties with getters are not available', true) };
this.messageTable_[ARG_LOCAL_LIMIT_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Locals and arguments are only displayed for the ' +
'top `config.capture.maxExpandFrames=' +
config.capture.maxExpandFrames +
'` stack frames.',
true) };
this.messageTable_[STRING_LIMIT_MESSAGE_INDEX] =
{ status: new StatusMessage(StatusMessage.VARIABLE_VALUE,
'Only first `config.capture.maxStringLength=' +
config.capture.maxStringLength +
'` chars were captured.',
false) };

this.resolvedVariableTable_ = util._extend([], this.messageTable_);
this.rawVariableTable_ = this.messageTable_.map(function() { return null; });
}


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

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

var that = this;
var processBufferFull = function(variables) {
variables.forEach(function (variable) {
if (variable.varTableIndex && variable.varTableIndex >= fromIndex) {
// make it point to the sentinel 'buffer full' value
variable.varTableIndex = BUFFER_FULL_MESSAGE_INDEX;
variable.status = MESSAGE_TABLE[BUFFER_FULL_MESSAGE_INDEX].status;
variable.status = that.messageTable_[BUFFER_FULL_MESSAGE_INDEX].status;
}
if (variable.members) {
processBufferFull(variable.members);
Expand Down Expand Up @@ -463,7 +461,7 @@ StateResolver.prototype.resolveVariable_ = function(name, value) {
var maxLength = this.config_.capture.maxStringLength;
if (maxLength && maxLength < data.value.length) {
data.value = data.value.substring(0, maxLength) + '...';
data.status = MESSAGE_TABLE[STRING_LIMIT_MESSAGE_INDEX].status;
data.status = this.messageTable_[STRING_LIMIT_MESSAGE_INDEX].status;
}

} else if (value.isFunction()) {
Expand Down Expand Up @@ -533,8 +531,9 @@ StateResolver.prototype.resolveMirrorSlow_ = function(mirror) {
return that.resolveMirrorProperty_(mirror.property(prop));
});
if (truncate) {
members.push({name: 'Only first `config.capture.maxProperties` ' +
'properties were captured'});
members.push({name: 'Only first `config.capture.maxProperties=' +
this.config_.capture.maxProperties +
'` properties were captured'});
}

var mirrorVal = mirror.value();
Expand All @@ -558,7 +557,9 @@ StateResolver.prototype.resolveMirrorFast_ = function(mirror) {
}
var members = properties.map(this.resolveMirrorProperty_.bind(this));
if (truncate) {
members.push({name: 'Only first maxProperties properties were captured'});
members.push({name: 'Only first `config.capture.maxProperties=' +
this.config_.capture.maxProperties +
'` properties were captured'});
}
return {
value: mirror.toText(),
Expand Down
23 changes: 20 additions & 3 deletions test/test-v8debugapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,16 +544,23 @@ describe('v8debugapi', function() {
assert.ifError(err);
assert.ok(bp.stackFrames);
assert.ok(bp.variableTable);

var topFrame = bp.stackFrames[0];
assert.ok(topFrame);
assert.equal(topFrame['function'], 'foo');
assert.equal(topFrame.arguments.length, 1);
var argsVal = bp.variableTable[topFrame.arguments[0].varTableIndex];
assert(argsVal.status.isError);
assert(argsVal.status.description.format.indexOf(
'Locals and arguments are only displayed') !== -1);
assert(argsVal.status.description.format.indexOf(
'config.capture.maxExpandFrames=0') !== -1);
assert.equal(topFrame.locals.length, 1);
var localsVal = bp.variableTable[topFrame.locals[0].varTableIndex];
assert(localsVal.status.isError);
assert(localsVal.status.description.format.indexOf(
'Locals and arguments are only displayed') !== -1);
assert(localsVal.status.description.format.indexOf(
'config.capture.maxExpandFrames=0') !== -1);
api.clear(bp);
config.capture.maxExpandFrames = oldCount;
done();
Expand Down Expand Up @@ -732,9 +739,15 @@ describe('v8debugapi', function() {
assert.ifError(err);
var hasGetter = bp.evaluatedExpressions[0];
var getterVal = bp.variableTable[hasGetter.varTableIndex];
assert(getterVal.members.some(function(m) {
var stringItems = getterVal.members.filter(function(m) {
return m.value === 'hel...';
}));
});
assert(stringItems.length === 1);

var item = stringItems[0];
assert(item.status.description.format.indexOf('Only first') !== -1);
assert(item.status.description.format.indexOf(
'config.capture.maxStringLength=3') !== -1);

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

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

api.clear(bp);
config.capture.maxProperties = oldMax;
Expand Down

0 comments on commit d666c99

Please sign in to comment.