Commit dc2a0ec3 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Reverted r1078 as it was committed by accident without review.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1079 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 6bc1d40a
......@@ -994,25 +994,22 @@ ResponsePacket.prototype.toJSONProtocol = function() {
if (this.body) {
json += ',"body":';
// Encode the body part.
var serializer = MakeMirrorSerializer(true);
if (this.body instanceof Mirror) {
json += serializer.serializeValue(this.body);
if (this.body.toJSONProtocol) {
json += this.body.toJSONProtocol(true);
} else if (this.body instanceof Array) {
json += '[';
for (var i = 0; i < this.body.length; i++) {
if (i != 0) json += ',';
if (this.body[i] instanceof Mirror) {
json += serializer.serializeValue(this.body[i]);
if (this.body[i].toJSONProtocol) {
json += this.body[i].toJSONProtocol(true)
} else {
json += SimpleObjectToJSON_(this.body[i], serializer);
json += SimpleObjectToJSON_(this.body[i]);
}
}
json += ']';
} else {
json += SimpleObjectToJSON_(this.body, serializer);
json += SimpleObjectToJSON_(this.body);
}
json += ',"refs":';
json += serializer.serializeReferencedObjects();
}
if (this.message) {
json += ',"message":' + StringToJSON_(this.message) ;
......@@ -1571,11 +1568,9 @@ DebugCommandProcessor.prototype.formatCFrame = function(cframe_value) {
* a general implementation but sufficient for the debugger. Note that circular
* structures will cause infinite recursion.
* @param {Object} object The object to format as JSON
* @param {MirrorSerializer} mirror_serializer The serializer to use if any
* mirror objects are encountered.
* @return {string} JSON formatted object value
*/
function SimpleObjectToJSON_(object, mirror_serializer) {
function SimpleObjectToJSON_(object) {
var content = [];
for (var key in object) {
// Only consider string keys.
......@@ -1589,9 +1584,9 @@ function SimpleObjectToJSON_(object, mirror_serializer) {
if (typeof property_value.toJSONProtocol == 'function') {
property_value_json = property_value.toJSONProtocol(true)
} else if (IS_ARRAY(property_value)){
property_value_json = SimpleArrayToJSON_(property_value, mirror_serializer);
property_value_json = SimpleArrayToJSON_(property_value);
} else {
property_value_json = SimpleObjectToJSON_(property_value, mirror_serializer);
property_value_json = SimpleObjectToJSON_(property_value);
}
break;
......@@ -1625,12 +1620,10 @@ function SimpleObjectToJSON_(object, mirror_serializer) {
/**
* Convert an array to its JSON representation. This is a VERY simple
* implementation just to support what is needed for the debugger.
* @param {Array} array The array to format as JSON
* @param {MirrorSerializer} mirror_serializer The serializer to use if any
* mirror objects are encountered.
* @param {Array} arrya The array to format as JSON
* @return {string} JSON formatted array value
*/
function SimpleArrayToJSON_(array, mirror_serializer) {
function SimpleArrayToJSON_(array) {
// Make JSON array representation.
var json = '[';
for (var i = 0; i < array.length; i++) {
......@@ -1638,8 +1631,8 @@ function SimpleArrayToJSON_(array, mirror_serializer) {
json += ',';
}
var elem = array[i];
if (elem instanceof Mirror) {
json += mirror_serializer.serializeValue(elem);
if (elem.toJSONProtocol) {
json += elem.toJSONProtocol(true)
} else if (IS_OBJECT(elem)) {
json += SimpleObjectToJSON_(elem);
} else if (IS_BOOLEAN(elem)) {
......
......@@ -1303,22 +1303,6 @@ bool Debug::IsDebugGlobal(GlobalObject* global) {
}
void Debug::ClearMirrorCache() {
ASSERT(Top::context() == *Debug::debug_context());
// Clear the mirror cache.
Handle<String> function_name =
Factory::LookupSymbol(CStrVector("ClearMirrorCache"));
Handle<Object> fun(Top::global()->GetProperty(*function_name));
ASSERT(fun->IsJSFunction());
bool caught_exception;
Handle<Object> js_object = Execution::TryCall(
Handle<JSFunction>::cast(fun),
Handle<JSObject>(Debug::debug_context()->global()),
0, NULL, &caught_exception);
}
bool Debugger::debugger_active_ = false;
bool Debugger::compiling_natives_ = false;
bool Debugger::is_loading_debugger_ = false;
......@@ -1644,9 +1628,6 @@ void Debugger::ProcessDebugEvent(v8::DebugEvent event,
}
}
}
// Clear the mirror cache.
Debug::ClearMirrorCache();
}
......
......@@ -260,9 +260,6 @@ class Debug {
static char* RestoreDebug(char* from);
static int ArchiveSpacePerThread();
// Mirror cache handling.
static void ClearMirrorCache();
// Code generation assumptions.
static const int kIa32CallInstructionLength = 5;
static const int kIa32JSReturnSequenceLength = 6;
......
......@@ -33,18 +33,6 @@ RegExp;
Date;
var next_handle_ = 0;
var mirror_cache_ = [];
/**
* Clear the mirror handle cache.
*/
function ClearMirrorCache() {
next_handle_ = 0;
mirror_cache_ = [];
}
/**
* Returns the mirror for a specified value or object.
*
......@@ -52,50 +40,17 @@ function ClearMirrorCache() {
* @returns {Mirror} the mirror reflects the passed value or object
*/
function MakeMirror(value) {
var mirror;
for (id in mirror_cache_) {
mirror = mirror_cache_[id];
if (mirror.value() === value) {
return mirror;
}
}
if (IS_UNDEFINED(value)) {
mirror = new UndefinedMirror();
} else if (IS_NULL(value)) {
mirror = new NullMirror();
} else if (IS_BOOLEAN(value)) {
mirror = new BooleanMirror(value);
} else if (IS_NUMBER(value)) {
mirror = new NumberMirror(value);
} else if (IS_STRING(value)) {
mirror = new StringMirror(value);
} else if (IS_ARRAY(value)) {
mirror = new ArrayMirror(value);
} else if (IS_DATE(value)) {
mirror = new DateMirror(value);
} else if (IS_FUNCTION(value)) {
mirror = new FunctionMirror(value);
} else if (IS_REGEXP(value)) {
mirror = new RegExpMirror(value);
} else if (IS_ERROR(value)) {
mirror = new ErrorMirror(value);
} else {
mirror = new ObjectMirror(value);
}
mirror_cache_[mirror.handle()] = mirror;
return mirror;
}
/**
* Returns the mirror for the undifined value.
*
* @returns {Mirror} the mirror reflects the undifined value
*/
function GetUndefinedMirror() {
return MakeMirror(void 0);
if (IS_UNDEFINED(value)) return new UndefinedMirror();
if (IS_NULL(value)) return new NullMirror();
if (IS_BOOLEAN(value)) return new BooleanMirror(value);
if (IS_NUMBER(value)) return new NumberMirror(value);
if (IS_STRING(value)) return new StringMirror(value);
if (IS_ARRAY(value)) return new ArrayMirror(value);
if (IS_DATE(value)) return new DateMirror(value);
if (IS_FUNCTION(value)) return new FunctionMirror(value);
if (IS_REGEXP(value)) return new RegExpMirror(value);
if (IS_ERROR(value)) return new ErrorMirror(value);
return new ObjectMirror(value);
}
......@@ -132,6 +87,7 @@ const FUNCTION_TYPE = 'function';
const REGEXP_TYPE = 'regexp';
const ERROR_TYPE = 'error';
const PROPERTY_TYPE = 'property';
const ACCESSOR_TYPE = 'accessor';
const FRAME_TYPE = 'frame';
const SCRIPT_TYPE = 'script';
......@@ -198,15 +154,6 @@ Mirror.prototype.type = function() {
};
/**
* Check whether the mirror reflects a value.
* @returns {boolean} True if the mirror reflects a value.
*/
Mirror.prototype.isValue = function() {
return this instanceof ValueMirror;
}
/**
* Check whether the mirror reflects the undefined value.
* @returns {boolean} True if the mirror reflects the undefined value.
......@@ -342,6 +289,18 @@ Mirror.prototype.isScript = function() {
}
/**
* Serialize object in JSON format. The actual serialization is handled by the
* JSONProtocolSerializer.
* @param {boolean} details Indicate level of details to include
* @return {string} JSON serialization
*/
Mirror.prototype.toJSONProtocol = function(details) {
var serializer = new JSONProtocolSerializer(details)
return serializer.serialize(this)
}
Mirror.prototype.toText = function() {
// Simpel to text which is used when on specialization in subclass.
return "#<" + builtins.GetInstanceName(this.constructor.name) + ">";
......@@ -357,17 +316,11 @@ Mirror.prototype.toText = function() {
*/
function ValueMirror(type, value) {
Mirror.call(this, type);
this.handle_ = next_handle_++;
this.value_ = value;
}
inherits(ValueMirror, Mirror);
Mirror.prototype.handle = function() {
return this.handle_;
};
/**
* Check whether this is a primitive value.
* @return {boolean} True if the mirror reflects a primitive value
......@@ -382,7 +335,7 @@ ValueMirror.prototype.isPrimitive = function() {
};
/**
/**
* Get the actual value reflected by this mirror.
* @return {value} The value reflected by this mirror
*/
......@@ -628,7 +581,7 @@ ObjectMirror.prototype.property = function(name) {
}
// Nothing found.
return GetUndefinedMirror();
return new UndefinedMirror();
};
......@@ -655,7 +608,7 @@ ObjectMirror.prototype.lookupProperty = function(value) {
}
// Nothing found.
return GetUndefinedMirror();
return new UndefinedMirror();
};
......@@ -734,6 +687,8 @@ FunctionMirror.prototype.source = function() {
// Return source if function is resolved. Otherwise just fall through to
// return undefined.
if (this.resolved()) {
// This builtins function is context independant (only uses runtime
// calls and typeof.
return builtins.FunctionSourceString(this.value_);
}
};
......@@ -808,17 +763,17 @@ UnresolvedFunctionMirror.prototype.className = function() {
UnresolvedFunctionMirror.prototype.constructorFunction = function() {
return GetUndefinedMirror();
return new UndefinedMirror();
};
UnresolvedFunctionMirror.prototype.prototypeObject = function() {
return GetUndefinedMirror();
return new UndefinedMirror();
};
UnresolvedFunctionMirror.prototype.protoObject = function() {
return GetUndefinedMirror();
return new UndefinedMirror();
};
......@@ -860,7 +815,7 @@ ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index, opt_
if (details) {
value = new PropertyMirror(this, i, details);
} else {
value = GetUndefinedMirror();
value = new UndefinedMirror();
}
values[i - from_index] = value;
}
......@@ -1270,7 +1225,7 @@ FrameMirror.prototype.func = function() {
// value returned from the VM might be a string if the function for the
// frame is unresolved.
if (IS_FUNCTION(f)) {
return MakeMirror(f);
return new FunctionMirror(f);
} else {
return new UnresolvedFunctionMirror(f);
}
......@@ -1390,7 +1345,7 @@ FrameMirror.prototype.invocationText = function() {
}
// Try to find the function as a property in the receiver. Include the
// prototype chain in the lookup.
var property = GetUndefinedMirror();
var property = new UndefinedMirror();
if (!receiver.isUndefined()) {
for (var r = receiver; !r.isNull() && property.isUndefined(); r = r.protoObject()) {
property = r.lookupProperty(func);
......@@ -1571,106 +1526,16 @@ ScriptMirror.prototype.toText = function() {
}
/**
* Returns a mirror serializer
*
* @param {boolean} details Set to true to include details
* @returns {MirrorSerializer} mirror serializer
*/
function MakeMirrorSerializer(details) {
return new JSONProtocolSerializer(details);
}
/**
* Object for serializing a mirror objects and its direct references.
* @param {boolean} details Indicates whether to include details for the mirror
* serialized
* @constructor
*/
function JSONProtocolSerializer(details) {
this.details_ = details;
this.mirrors_ = [ ];
}
/**
* Returns a serialization of an object reference. The referenced object are
* added to the serialization state.
*
* @param {Mirror} mirror The mirror to serialize
* @returns {String} JSON serialization
*/
JSONProtocolSerializer.prototype.serializeReference = function(mirror) {
return this.serialize_(mirror, true, true);
}
/**
* Returns a serialization of an object value. The referenced objects are
* added to the serialization state.
*
* @param {Mirror} mirror The mirror to serialize
* @returns {String} JSON serialization
*/
JSONProtocolSerializer.prototype.serializeValue = function(mirror) {
var json = this.serialize_(mirror, false, true);
return json;
}
/**
* Returns a serialization of all the objects referenced.
*
* @param {Mirror} mirror The mirror to serialize
* @returns {String} JSON serialization
*/
JSONProtocolSerializer.prototype.serializeReferencedObjects = function() {
// Collect the JSON serialization of the referenced objects in an array.
var content = new Array();
// Get the number of referenced objects.
var count = this.mirrors_.length;
for (var i = 0; i < count; i++) {
content.push(this.serialize_(this.mirrors_[i], false, false));
}
var json = ArrayToJSONArray_(content);
return json;
}
JSONProtocolSerializer.prototype.add_ = function(mirror) {
// If this mirror is already in the list just return.
for (var i = 0; i < this.mirrors_.length; i++) {
if (this.mirrors_[i] === mirror) {
return;
}
}
// Add the mirror to the list of mirrors to be serialized.
this.mirrors_.push(mirror);
}
JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, details) {
// If serializing a reference to a value just return the reference and add the
// mirror to the referenced mirrors.
if (reference && mirror.isValue()) {
this.add_(mirror);
return '{ref:' + mirror.handle() + '}';
}
// Collect the JSON property/value pairs in an array.
JSONProtocolSerializer.prototype.serialize = function(mirror) {
// Collect the JSON property/value pairs in a array.
var content = new Array();
// Add the handle for value mirrors.
if (mirror.isValue()) {
content.push(MakeJSONPair_('handle', NumberToJSON_(mirror.handle())));
}
// Always add the type.
// Always add the type
content.push(MakeJSONPair_('type', StringToJSON_(mirror.type())));
switch (mirror.type()) {
......@@ -1708,11 +1573,35 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, detail
case ERROR_TYPE:
case REGEXP_TYPE:
// Add object representation.
this.serializeObject_(mirror, content, details);
this.serializeObject_(mirror, content);
break;
case PROPERTY_TYPE:
throw new Error('PropertyMirror cannot be serialized independeltly')
// Properties are represented by name, value, attributes and type.
content.push(MakeJSONPair_('name',
StringToJSON_(mirror.name())));
content.push(MakeJSONPair_('value',
mirror.value().toJSONProtocol(this.details_)));
if (mirror.attributes() != PropertyAttribute.None) {
content.push(MakeJSONPair_('attributes',
NumberToJSON_(mirror.attributes())));
}
if (mirror.propertyType() != PropertyType.Normal) {
content.push(MakeJSONPair_('propertyType',
NumberToJSON_(mirror.propertyType())));
}
break;
case ACCESSOR_TYPE:
// An accessor can either be native or defined through JavaScript.
if (mirror.isNative()) {
content.push(MakeJSONPair_('native', BooleanToJSON_(true)));
} else {
content.push(MakeJSONPair_('getter',
mirror.getter().toJSONProtocol(false)));
content.push(MakeJSONPair_('setter',
mirror.setter().toJSONProtocol(false)));
}
break;
case FRAME_TYPE:
......@@ -1734,6 +1623,7 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, detail
content.push(MakeJSONPair_('scriptType',
NumberToJSON_(mirror.scriptType())));
break;
}
// Always add the text representation.
......@@ -1744,120 +1634,86 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, detail
}
/**
* Serialize object information to the following JSON format.
*
* {"className":"<class name>",
* "constructorFunction":{"ref":<number>},
* "protoObject":{"ref":<number>},
* "prototypeObject":{"ref":<number>},
* "namedInterceptor":<boolean>,
* "indexedInterceptor":<boolean>,
* "properties":[<properties>]}
*/
JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, details) {
// Add general object properties.
JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content) {
content.push(MakeJSONPair_('className',
StringToJSON_(mirror.className())));
content.push(MakeJSONPair_('constructorFunction',
this.serializeReference(mirror.constructorFunction())));
content.push(MakeJSONPair_('protoObject',
this.serializeReference(mirror.protoObject())));
content.push(MakeJSONPair_('prototypeObject',
this.serializeReference(mirror.prototypeObject())));
// Add flags to indicate whether there are interceptors.
if (this.details_) {
content.push(MakeJSONPair_('constructorFunction',
mirror.constructorFunction().toJSONProtocol(false)));
content.push(MakeJSONPair_('protoObject',
mirror.protoObject().toJSONProtocol(false)));
content.push(MakeJSONPair_('prototypeObject',
mirror.prototypeObject().toJSONProtocol(false)));
// Add properties. For arrays don't include indexed proeprties.
var kind = PropertyKind.Named;
if (!mirror.isArray()) {
kind |= PropertyKind.Indexed
}
var propertyNames = mirror.propertyNames(kind);
var x = new Array(propertyNames.length);
for (var i = 0; i < propertyNames.length; i++) {
x[i] = mirror.property(propertyNames[i]).toJSONProtocol(false);
}
content.push(MakeJSONPair_('properties', ArrayToJSONArray_(x)));
// For arrays the indexed properties are added separately and the length is
// added as well.
if (mirror.isArray()) {
var propertyNames = mirror.propertyNames(PropertyKind.Indexed);
var x = new Array(propertyNames.length);
for (var i = 0; i < propertyNames.length; i++) {
x[i] = mirror.property(propertyNames[i]).toJSONProtocol(false);
}
content.push(MakeJSONPair_('indexedProperties', ArrayToJSONArray_(x)));
// Add the array length.
content.push(MakeJSONPair_('length', NumberToJSON_(mirror.length())));
}
}
if (mirror.hasNamedInterceptor()) {
content.push(MakeJSONPair_('namedInterceptor', BooleanToJSON_(true)));
}
if (mirror.hasIndexedInterceptor()) {
content.push(MakeJSONPair_('indexedInterceptor', BooleanToJSON_(true)));
}
// Add function specific properties.
if (mirror.isFunction()) {
// Add function specific properties.
content.push(MakeJSONPair_('name', StringToJSON_(mirror.name())));
content.push(MakeJSONPair_('resolved', BooleanToJSON_(mirror.resolved())));
if (mirror.resolved()) {
if (this.details_ && mirror.resolved()) {
content.push(MakeJSONPair_('source', StringToJSON_(mirror.source())));
}
if (mirror.script()) {
content.push(MakeJSONPair_('script', this.serializeValue(mirror.script())));
content.push(MakeJSONPair_('script', mirror.script().toJSONProtocol()));
}
}
// Add date specific properties.
if (mirror.isDate()) {
} else if (mirror.isDate()) {
// Add date specific properties.
content.push(MakeJSONPair_('value', DateToJSON_(mirror.value())));
} else if (mirror.isRegExp()) {
// Add regexp specific properties.
content.push(MakeJSONPair_('source', StringToJSON_(mirror.source())));
content.push(MakeJSONPair_('global', BooleanToJSON_(mirror.global())));
content.push(MakeJSONPair_('ignoreCase',
BooleanToJSON_(mirror.ignoreCase())));
content.push(MakeJSONPair_('multiline',
BooleanToJSON_(mirror.multiline())));
} else if (mirror.isError()) {
// Add error specific properties.
content.push(MakeJSONPair_('message', StringToJSON_(mirror.message())));
}
// Add actual properties - named properties followed by indexed properties.
var propertyNames = mirror.propertyNames(PropertyKind.Named);
var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed);
var p = new Array(propertyNames.length + propertyIndexes.length);
for (var i = 0; i < propertyNames.length; i++) {
var property_mirror = mirror.property(propertyNames[i]);
p[i] = this.serializeProperty_(property_mirror);
if (details) {
this.add_(property_mirror.value());
}
}
for (var i = 0; i < propertyIndexes.length; i++) {
var property_mirror = mirror.property(propertyIndexes[i]);
p[propertyNames.length + i] = this.serializeProperty_(property_mirror);
if (details) {
this.add_(property_mirror.value());
}
}
content.push(MakeJSONPair_('properties', ArrayToJSONArray_(p)));
}
/**
* Serialize property information to the following JSON format for building the
* array of properties.
*
* {"name":"<property name>",
* "attributes":<number>,
* "propertyType":<number>,
* "ref":<number>}
*
* If the attribute for the property is PropertyAttribute.None it is not added.
* If the propertyType for the property is PropertyType.Normal it is not added.
* Here are a couple of examples.
*
* {"name":"hello","ref":1}
* {"name":"length","attributes":7,"propertyType":3,"ref":2}
*
* @param {PropertyMirror} property_mirror The property to serialize
* @returns {String} JSON serialization
*/
JSONProtocolSerializer.prototype.serializeProperty_ = function(property_mirror) {
var builder = new builtins.StringBuilder();
builder.add('{"name":');
builder.add(StringToJSON_(property_mirror.name()));
if (property_mirror.attributes() != PropertyAttribute.None) {
builder.add(',"attributes":');
builder.add(NumberToJSON_(property_mirror.attributes()));
}
if (property_mirror.propertyType() != PropertyType.Normal) {
builder.add(',"propertyType":');
builder.add(NumberToJSON_(property_mirror.propertyType()));
}
builder.add(',"ref":');
builder.add(NumberToJSON_(property_mirror.value().handle()));
builder.add('}');
return builder.generate();
}
JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
content.push(MakeJSONPair_('index', NumberToJSON_(mirror.index())));
content.push(MakeJSONPair_('receiver',
this.serializeReference(mirror.receiver())));
content.push(MakeJSONPair_('func', this.serializeReference(mirror.func())));
mirror.receiver().toJSONProtocol(false)));
content.push(MakeJSONPair_('func', mirror.func().toJSONProtocol(false)));
content.push(MakeJSONPair_('constructCall',
BooleanToJSON_(mirror.isConstructCall())));
content.push(MakeJSONPair_('debuggerFrame',
......@@ -1870,7 +1726,7 @@ JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
arg.push(MakeJSONPair_('name', StringToJSON_(argument_name)));
}
arg.push(MakeJSONPair_('value',
this.serializeReference(mirror.argumentValue(i))));
mirror.argumentValue(i).toJSONProtocol(false)));
x[i] = ArrayToJSONObject_(arg);
}
content.push(MakeJSONPair_('arguments', ArrayToJSONArray_(x)));
......@@ -1878,7 +1734,7 @@ JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
for (var i = 0; i < mirror.localCount(); i++) {
var name = MakeJSONPair_('name', StringToJSON_(mirror.localName(i)));
var value = MakeJSONPair_('value',
this.serializeReference(mirror.localValue(i)));
mirror.localValue(i).toJSONProtocol(false));
x[i] = '{' + name + ',' + value + '}';
}
content.push(MakeJSONPair_('locals', ArrayToJSONArray_(x)));
......
......@@ -43,33 +43,14 @@ Debug = debug.Debug
listenerCalled = false;
exception = false;
function ParsedResponse(json) {
this.response_ = eval('(' + json + ')');
this.refs_ = [];
if (this.response_.refs) {
for (var i = 0; i < this.response_.refs.length; i++) {
this.refs_[this.response_.refs[i].handle] = this.response_.refs[i];
}
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
return undefined;
}
}
ParsedResponse.prototype.response = function() {
return this.response_;
}
ParsedResponse.prototype.body = function() {
return this.response_.body;
}
ParsedResponse.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break)
......@@ -79,19 +60,13 @@ function listener(event, exec_state, event_data, data) {
// 1: g
// 2: [anonymous]
var response;
var backtrace;
var frame;
var source;
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor();
// Get the backtrace.
var json;
json = '{"seq":0,"type":"request","command":"backtrace"}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
backtrace = response.body();
var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(0, backtrace.fromFrame);
assertEquals(3, backtrace.toFrame);
assertEquals(3, backtrace.totalFrames);
......@@ -101,16 +76,15 @@ function listener(event, exec_state, event_data, data) {
assertEquals('frame', frames[i].type);
}
assertEquals(0, frames[0].index);
assertEquals("f", response.lookup(frames[0].func.ref).name);
assertEquals("f", frames[0].func.name);
assertEquals(1, frames[1].index);
assertEquals("g", response.lookup(frames[1].func.ref).name);
assertEquals("g", frames[1].func.name);
assertEquals(2, frames[2].index);
assertEquals("", response.lookup(frames[2].func.ref).name);
assertEquals("", frames[2].func.name);
// Get backtrace with two frames.
json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFrame":1,"toFrame":3}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
backtrace = response.body();
var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(1, backtrace.fromFrame);
assertEquals(3, backtrace.toFrame);
assertEquals(3, backtrace.totalFrames);
......@@ -120,77 +94,71 @@ function listener(event, exec_state, event_data, data) {
assertEquals('frame', frames[i].type);
}
assertEquals(1, frames[0].index);
assertEquals("g", response.lookup(frames[0].func.ref).name);
assertEquals("g", frames[0].func.name);
assertEquals(2, frames[1].index);
assertEquals("", response.lookup(frames[1].func.ref).name);
assertEquals("", frames[1].func.name);
// Get the individual frames.
var frame;
json = '{"seq":0,"type":"request","command":"frame"}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
frame = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(0, frame.index);
assertEquals("f", response.lookup(frame.func.ref).name);
assertEquals("f", frame.func.name);
assertTrue(frame.constructCall);
assertEquals(31, frame.line);
assertEquals(3, frame.column);
assertEquals(2, frame.arguments.length);
assertEquals('x', frame.arguments[0].name);
assertEquals('number', response.lookup(frame.arguments[0].value.ref).type);
assertEquals(1, response.lookup(frame.arguments[0].value.ref).value);
assertEquals('number', frame.arguments[0].value.type);
assertEquals(1, frame.arguments[0].value.value);
assertEquals('y', frame.arguments[1].name);
assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type);
assertEquals('undefined', frame.arguments[1].value.type);
json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":0}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
frame = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(0, frame.index);
assertEquals("f", response.lookup(frame.func.ref).name);
assertEquals("f", frame.func.name);
assertEquals(31, frame.line);
assertEquals(3, frame.column);
assertEquals(2, frame.arguments.length);
assertEquals('x', frame.arguments[0].name);
assertEquals('number', response.lookup(frame.arguments[0].value.ref).type);
assertEquals(1, response.lookup(frame.arguments[0].value.ref).value);
assertEquals('number', frame.arguments[0].value.type);
assertEquals(1, frame.arguments[0].value.value);
assertEquals('y', frame.arguments[1].name);
assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type);
assertEquals('undefined', frame.arguments[1].value.type);
json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":1}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
frame = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(1, frame.index);
assertEquals("g", response.lookup(frame.func.ref).name);
assertEquals("g", frame.func.name);
assertFalse(frame.constructCall);
assertEquals(35, frame.line);
assertEquals(2, frame.column);
assertEquals(0, frame.arguments.length);
json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":2}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
frame = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(2, frame.index);
assertEquals("", response.lookup(frame.func.ref).name);
assertEquals("", frame.func.name);
// Source slices for the individual frames (they all refer to this script).
json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":0,"fromLine":30,"toLine":32}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
source = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals("function f(x, y) {", source.source.substring(0, 18));
assertEquals(30, source.fromLine);
assertEquals(32, source.toLine);
json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":1,"fromLine":31,"toLine":32}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
source = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(" a=1;", source.source.substring(0, 6));
assertEquals(31, source.fromLine);
assertEquals(32, source.toLine);
json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":2,"fromLine":35,"toLine":36}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
source = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(" new f(1);", source.source.substring(0, 11));
assertEquals(35, source.fromLine);
assertEquals(36, source.toLine);
......@@ -198,13 +166,12 @@ function listener(event, exec_state, event_data, data) {
// Test line interval way beyond this script will result in an error.
json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
assertFalse(response.response().success);
response = safeEval(dcp.processDebugJSONRequest(json));
assertFalse(response.success);
// Test without arguments.
json = '{"seq":0,"type":"request","command":"source"}'
response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
source = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(Debug.findScript(f).source, source.source);
listenerCalled = true;
......
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
// The functions used for testing backtraces. They are at the top to make the
// testing of source line/column easier.
function f(x, y) {
a=1;
};
function g() {
new f(1);
};
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
listenerCallCount = 0;
listenerExceptionCount = 0;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break)
{
listenerCallCount++;
// Check that mirror cache is cleared when entering debugger.
assertEquals(0, debug.next_handle_, "Mirror cache not cleared");
assertEquals(0, debug.mirror_cache_.length, "Mirror cache not cleared");
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor();
// Make a backtrace request to create some mirrors.
var json;
json = '{"seq":0,"type":"request","command":"backtrace"}'
dcp.processDebugJSONRequest(json);
// Some mirrors where cached.
assertFalse(debug.next_handle_ == 0, "Mirror cache not used");
assertFalse(debug.mirror_cache_.length == 0, "Mirror cache not used");
}
} catch (e) {
print(e);
listenerExceptionCount++;
};
};
// Add the debug event listener.
Debug.addListener(listener);
// Enter the debugger twice.
debugger;
debugger;
// Make sure that the debug event listener vas invoked.
assertEquals(2, listenerCallCount, "Listener not called");
assertEquals(0, listenerExceptionCount, "Exception in listener");
......@@ -28,80 +28,50 @@
// Flags: --expose-debug-as debug
// Test the mirror object for objects
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testArrayMirror(a, names) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(a);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ArrayMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
assertTrue(mirror instanceof debug.ArrayMirror);
// Check the mirror properties.
assertTrue(mirror.isArray(), 'Unexpected mirror');
assertEquals('object', mirror.type(), 'Unexpected mirror type');
assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
assertEquals('Array', mirror.className(), 'Unexpected mirror class name');
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertEquals('Array', mirror.constructorFunction().name(), 'Unexpected constructor function name');
assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror.isArray());
assertEquals('object', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals('Array', mirror.className());
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror);
assertTrue(mirror.protoObject() instanceof debug.Mirror);
assertTrue(mirror.prototypeObject() instanceof debug.Mirror);
assertEquals(mirror.length(), a.length, "Length mismatch");
var indexedProperties = mirror.indexedPropertiesFromRange();
assertEquals(indexedProperties.length, a.length);
for (var i = 0; i < indexedProperties.length; i++) {
assertTrue(indexedProperties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(indexedProperties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
var indexedValueMirrors = mirror.indexedPropertiesFromRange();
assertEquals(indexedValueMirrors.length, a.length);
for (var i = 0; i < indexedValueMirrors.length; i++) {
assertTrue(indexedValueMirrors[i] instanceof debug.Mirror);
if (a[i]) {
assertTrue(indexedValueMirrors[i] instanceof debug.PropertyMirror);
}
}
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals('Array', fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals('Array', refs.lookup(fromJSON.constructorFunction.ref).name, 'Unexpected constructor function name in JSON');
assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');
assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expected in JSON');
assertEquals('object', fromJSON.type);
assertEquals('Array', fromJSON.className);
assertEquals('function', fromJSON.constructorFunction.type);
assertEquals('Array', fromJSON.constructorFunction.name);
assertEquals(a.length, fromJSON.length, "Length mismatch in parsed JSON");
// Check that the serialization contains all indexed properties and the length property.
var length_found = false;
for (var i = 0; i < fromJSON.properties.length; i++) {
if (fromJSON.properties[i].name == 'length') {
length_found = true;
assertEquals('number', refs.lookup(fromJSON.properties[i].ref).type, "Unexpected type of the length property");
assertEquals(a.length, refs.lookup(fromJSON.properties[i].ref).value, "Length mismatch in parsed JSON");
} else {
var index = parseInt(fromJSON.properties[i].name);
print(index);
if (!isNaN(index)) {
print(index);
// This test assumes that the order of the indexeed properties is in the
// same order in the serialization as returned from
// indexedPropertiesFromRange()
assertEquals(indexedProperties[index].name(), index);
assertEquals(indexedProperties[index].value().type(), refs.lookup(fromJSON.properties[i].ref).type, 'Unexpected serialized type');
}
}
// Check that the serialization contains all indexed properties.
for (var i = 0; i < fromJSON.indexedProperties.length; i++) {
var index = fromJSON.indexedProperties[i].name;
assertEquals(indexedValueMirrors[index].name(), index);
assertEquals(indexedValueMirrors[index].value().type(), fromJSON.indexedProperties[i].value.type, index);
}
assertTrue(length_found, 'Property length not found');
// Check that the serialization contains all names properties.
if (names) {
......@@ -114,6 +84,8 @@ function testArrayMirror(a, names) {
}
assertTrue(found, names[i])
}
} else {
assertEquals(1, fromJSON.properties.length)
}
}
......
......@@ -31,8 +31,7 @@
function testBooleanMirror(b) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(b);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......
......@@ -31,8 +31,7 @@
function testDateMirror(d, iso8601) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(d);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......
......@@ -28,24 +28,10 @@
// Flags: --expose-debug-as debug
// Test the mirror object for regular error objects
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testErrorMirror(e) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(e);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......@@ -63,18 +49,7 @@ function testErrorMirror(e) {
var fromJSON = eval('(' + json + ')');
assertEquals('error', fromJSON.type);
assertEquals('Error', fromJSON.className);
if (e.message) {
var found_message = false;
for (var i in fromJSON.properties) {
var p = fromJSON.properties[i];
print(p.name);
if (p.name == 'message') {
assertEquals(e.message, refs.lookup(p.ref).value);
found_message = true;
}
}
assertTrue(found_message, 'Property message not found');
}
assertEquals(fromJSON.message, e.message, 'message');
// Check the formatted text (regress 1231579).
assertEquals(fromJSON.text, e.toString(), 'toString');
......
......@@ -28,24 +28,10 @@
// Flags: --expose-debug-as debug
// Test the mirror object for functions.
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testFunctionMirror(f) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(f);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......@@ -72,8 +58,8 @@ function testFunctionMirror(f) {
var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type);
assertEquals('Function', fromJSON.className);
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type);
assertEquals('Function', refs.lookup(fromJSON.constructorFunction.ref).name);
assertEquals('function', fromJSON.constructorFunction.type);
assertEquals('Function', fromJSON.constructorFunction.name);
assertTrue(fromJSON.resolved);
assertEquals(f.name, fromJSON.name);
assertEquals(f.toString(), fromJSON.source);
......
......@@ -30,8 +30,7 @@
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(null);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......
......@@ -31,8 +31,7 @@
function testNumberMirror(n) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(n);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......
......@@ -28,53 +28,38 @@
// Flags: --expose-debug-as debug
// Test the mirror object for objects
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
function testObjectMirror(o, cls_name, ctor_name, hasSpecialProperties) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(obj);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
var mirror = debug.MakeMirror(o);
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.Mirror);
assertTrue(mirror instanceof debug.ValueMirror);
assertTrue(mirror instanceof debug.ObjectMirror);
// Check the mirror properties.
assertTrue(mirror.isObject(), 'Unexpected mirror');
assertEquals('object', mirror.type(), 'Unexpected mirror type');
assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
assertEquals(cls_name, mirror.className(), 'Unexpected mirror class name');
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertEquals(ctor_name, mirror.constructorFunction().name(), 'Unexpected constructor function name');
assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected');
assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected');
assertTrue(mirror.isObject());
assertEquals('object', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals(cls_name, mirror.className());
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror);
assertTrue(mirror.protoObject() instanceof debug.Mirror);
assertTrue(mirror.prototypeObject() instanceof debug.Mirror);
assertFalse(mirror.hasNamedInterceptor(), "hasNamedInterceptor()");
assertFalse(mirror.hasIndexedInterceptor(), "hasIndexedInterceptor()");
var names = mirror.propertyNames();
var properties = mirror.properties()
assertEquals(names.length, properties.length);
for (var i = 0; i < properties.length; i++) {
assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
assertEquals('property', properties[i].type(), 'Unexpected mirror type');
assertEquals(names[i], properties[i].name(), 'Unexpected property name');
assertTrue(properties[i] instanceof debug.Mirror);
assertTrue(properties[i] instanceof debug.PropertyMirror);
assertEquals('property', properties[i].type());
assertEquals(names[i], properties[i].name());
}
for (var p in obj) {
for (var p in o) {
var property_mirror = mirror.property(p);
assertTrue(property_mirror instanceof debug.PropertyMirror);
assertEquals(p, property_mirror.name());
......@@ -89,55 +74,46 @@ function testObjectMirror(obj, cls_name, ctor_name, hasSpecialProperties) {
// Parse JSON representation and check.
var fromJSON = eval('(' + json + ')');
assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals(cls_name, fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals(ctor_name, refs.lookup(fromJSON.constructorFunction.ref).name, 'Unexpected constructor function name in JSON');
assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpected proto object handle in JSON');
assertEquals(mirror.protoObject().type(), refs.lookup(fromJSON.protoObject.ref).type, 'Unexpected proto object type in JSON');
assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref, 'Unexpected prototype object handle in JSON');
assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeObject.ref).type, 'Unexpected prototype object type in JSON');
assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');
assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expected in JSON');
assertEquals('object', fromJSON.type);
assertEquals(cls_name, fromJSON.className);
assertEquals('function', fromJSON.constructorFunction.type);
if (ctor_name !== undefined)
assertEquals(ctor_name, fromJSON.constructorFunction.name);
assertEquals(void 0, fromJSON.namedInterceptor);
assertEquals(void 0, fromJSON.indexedInterceptor);
// For array the index properties are seperate from named properties.
if (!cls_name == 'Array') {
assertEquals(names.length, fromJSON.properties.length, 'Some properties missing in JSON');
}
// Check that the serialization contains all properties.
assertEquals(names.length, fromJSON.properties.length, 'Some properties missing in JSON');
for (var i = 0; i < fromJSON.properties.length; i++) {
var name = fromJSON.properties[i].name;
if (!name) name = fromJSON.properties[i].index;
var found = false;
for (var j = 0; j < names.length; j++) {
if (names[j] == name) {
// Check that serialized handle is correct.
assertEquals(properties[i].value().handle(), fromJSON.properties[i].ref, 'Unexpected serialized handle');
// Check that serialized name is correct.
assertEquals(properties[i].name(), fromJSON.properties[i].name, 'Unexpected serialized name');
// If property type is normal property type is not serialized.
assertEquals(properties[i].value().type(), fromJSON.properties[i].value.type);
// If property type is normal nothing is serialized.
if (properties[i].propertyType() != debug.PropertyType.Normal) {
assertEquals(properties[i].propertyType(), fromJSON.properties[i].propertyType, 'Unexpected serialized property type');
assertEquals(properties[i].propertyType(), fromJSON.properties[i].propertyType);
} else {
assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined', 'Unexpected serialized property type');
assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined');
}
// If there are no attributes attributes are not serialized.
// If there are no attributes nothing is serialized.
if (properties[i].attributes() != debug.PropertyAttribute.None) {
assertEquals(properties[i].attributes(), fromJSON.properties[i].attributes, 'Unexpected serialized attributes');
assertEquals(properties[i].attributes(), fromJSON.properties[i].attributes);
} else {
assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes');
assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined');
}
// Lookup the serialized object from the handle reference.
var o = refs.lookup(fromJSON.properties[i].ref);
assertTrue(o != void 0, 'Referenced object is not serialized');
assertEquals(properties[i].value().type(), o.type, 'Unexpected serialized property type for ' + name);
if (properties[i].value().isPrimitive()) {
assertEquals(properties[i].value().value(), o.value, 'Unexpected serialized property value for ' + name);
} else if (properties[i].value().isFunction()) {
assertEquals(properties[i].value().source(), o.source, 'Unexpected serialized property value for ' + name);
if (!properties[i].value().isPrimitive()) {
// NaN is not equal to NaN.
if (isNaN(properties[i].value().value())) {
assertTrue(isNaN(fromJSON.properties[i].value.value));
} else {
assertEquals(properties[i].value().value(), fromJSON.properties[i].value.value);
}
}
found = true;
}
......@@ -158,7 +134,7 @@ testObjectMirror({}, 'Object', 'Object');
testObjectMirror({'a':1,'b':2}, 'Object', 'Object');
testObjectMirror({'1':void 0,'2':null,'f':function pow(x,y){return Math.pow(x,y);}}, 'Object', 'Object');
testObjectMirror(new Point(-1.2,2.003), 'Object', 'Point');
testObjectMirror(this, 'global', '', true); // Global object has special properties
testObjectMirror(this, 'global', undefined, true); // Global object has special properties
testObjectMirror([], 'Array', 'Array');
testObjectMirror([1,2], 'Array', 'Array');
......
......@@ -39,24 +39,10 @@ var expected_attributes = {
'lastIndex': debug.PropertyAttribute.DontEnum | debug.PropertyAttribute.DontDelete
};
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function testRegExpMirror(r) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(r);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......@@ -68,6 +54,10 @@ function testRegExpMirror(r) {
assertTrue(mirror.isRegExp());
assertEquals('regexp', mirror.type());
assertFalse(mirror.isPrimitive());
assertEquals(mirror.source(), r.source, 'source');
assertEquals(mirror.global(), r.global, 'global');
assertEquals(mirror.ignoreCase(), r.ignoreCase, 'ignoreCase');
assertEquals(mirror.multiline(), r.multiline, 'multiline');
for (var p in expected_attributes) {
assertEquals(mirror.property(p).attributes(),
expected_attributes[p],
......@@ -81,21 +71,16 @@ function testRegExpMirror(r) {
var fromJSON = eval('(' + json + ')');
assertEquals('regexp', fromJSON.type);
assertEquals('RegExp', fromJSON.className);
assertEquals(fromJSON.source, r.source, 'source');
assertEquals(fromJSON.global, r.global, 'global');
assertEquals(fromJSON.ignoreCase, r.ignoreCase, 'ignoreCase');
assertEquals(fromJSON.multiline, r.multiline, 'multiline');
for (var p in expected_attributes) {
for (var i = 0; i < fromJSON.properties.length; i++) {
if (fromJSON.properties[i].name == p) {
assertEquals(expected_attributes[p],
fromJSON.properties[i].attributes,
'Unexpected value for ' + p + ' attributes');
assertEquals(mirror.property(p).propertyType(),
fromJSON.properties[i].propertyType,
'Unexpected value for ' + p + ' propertyType');
assertEquals(mirror.property(p).value().handle(),
fromJSON.properties[i].ref,
'Unexpected handle for ' + p);
assertEquals(mirror.property(p).value().value(),
refs.lookup(fromJSON.properties[i].ref).value,
'Unexpected value for ' + p);
assertEquals(fromJSON.properties[i].attributes,
expected_attributes[p],
p + ' attributes');
}
}
}
......
......@@ -31,8 +31,8 @@
function testScriptMirror(f, file_name, file_lines, script_type) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(f).script();
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var json = mirror.toJSONProtocol(true);
print(json);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......
......@@ -33,8 +33,7 @@ const kMaxProtocolStringLength = 80; // Constant from mirror-delay.js
function testStringMirror(s) {
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(s);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......
......@@ -30,8 +30,7 @@
// Create mirror and JSON representation.
var mirror = debug.MakeMirror(void 0);
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror);
......
......@@ -28,22 +28,8 @@
// Flags: --expose-debug-as debug
// Test the mirror object for unresolved functions.
function MirrorRefCache(json_refs) {
var tmp = eval('(' + json_refs + ')');
this.refs_ = [];
for (var i = 0; i < tmp.length; i++) {
this.refs_[tmp[i].handle] = tmp[i];
}
}
MirrorRefCache.prototype.lookup = function(handle) {
return this.refs_[handle];
}
var mirror = new debug.UnresolvedFunctionMirror("f");
var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
var json = mirror.toJSONProtocol(true);
// Check the mirror hierachy for unresolved functions.
assertTrue(mirror instanceof debug.Mirror);
......@@ -64,15 +50,12 @@ assertEquals('undefined', mirror.protoObject().type());
assertEquals('undefined', mirror.prototypeObject().type());
// Parse JSON representation of unresolved functions and check.
var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals('Function', fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
assertEquals('undefined', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpected proto object handle in JSON');
assertEquals('undefined', refs.lookup(fromJSON.protoObject.ref).type, 'Unexpected proto object type in JSON');
assertEquals(mirror.prototypeObject().handle(), fromJSON.prototypeObject.ref, 'Unexpected prototype object handle in JSON');
assertEquals('undefined', refs.lookup(fromJSON.prototypeObject.ref).type, 'Unexpected prototype object type in JSON');
/*var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type);
assertEquals('Function', fromJSON.className);
assertEquals('undefined', fromJSON.constructorFunction.type);
assertEquals('undefined', fromJSON.protoObject.type);
assertEquals('undefined', fromJSON.prototypeObject.type);
assertFalse(fromJSON.resolved);
assertEquals("f", fromJSON.name);
assertEquals(void 0, fromJSON.source);
assertEquals(void 0, fromJSON.source);*/
......@@ -34,32 +34,14 @@ Debug = debug.Debug
listenerCalled = false;
exception = false;
function ParsedResponse(json) {
this.response_ = eval('(' + json + ')');
this.refs_ = [];
if (this.response_.refs) {
for (var i = 0; i < this.response_.refs.length; i++) {
this.refs_[this.response_.refs[i].handle] = this.response_.refs[i];
}
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
return undefined;
}
}
ParsedResponse.prototype.response = function() {
return this.response_;
}
ParsedResponse.prototype.body = function() {
return this.response_.body;
}
ParsedResponse.prototype.lookup = function(handle) {
return this.refs_[handle];
}
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Exception)
......@@ -74,13 +56,12 @@ function listener(event, exec_state, event_data, data) {
// Get the backtrace.
var json;
json = '{"seq":0,"type":"request","command":"backtrace"}'
var response = new ParsedResponse(dcp.processDebugJSONRequest(json));
var backtrace = response.body();
var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body;
assertEquals(2, backtrace.totalFrames);
assertEquals(2, backtrace.frames.length);
assertEquals("g", response.lookup(backtrace.frames[0].func.ref).name);
assertEquals("", response.lookup(backtrace.frames[1].func.ref).name);
assertEquals("g", backtrace.frames[0].func.name);
assertEquals("", backtrace.frames[1].func.name);
listenerCalled = true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment