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

Added handles to the mirror objects. When a mirror for an object is created

it is assigned a numeric handle. Handles are used to make a 1:1
correspondence between objects and mirrors. Currently the mirrors are
cached in a JavaScript array and when creating a mirror this cache is
checked to see if a mirror already exists for the object. This cache is
cleared when leaving the debugger.

Changed the serialization format to take advantage of these handles. When
an object is serialized referenced objects are represented just by their
handle id serialized as '{ref:<handle>}'. During serialization the
referenced handles are collected and the serializer can provide a
serialization of all the referenced objects.

Removed the special handling of array properties. Indexed properties and
the length property are now rendered as named properties in the
serialization.

Removed the special serialization handling of RegExp properties. The
properties 'source', 'global', 'ignoreCase' and 'multiline' are serialized
with the rest of the properties.

Changed a lot of tests to handle the changed format.
Review URL: http://codereview.chromium.org/18092

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1093 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent baa54768
...@@ -994,22 +994,25 @@ ResponsePacket.prototype.toJSONProtocol = function() { ...@@ -994,22 +994,25 @@ ResponsePacket.prototype.toJSONProtocol = function() {
if (this.body) { if (this.body) {
json += ',"body":'; json += ',"body":';
// Encode the body part. // Encode the body part.
if (this.body.toJSONProtocol) { var serializer = MakeMirrorSerializer(true);
json += this.body.toJSONProtocol(true); if (this.body instanceof Mirror) {
json += serializer.serializeValue(this.body);
} else if (this.body instanceof Array) { } else if (this.body instanceof Array) {
json += '['; json += '[';
for (var i = 0; i < this.body.length; i++) { for (var i = 0; i < this.body.length; i++) {
if (i != 0) json += ','; if (i != 0) json += ',';
if (this.body[i].toJSONProtocol) { if (this.body[i] instanceof Mirror) {
json += this.body[i].toJSONProtocol(true) json += serializer.serializeValue(this.body[i]);
} else { } else {
json += SimpleObjectToJSON_(this.body[i]); json += SimpleObjectToJSON_(this.body[i], serializer);
} }
} }
json += ']'; json += ']';
} else { } else {
json += SimpleObjectToJSON_(this.body); json += SimpleObjectToJSON_(this.body, serializer);
} }
json += ',"refs":';
json += serializer.serializeReferencedObjects();
} }
if (this.message) { if (this.message) {
json += ',"message":' + StringToJSON_(this.message) ; json += ',"message":' + StringToJSON_(this.message) ;
...@@ -1568,9 +1571,11 @@ DebugCommandProcessor.prototype.formatCFrame = function(cframe_value) { ...@@ -1568,9 +1571,11 @@ DebugCommandProcessor.prototype.formatCFrame = function(cframe_value) {
* a general implementation but sufficient for the debugger. Note that circular * a general implementation but sufficient for the debugger. Note that circular
* structures will cause infinite recursion. * structures will cause infinite recursion.
* @param {Object} object The object to format as JSON * @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 * @return {string} JSON formatted object value
*/ */
function SimpleObjectToJSON_(object) { function SimpleObjectToJSON_(object, mirror_serializer) {
var content = []; var content = [];
for (var key in object) { for (var key in object) {
// Only consider string keys. // Only consider string keys.
...@@ -1584,9 +1589,9 @@ function SimpleObjectToJSON_(object) { ...@@ -1584,9 +1589,9 @@ function SimpleObjectToJSON_(object) {
if (typeof property_value.toJSONProtocol == 'function') { if (typeof property_value.toJSONProtocol == 'function') {
property_value_json = property_value.toJSONProtocol(true) property_value_json = property_value.toJSONProtocol(true)
} else if (IS_ARRAY(property_value)){ } else if (IS_ARRAY(property_value)){
property_value_json = SimpleArrayToJSON_(property_value); property_value_json = SimpleArrayToJSON_(property_value, mirror_serializer);
} else { } else {
property_value_json = SimpleObjectToJSON_(property_value); property_value_json = SimpleObjectToJSON_(property_value, mirror_serializer);
} }
break; break;
...@@ -1620,10 +1625,12 @@ function SimpleObjectToJSON_(object) { ...@@ -1620,10 +1625,12 @@ function SimpleObjectToJSON_(object) {
/** /**
* Convert an array to its JSON representation. This is a VERY simple * Convert an array to its JSON representation. This is a VERY simple
* implementation just to support what is needed for the debugger. * implementation just to support what is needed for the debugger.
* @param {Array} arrya The array to format as JSON * @param {Array} array The array to format as JSON
* @param {MirrorSerializer} mirror_serializer The serializer to use if any
* mirror objects are encountered.
* @return {string} JSON formatted array value * @return {string} JSON formatted array value
*/ */
function SimpleArrayToJSON_(array) { function SimpleArrayToJSON_(array, mirror_serializer) {
// Make JSON array representation. // Make JSON array representation.
var json = '['; var json = '[';
for (var i = 0; i < array.length; i++) { for (var i = 0; i < array.length; i++) {
...@@ -1631,8 +1638,8 @@ function SimpleArrayToJSON_(array) { ...@@ -1631,8 +1638,8 @@ function SimpleArrayToJSON_(array) {
json += ','; json += ',';
} }
var elem = array[i]; var elem = array[i];
if (elem.toJSONProtocol) { if (elem instanceof Mirror) {
json += elem.toJSONProtocol(true) json += mirror_serializer.serializeValue(elem);
} else if (IS_OBJECT(elem)) { } else if (IS_OBJECT(elem)) {
json += SimpleObjectToJSON_(elem); json += SimpleObjectToJSON_(elem);
} else if (IS_BOOLEAN(elem)) { } else if (IS_BOOLEAN(elem)) {
......
...@@ -1303,6 +1303,22 @@ bool Debug::IsDebugGlobal(GlobalObject* global) { ...@@ -1303,6 +1303,22 @@ 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::debugger_active_ = false;
bool Debugger::compiling_natives_ = false; bool Debugger::compiling_natives_ = false;
bool Debugger::is_loading_debugger_ = false; bool Debugger::is_loading_debugger_ = false;
...@@ -1628,6 +1644,9 @@ void Debugger::ProcessDebugEvent(v8::DebugEvent event, ...@@ -1628,6 +1644,9 @@ void Debugger::ProcessDebugEvent(v8::DebugEvent event,
} }
} }
} }
// Clear the mirror cache.
Debug::ClearMirrorCache();
} }
......
...@@ -260,6 +260,9 @@ class Debug { ...@@ -260,6 +260,9 @@ class Debug {
static char* RestoreDebug(char* from); static char* RestoreDebug(char* from);
static int ArchiveSpacePerThread(); static int ArchiveSpacePerThread();
// Mirror cache handling.
static void ClearMirrorCache();
// Code generation assumptions. // Code generation assumptions.
static const int kIa32CallInstructionLength = 5; static const int kIa32CallInstructionLength = 5;
static const int kIa32JSReturnSequenceLength = 6; static const int kIa32JSReturnSequenceLength = 6;
......
This diff is collapsed.
...@@ -43,14 +43,33 @@ Debug = debug.Debug ...@@ -43,14 +43,33 @@ Debug = debug.Debug
listenerCalled = false; listenerCalled = false;
exception = false; exception = false;
function safeEval(code) {
try { function ParsedResponse(json) {
return eval('(' + code + ')'); this.response_ = eval('(' + json + ')');
} catch (e) { this.refs_ = [];
return undefined; 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];
}
} }
} }
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) { function listener(event, exec_state, event_data, data) {
try { try {
if (event == Debug.DebugEvent.Break) if (event == Debug.DebugEvent.Break)
...@@ -60,13 +79,19 @@ function listener(event, exec_state, event_data, data) { ...@@ -60,13 +79,19 @@ function listener(event, exec_state, event_data, data) {
// 1: g // 1: g
// 2: [anonymous] // 2: [anonymous]
var response;
var backtrace;
var frame;
var source;
// Get the debug command processor. // Get the debug command processor.
var dcp = exec_state.debugCommandProcessor(); var dcp = exec_state.debugCommandProcessor();
// Get the backtrace. // Get the backtrace.
var json; var json;
json = '{"seq":0,"type":"request","command":"backtrace"}' json = '{"seq":0,"type":"request","command":"backtrace"}'
var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
backtrace = response.body();
assertEquals(0, backtrace.fromFrame); assertEquals(0, backtrace.fromFrame);
assertEquals(3, backtrace.toFrame); assertEquals(3, backtrace.toFrame);
assertEquals(3, backtrace.totalFrames); assertEquals(3, backtrace.totalFrames);
...@@ -76,15 +101,16 @@ function listener(event, exec_state, event_data, data) { ...@@ -76,15 +101,16 @@ function listener(event, exec_state, event_data, data) {
assertEquals('frame', frames[i].type); assertEquals('frame', frames[i].type);
} }
assertEquals(0, frames[0].index); assertEquals(0, frames[0].index);
assertEquals("f", frames[0].func.name); assertEquals("f", response.lookup(frames[0].func.ref).name);
assertEquals(1, frames[1].index); assertEquals(1, frames[1].index);
assertEquals("g", frames[1].func.name); assertEquals("g", response.lookup(frames[1].func.ref).name);
assertEquals(2, frames[2].index); assertEquals(2, frames[2].index);
assertEquals("", frames[2].func.name); assertEquals("", response.lookup(frames[2].func.ref).name);
// Get backtrace with two frames. // Get backtrace with two frames.
json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFrame":1,"toFrame":3}}' json = '{"seq":0,"type":"request","command":"backtrace","arguments":{"fromFrame":1,"toFrame":3}}'
var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
backtrace = response.body();
assertEquals(1, backtrace.fromFrame); assertEquals(1, backtrace.fromFrame);
assertEquals(3, backtrace.toFrame); assertEquals(3, backtrace.toFrame);
assertEquals(3, backtrace.totalFrames); assertEquals(3, backtrace.totalFrames);
...@@ -94,71 +120,77 @@ function listener(event, exec_state, event_data, data) { ...@@ -94,71 +120,77 @@ function listener(event, exec_state, event_data, data) {
assertEquals('frame', frames[i].type); assertEquals('frame', frames[i].type);
} }
assertEquals(1, frames[0].index); assertEquals(1, frames[0].index);
assertEquals("g", frames[0].func.name); assertEquals("g", response.lookup(frames[0].func.ref).name);
assertEquals(2, frames[1].index); assertEquals(2, frames[1].index);
assertEquals("", frames[1].func.name); assertEquals("", response.lookup(frames[1].func.ref).name);
// Get the individual frames. // Get the individual frames.
var frame;
json = '{"seq":0,"type":"request","command":"frame"}' json = '{"seq":0,"type":"request","command":"frame"}'
frame = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
assertEquals(0, frame.index); assertEquals(0, frame.index);
assertEquals("f", frame.func.name); assertEquals("f", response.lookup(frame.func.ref).name);
assertTrue(frame.constructCall); assertTrue(frame.constructCall);
assertEquals(31, frame.line); assertEquals(31, frame.line);
assertEquals(3, frame.column); assertEquals(3, frame.column);
assertEquals(2, frame.arguments.length); assertEquals(2, frame.arguments.length);
assertEquals('x', frame.arguments[0].name); assertEquals('x', frame.arguments[0].name);
assertEquals('number', frame.arguments[0].value.type); assertEquals('number', response.lookup(frame.arguments[0].value.ref).type);
assertEquals(1, frame.arguments[0].value.value); assertEquals(1, response.lookup(frame.arguments[0].value.ref).value);
assertEquals('y', frame.arguments[1].name); assertEquals('y', frame.arguments[1].name);
assertEquals('undefined', frame.arguments[1].value.type); assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type);
json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":0}}' json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":0}}'
frame = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
assertEquals(0, frame.index); assertEquals(0, frame.index);
assertEquals("f", frame.func.name); assertEquals("f", response.lookup(frame.func.ref).name);
assertEquals(31, frame.line); assertEquals(31, frame.line);
assertEquals(3, frame.column); assertEquals(3, frame.column);
assertEquals(2, frame.arguments.length); assertEquals(2, frame.arguments.length);
assertEquals('x', frame.arguments[0].name); assertEquals('x', frame.arguments[0].name);
assertEquals('number', frame.arguments[0].value.type); assertEquals('number', response.lookup(frame.arguments[0].value.ref).type);
assertEquals(1, frame.arguments[0].value.value); assertEquals(1, response.lookup(frame.arguments[0].value.ref).value);
assertEquals('y', frame.arguments[1].name); assertEquals('y', frame.arguments[1].name);
assertEquals('undefined', frame.arguments[1].value.type); assertEquals('undefined', response.lookup(frame.arguments[1].value.ref).type);
json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":1}}' json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":1}}'
frame = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
assertEquals(1, frame.index); assertEquals(1, frame.index);
assertEquals("g", frame.func.name); assertEquals("g", response.lookup(frame.func.ref).name);
assertFalse(frame.constructCall); assertFalse(frame.constructCall);
assertEquals(35, frame.line); assertEquals(35, frame.line);
assertEquals(2, frame.column); assertEquals(2, frame.column);
assertEquals(0, frame.arguments.length); assertEquals(0, frame.arguments.length);
json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":2}}' json = '{"seq":0,"type":"request","command":"frame","arguments":{"number":2}}'
frame = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
frame = response.body();
assertEquals(2, frame.index); assertEquals(2, frame.index);
assertEquals("", frame.func.name); assertEquals("", response.lookup(frame.func.ref).name);
// Source slices for the individual frames (they all refer to this script). // Source slices for the individual frames (they all refer to this script).
json = '{"seq":0,"type":"request","command":"source",' + json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":0,"fromLine":30,"toLine":32}}' '"arguments":{"frame":0,"fromLine":30,"toLine":32}}'
source = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
assertEquals("function f(x, y) {", source.source.substring(0, 18)); assertEquals("function f(x, y) {", source.source.substring(0, 18));
assertEquals(30, source.fromLine); assertEquals(30, source.fromLine);
assertEquals(32, source.toLine); assertEquals(32, source.toLine);
json = '{"seq":0,"type":"request","command":"source",' + json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":1,"fromLine":31,"toLine":32}}' '"arguments":{"frame":1,"fromLine":31,"toLine":32}}'
source = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
assertEquals(" a=1;", source.source.substring(0, 6)); assertEquals(" a=1;", source.source.substring(0, 6));
assertEquals(31, source.fromLine); assertEquals(31, source.fromLine);
assertEquals(32, source.toLine); assertEquals(32, source.toLine);
json = '{"seq":0,"type":"request","command":"source",' + json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":2,"fromLine":35,"toLine":36}}' '"arguments":{"frame":2,"fromLine":35,"toLine":36}}'
source = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
assertEquals(" new f(1);", source.source.substring(0, 11)); assertEquals(" new f(1);", source.source.substring(0, 11));
assertEquals(35, source.fromLine); assertEquals(35, source.fromLine);
assertEquals(36, source.toLine); assertEquals(36, source.toLine);
...@@ -166,12 +198,13 @@ function listener(event, exec_state, event_data, data) { ...@@ -166,12 +198,13 @@ function listener(event, exec_state, event_data, data) {
// Test line interval way beyond this script will result in an error. // Test line interval way beyond this script will result in an error.
json = '{"seq":0,"type":"request","command":"source",' + json = '{"seq":0,"type":"request","command":"source",' +
'"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}' '"arguments":{"frame":0,"fromLine":10000,"toLine":20000}}'
response = safeEval(dcp.processDebugJSONRequest(json)); response = new ParsedResponse(dcp.processDebugJSONRequest(json));
assertFalse(response.success); assertFalse(response.response().success);
// Test without arguments. // Test without arguments.
json = '{"seq":0,"type":"request","command":"source"}' json = '{"seq":0,"type":"request","command":"source"}'
source = safeEval(dcp.processDebugJSONRequest(json)).body; response = new ParsedResponse(dcp.processDebugJSONRequest(json));
source = response.body();
assertEquals(Debug.findScript(f).source, source.source); assertEquals(Debug.findScript(f).source, source.source);
listenerCalled = true; 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,50 +28,80 @@ ...@@ -28,50 +28,80 @@
// Flags: --expose-debug-as debug // Flags: --expose-debug-as debug
// Test the mirror object for objects // 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) { function testArrayMirror(a, names) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(a); var mirror = debug.MakeMirror(a);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ValueMirror); assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ObjectMirror); assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ArrayMirror); assertTrue(mirror instanceof debug.ArrayMirror, 'Unexpected mirror hierachy');
// Check the mirror properties. // Check the mirror properties.
assertTrue(mirror.isArray()); assertTrue(mirror.isArray(), 'Unexpected mirror');
assertEquals('object', mirror.type()); assertEquals('object', mirror.type(), 'Unexpected mirror type');
assertFalse(mirror.isPrimitive()); assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
assertEquals('Array', mirror.className()); assertEquals('Array', mirror.className(), 'Unexpected mirror class name');
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror); assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertTrue(mirror.protoObject() instanceof debug.Mirror); assertEquals('Array', mirror.constructorFunction().name(), 'Unexpected constructor function name');
assertTrue(mirror.prototypeObject() instanceof debug.Mirror); assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertEquals(mirror.length(), a.length, "Length mismatch"); assertEquals(mirror.length(), a.length, "Length mismatch");
var indexedValueMirrors = mirror.indexedPropertiesFromRange(); var indexedProperties = mirror.indexedPropertiesFromRange();
assertEquals(indexedValueMirrors.length, a.length); assertEquals(indexedProperties.length, a.length);
for (var i = 0; i < indexedValueMirrors.length; i++) { for (var i = 0; i < indexedProperties.length; i++) {
assertTrue(indexedValueMirrors[i] instanceof debug.Mirror); assertTrue(indexedProperties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
if (a[i]) { assertTrue(indexedProperties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
assertTrue(indexedValueMirrors[i] instanceof debug.PropertyMirror);
}
} }
// Parse JSON representation and check. // Parse JSON representation and check.
var fromJSON = eval('(' + json + ')'); var fromJSON = eval('(' + json + ')');
assertEquals('object', fromJSON.type); assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals('Array', fromJSON.className); assertEquals('Array', fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals('function', fromJSON.constructorFunction.type); assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
assertEquals('Array', fromJSON.constructorFunction.name); assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals(a.length, fromJSON.length, "Length mismatch in parsed 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');
// Check that the serialization contains all indexed properties. // Check that the serialization contains all indexed properties and the length property.
for (var i = 0; i < fromJSON.indexedProperties.length; i++) { var length_found = false;
var index = fromJSON.indexedProperties[i].name; for (var i = 0; i < fromJSON.properties.length; i++) {
assertEquals(indexedValueMirrors[index].name(), index); if (fromJSON.properties[i].name == 'length') {
assertEquals(indexedValueMirrors[index].value().type(), fromJSON.indexedProperties[i].value.type, index); 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');
}
}
} }
assertTrue(length_found, 'Property length not found');
// Check that the serialization contains all names properties. // Check that the serialization contains all names properties.
if (names) { if (names) {
...@@ -84,8 +114,6 @@ function testArrayMirror(a, names) { ...@@ -84,8 +114,6 @@ function testArrayMirror(a, names) {
} }
assertTrue(found, names[i]) assertTrue(found, names[i])
} }
} else {
assertEquals(1, fromJSON.properties.length)
} }
} }
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
function testBooleanMirror(b) { function testBooleanMirror(b) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(b); var mirror = debug.MakeMirror(b);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
function testDateMirror(d, iso8601) { function testDateMirror(d, iso8601) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(d); var mirror = debug.MakeMirror(d);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
......
...@@ -28,10 +28,24 @@ ...@@ -28,10 +28,24 @@
// Flags: --expose-debug-as debug // Flags: --expose-debug-as debug
// Test the mirror object for regular error objects // 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) { function testErrorMirror(e) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(e); var mirror = debug.MakeMirror(e);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
...@@ -49,7 +63,18 @@ function testErrorMirror(e) { ...@@ -49,7 +63,18 @@ function testErrorMirror(e) {
var fromJSON = eval('(' + json + ')'); var fromJSON = eval('(' + json + ')');
assertEquals('error', fromJSON.type); assertEquals('error', fromJSON.type);
assertEquals('Error', fromJSON.className); assertEquals('Error', fromJSON.className);
assertEquals(fromJSON.message, e.message, 'message'); 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');
}
// Check the formatted text (regress 1231579). // Check the formatted text (regress 1231579).
assertEquals(fromJSON.text, e.toString(), 'toString'); assertEquals(fromJSON.text, e.toString(), 'toString');
......
...@@ -28,10 +28,24 @@ ...@@ -28,10 +28,24 @@
// Flags: --expose-debug-as debug // Flags: --expose-debug-as debug
// Test the mirror object for functions. // 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) { function testFunctionMirror(f) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(f); var mirror = debug.MakeMirror(f);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
...@@ -58,8 +72,8 @@ function testFunctionMirror(f) { ...@@ -58,8 +72,8 @@ function testFunctionMirror(f) {
var fromJSON = eval('(' + json + ')'); var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type); assertEquals('function', fromJSON.type);
assertEquals('Function', fromJSON.className); assertEquals('Function', fromJSON.className);
assertEquals('function', fromJSON.constructorFunction.type); assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type);
assertEquals('Function', fromJSON.constructorFunction.name); assertEquals('Function', refs.lookup(fromJSON.constructorFunction.ref).name);
assertTrue(fromJSON.resolved); assertTrue(fromJSON.resolved);
assertEquals(f.name, fromJSON.name); assertEquals(f.name, fromJSON.name);
assertEquals(f.toString(), fromJSON.source); assertEquals(f.toString(), fromJSON.source);
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(null); var mirror = debug.MakeMirror(null);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
function testNumberMirror(n) { function testNumberMirror(n) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(n); var mirror = debug.MakeMirror(n);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
......
...@@ -28,38 +28,53 @@ ...@@ -28,38 +28,53 @@
// Flags: --expose-debug-as debug // Flags: --expose-debug-as debug
// Test the mirror object for objects // Test the mirror object for objects
function testObjectMirror(o, cls_name, ctor_name, hasSpecialProperties) { 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) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(o); var mirror = debug.MakeMirror(obj);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ValueMirror); assertTrue(mirror instanceof debug.ValueMirror, 'Unexpected mirror hierachy');
assertTrue(mirror instanceof debug.ObjectMirror); assertTrue(mirror instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
// Check the mirror properties. // Check the mirror properties.
assertTrue(mirror.isObject()); assertTrue(mirror.isObject(), 'Unexpected mirror');
assertEquals('object', mirror.type()); assertEquals('object', mirror.type(), 'Unexpected mirror type');
assertFalse(mirror.isPrimitive()); assertFalse(mirror.isPrimitive(), 'Unexpected primitive mirror');
assertEquals(cls_name, mirror.className()); assertEquals(cls_name, mirror.className(), 'Unexpected mirror class name');
assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror); assertTrue(mirror.constructorFunction() instanceof debug.ObjectMirror, 'Unexpected mirror hierachy');
assertTrue(mirror.protoObject() instanceof debug.Mirror); assertEquals(ctor_name, mirror.constructorFunction().name(), 'Unexpected constructor function name');
assertTrue(mirror.prototypeObject() instanceof debug.Mirror); assertTrue(mirror.protoObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertFalse(mirror.hasNamedInterceptor(), "hasNamedInterceptor()"); assertTrue(mirror.prototypeObject() instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertFalse(mirror.hasIndexedInterceptor(), "hasIndexedInterceptor()"); assertFalse(mirror.hasNamedInterceptor(), 'No named interceptor expected');
assertFalse(mirror.hasIndexedInterceptor(), 'No indexed interceptor expected');
var names = mirror.propertyNames(); var names = mirror.propertyNames();
var properties = mirror.properties() var properties = mirror.properties()
assertEquals(names.length, properties.length); assertEquals(names.length, properties.length);
for (var i = 0; i < properties.length; i++) { for (var i = 0; i < properties.length; i++) {
assertTrue(properties[i] instanceof debug.Mirror); assertTrue(properties[i] instanceof debug.Mirror, 'Unexpected mirror hierachy');
assertTrue(properties[i] instanceof debug.PropertyMirror); assertTrue(properties[i] instanceof debug.PropertyMirror, 'Unexpected mirror hierachy');
assertEquals('property', properties[i].type()); assertEquals('property', properties[i].type(), 'Unexpected mirror type');
assertEquals(names[i], properties[i].name()); assertEquals(names[i], properties[i].name(), 'Unexpected property name');
} }
for (var p in o) { for (var p in obj) {
var property_mirror = mirror.property(p); var property_mirror = mirror.property(p);
assertTrue(property_mirror instanceof debug.PropertyMirror); assertTrue(property_mirror instanceof debug.PropertyMirror);
assertEquals(p, property_mirror.name()); assertEquals(p, property_mirror.name());
...@@ -74,46 +89,55 @@ function testObjectMirror(o, cls_name, ctor_name, hasSpecialProperties) { ...@@ -74,46 +89,55 @@ function testObjectMirror(o, cls_name, ctor_name, hasSpecialProperties) {
// Parse JSON representation and check. // Parse JSON representation and check.
var fromJSON = eval('(' + json + ')'); var fromJSON = eval('(' + json + ')');
assertEquals('object', fromJSON.type); assertEquals('object', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals(cls_name, fromJSON.className); assertEquals(cls_name, fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals('function', fromJSON.constructorFunction.type); assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
if (ctor_name !== undefined) assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals(ctor_name, fromJSON.constructorFunction.name); assertEquals(ctor_name, refs.lookup(fromJSON.constructorFunction.ref).name, 'Unexpected constructor function name in JSON');
assertEquals(void 0, fromJSON.namedInterceptor); assertEquals(mirror.protoObject().handle(), fromJSON.protoObject.ref, 'Unexpected proto object handle in JSON');
assertEquals(void 0, fromJSON.indexedInterceptor); 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');
// For array the index properties are seperate from named properties. assertEquals(mirror.prototypeObject().type(), refs.lookup(fromJSON.prototypeObject.ref).type, 'Unexpected prototype object type in JSON');
if (!cls_name == 'Array') { assertEquals(void 0, fromJSON.namedInterceptor, 'No named interceptor expected in JSON');
assertEquals(names.length, fromJSON.properties.length, 'Some properties missing in JSON'); assertEquals(void 0, fromJSON.indexedInterceptor, 'No indexed interceptor expected in JSON');
}
// Check that the serialization contains all properties. // 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++) { for (var i = 0; i < fromJSON.properties.length; i++) {
var name = fromJSON.properties[i].name; var name = fromJSON.properties[i].name;
if (!name) name = fromJSON.properties[i].index; if (!name) name = fromJSON.properties[i].index;
var found = false; var found = false;
for (var j = 0; j < names.length; j++) { for (var j = 0; j < names.length; j++) {
if (names[j] == name) { if (names[j] == name) {
assertEquals(properties[i].value().type(), fromJSON.properties[i].value.type); // Check that serialized handle is correct.
// If property type is normal nothing is serialized. 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.
if (properties[i].propertyType() != debug.PropertyType.Normal) { if (properties[i].propertyType() != debug.PropertyType.Normal) {
assertEquals(properties[i].propertyType(), fromJSON.properties[i].propertyType); assertEquals(properties[i].propertyType(), fromJSON.properties[i].propertyType, 'Unexpected serialized property type');
} else { } else {
assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined'); assertTrue(typeof(fromJSON.properties[i].propertyType) === 'undefined', 'Unexpected serialized property type');
} }
// If there are no attributes nothing is serialized.
// If there are no attributes attributes are not serialized.
if (properties[i].attributes() != debug.PropertyAttribute.None) { if (properties[i].attributes() != debug.PropertyAttribute.None) {
assertEquals(properties[i].attributes(), fromJSON.properties[i].attributes); assertEquals(properties[i].attributes(), fromJSON.properties[i].attributes, 'Unexpected serialized attributes');
} else { } else {
assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined'); assertTrue(typeof(fromJSON.properties[i].attributes) === 'undefined', 'Unexpected serialized attributes');
} }
if (!properties[i].value().isPrimitive()) {
// NaN is not equal to NaN. // Lookup the serialized object from the handle reference.
if (isNaN(properties[i].value().value())) { var o = refs.lookup(fromJSON.properties[i].ref);
assertTrue(isNaN(fromJSON.properties[i].value.value)); assertTrue(o != void 0, 'Referenced object is not serialized');
} else {
assertEquals(properties[i].value().value(), fromJSON.properties[i].value.value); 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);
} }
found = true; found = true;
} }
...@@ -134,7 +158,7 @@ testObjectMirror({}, 'Object', 'Object'); ...@@ -134,7 +158,7 @@ testObjectMirror({}, 'Object', 'Object');
testObjectMirror({'a':1,'b':2}, '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({'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(new Point(-1.2,2.003), 'Object', 'Point');
testObjectMirror(this, 'global', undefined, true); // Global object has special properties testObjectMirror(this, 'global', '', true); // Global object has special properties
testObjectMirror([], 'Array', 'Array'); testObjectMirror([], 'Array', 'Array');
testObjectMirror([1,2], 'Array', 'Array'); testObjectMirror([1,2], 'Array', 'Array');
......
...@@ -39,10 +39,24 @@ var expected_attributes = { ...@@ -39,10 +39,24 @@ var expected_attributes = {
'lastIndex': debug.PropertyAttribute.DontEnum | debug.PropertyAttribute.DontDelete '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) { function testRegExpMirror(r) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(r); var mirror = debug.MakeMirror(r);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
...@@ -54,10 +68,6 @@ function testRegExpMirror(r) { ...@@ -54,10 +68,6 @@ function testRegExpMirror(r) {
assertTrue(mirror.isRegExp()); assertTrue(mirror.isRegExp());
assertEquals('regexp', mirror.type()); assertEquals('regexp', mirror.type());
assertFalse(mirror.isPrimitive()); 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) { for (var p in expected_attributes) {
assertEquals(mirror.property(p).attributes(), assertEquals(mirror.property(p).attributes(),
expected_attributes[p], expected_attributes[p],
...@@ -71,16 +81,21 @@ function testRegExpMirror(r) { ...@@ -71,16 +81,21 @@ function testRegExpMirror(r) {
var fromJSON = eval('(' + json + ')'); var fromJSON = eval('(' + json + ')');
assertEquals('regexp', fromJSON.type); assertEquals('regexp', fromJSON.type);
assertEquals('RegExp', fromJSON.className); 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 p in expected_attributes) {
for (var i = 0; i < fromJSON.properties.length; i++) { for (var i = 0; i < fromJSON.properties.length; i++) {
if (fromJSON.properties[i].name == p) { if (fromJSON.properties[i].name == p) {
assertEquals(fromJSON.properties[i].attributes, assertEquals(expected_attributes[p],
expected_attributes[p], fromJSON.properties[i].attributes,
p + ' 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);
} }
} }
} }
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
function testScriptMirror(f, file_name, file_lines, script_type) { function testScriptMirror(f, file_name, file_lines, script_type) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(f).script(); var mirror = debug.MakeMirror(f).script();
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
print(json); var json = serializer.serializeValue(mirror);
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
......
...@@ -33,7 +33,8 @@ const kMaxProtocolStringLength = 80; // Constant from mirror-delay.js ...@@ -33,7 +33,8 @@ const kMaxProtocolStringLength = 80; // Constant from mirror-delay.js
function testStringMirror(s) { function testStringMirror(s) {
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(s); var mirror = debug.MakeMirror(s);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
// Create mirror and JSON representation. // Create mirror and JSON representation.
var mirror = debug.MakeMirror(void 0); var mirror = debug.MakeMirror(void 0);
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
// Check the mirror hierachy. // Check the mirror hierachy.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
......
...@@ -28,8 +28,22 @@ ...@@ -28,8 +28,22 @@
// Flags: --expose-debug-as debug // Flags: --expose-debug-as debug
// Test the mirror object for unresolved functions. // 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 mirror = new debug.UnresolvedFunctionMirror("f");
var json = mirror.toJSONProtocol(true); var serializer = debug.MakeMirrorSerializer();
var json = serializer.serializeValue(mirror);
var refs = new MirrorRefCache(serializer.serializeReferencedObjects());
// Check the mirror hierachy for unresolved functions. // Check the mirror hierachy for unresolved functions.
assertTrue(mirror instanceof debug.Mirror); assertTrue(mirror instanceof debug.Mirror);
...@@ -50,12 +64,15 @@ assertEquals('undefined', mirror.protoObject().type()); ...@@ -50,12 +64,15 @@ assertEquals('undefined', mirror.protoObject().type());
assertEquals('undefined', mirror.prototypeObject().type()); assertEquals('undefined', mirror.prototypeObject().type());
// Parse JSON representation of unresolved functions and check. // Parse JSON representation of unresolved functions and check.
/*var fromJSON = eval('(' + json + ')'); var fromJSON = eval('(' + json + ')');
assertEquals('function', fromJSON.type); assertEquals('function', fromJSON.type, 'Unexpected mirror type in JSON');
assertEquals('Function', fromJSON.className); assertEquals('Function', fromJSON.className, 'Unexpected mirror class name in JSON');
assertEquals('undefined', fromJSON.constructorFunction.type); assertEquals(mirror.constructorFunction().handle(), fromJSON.constructorFunction.ref, 'Unexpected constructor function handle in JSON');
assertEquals('undefined', fromJSON.protoObject.type); assertEquals('undefined', refs.lookup(fromJSON.constructorFunction.ref).type, 'Unexpected constructor function type in JSON');
assertEquals('undefined', fromJSON.prototypeObject.type); 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');
assertFalse(fromJSON.resolved); assertFalse(fromJSON.resolved);
assertEquals("f", fromJSON.name); assertEquals("f", fromJSON.name);
assertEquals(void 0, fromJSON.source);*/ assertEquals(void 0, fromJSON.source);
...@@ -34,14 +34,32 @@ Debug = debug.Debug ...@@ -34,14 +34,32 @@ Debug = debug.Debug
listenerCalled = false; listenerCalled = false;
exception = false; exception = false;
function safeEval(code) { function ParsedResponse(json) {
try { this.response_ = eval('(' + json + ')');
return eval('(' + code + ')'); this.refs_ = [];
} catch (e) { if (this.response_.refs) {
return undefined; for (var i = 0; i < this.response_.refs.length; i++) {
this.refs_[this.response_.refs[i].handle] = this.response_.refs[i];
}
} }
} }
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) { function listener(event, exec_state, event_data, data) {
try { try {
if (event == Debug.DebugEvent.Exception) if (event == Debug.DebugEvent.Exception)
...@@ -56,12 +74,13 @@ function listener(event, exec_state, event_data, data) { ...@@ -56,12 +74,13 @@ function listener(event, exec_state, event_data, data) {
// Get the backtrace. // Get the backtrace.
var json; var json;
json = '{"seq":0,"type":"request","command":"backtrace"}' json = '{"seq":0,"type":"request","command":"backtrace"}'
var backtrace = safeEval(dcp.processDebugJSONRequest(json)).body; var response = new ParsedResponse(dcp.processDebugJSONRequest(json));
var backtrace = response.body();
assertEquals(2, backtrace.totalFrames); assertEquals(2, backtrace.totalFrames);
assertEquals(2, backtrace.frames.length); assertEquals(2, backtrace.frames.length);
assertEquals("g", backtrace.frames[0].func.name); assertEquals("g", response.lookup(backtrace.frames[0].func.ref).name);
assertEquals("", backtrace.frames[1].func.name); assertEquals("", response.lookup(backtrace.frames[1].func.ref).name);
listenerCalled = true; 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