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;
......
This diff is collapsed.
......@@ -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