If 'compactFormat' argument is passed in the request the response won't include referenced mirrors in the refs section instead each protocol reference object will contain some details necessary for displaying the referenced object in the graphical debugger when the object is not expanded. That allows to request full information lazily when the object is expanded.

Review URL: http://codereview.chromium.org/115401

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1977 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yurys@chromium.org 2009-05-15 15:52:37 +00:00
parent e097183f22
commit 6a350c86bf
2 changed files with 69 additions and 8 deletions

View File

@ -1462,6 +1462,9 @@ DebugCommandProcessor.prototype.backtraceRequest_ = function(request, response)
if (from_index < 0 || to_index < 0) { if (from_index < 0 || to_index < 0) {
return response.failed('Invalid frame number'); return response.failed('Invalid frame number');
} }
if (request.arguments.compactFormat) {
response.setOption('compactFormat', true);
}
} }
// Adjust the index. // Adjust the index.
@ -1590,6 +1593,10 @@ DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) {
response.setOption('includeSource', includeSource); response.setOption('includeSource', includeSource);
} }
if (request.arguments.compactFormat) {
response.setOption('compactFormat', true);
}
// Lookup handles. // Lookup handles.
var mirrors = {}; var mirrors = {};
for (var i = 0; i < handles.length; i++) { for (var i = 0; i < handles.length; i++) {

View File

@ -1752,6 +1752,11 @@ JSONProtocolSerializer.prototype.includeSource_ = function() {
} }
JSONProtocolSerializer.prototype.compactFormat_ = function() {
return this.options_ && this.options_.compactFormat;
}
JSONProtocolSerializer.prototype.add_ = function(mirror) { JSONProtocolSerializer.prototype.add_ = function(mirror) {
// If this mirror is already in the list just return. // If this mirror is already in the list just return.
for (var i = 0; i < this.mirrors_.length; i++) { for (var i = 0; i < this.mirrors_.length; i++) {
@ -1765,15 +1770,59 @@ JSONProtocolSerializer.prototype.add_ = function(mirror) {
} }
/**
* Formats mirror object to protocol reference object with some data that can
* be used to display the value in debugger.
* @param {Mirror} mirror Mirror to serialize.
* @return {Object} Protocol reference object.
*/
JSONProtocolSerializer.prototype.serializeReferenceWithDisplayData_ =
function(mirror) {
var o = {};
o.ref = mirror.handle();
o.type = mirror.type();
switch (mirror.type()) {
case UNDEFINED_TYPE:
case NULL_TYPE:
case BOOLEAN_TYPE:
case NUMBER_TYPE:
o.value = mirror.value();
break;
case STRING_TYPE:
// Limit string length.
o.value = mirror.toText();
break;
case FUNCTION_TYPE:
o.name = mirror.name();
o.inferredName = mirror.inferredName();
if (mirror.script()) {
o.scriptId = mirror.script().id();
}
break;
case ERROR_TYPE:
case REGEXP_TYPE:
o.value = mirror.toText();
break;
case OBJECT_TYPE:
o.className = mirror.className();
break;
}
return o;
};
JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference,
details) { details) {
// If serializing a reference to a mirror just return the reference and add // If serializing a reference to a mirror just return the reference and add
// the mirror to the referenced mirrors. // the mirror to the referenced mirrors.
if (reference && if (reference &&
(mirror.isValue() || mirror.isScript() || mirror.isContext())) { (mirror.isValue() || mirror.isScript() || mirror.isContext())) {
if (this.compactFormat_() && mirror.isValue()) {
return this.serializeReferenceWithDisplayData_(mirror);
} else {
this.add_(mirror); this.add_(mirror);
return {'ref' : mirror.handle()}; return {'ref' : mirror.handle()};
} }
}
// Collect the JSON property/value pairs. // Collect the JSON property/value pairs.
var content = {}; var content = {};
@ -1965,13 +2014,18 @@ JSONProtocolSerializer.prototype.serializeProperty_ = function(propertyMirror) {
var result = {}; var result = {};
result.name = propertyMirror.name(); result.name = propertyMirror.name();
var propertyValue = propertyMirror.value();
if (this.compactFormat_() && propertyValue.isValue()) {
result.value = this.serializeReferenceWithDisplayData_(propertyValue);
} else {
if (propertyMirror.attributes() != PropertyAttribute.None) { if (propertyMirror.attributes() != PropertyAttribute.None) {
result.attributes = propertyMirror.attributes(); result.attributes = propertyMirror.attributes();
} }
if (propertyMirror.propertyType() != PropertyType.Normal) { if (propertyMirror.propertyType() != PropertyType.Normal) {
result.propertyType = propertyMirror.propertyType(); result.propertyType = propertyMirror.propertyType();
} }
result.ref = propertyMirror.value().handle(); result.ref = propertyValue.handle();
}
return result; return result;
} }