Commit b92740bf authored by yurys@chromium.org's avatar yurys@chromium.org

Lookup can now be performed for several handles.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1719 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9f7ccacf
......@@ -1547,20 +1547,24 @@ DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) {
}
// Pull out arguments.
var handle = request.arguments.handle;
var handles = request.arguments.handles;
// Check for legal arguments.
if (IS_UNDEFINED(handle)) {
return response.failed('Argument "handle" missing');
if (IS_UNDEFINED(handles)) {
return response.failed('Argument "handles" missing');
}
// Lookup handle.
var mirror = LookupMirror(handle);
if (mirror) {
response.body = mirror;
} else {
return response.failed('Object #' + handle + '# not found');
// Lookup handles.
var mirrors = {};
for (var i = 0; i < handles.length; i++) {
var handle = handles[i];
var mirror = LookupMirror(handle);
if (!mirror) {
return response.failed('Object #' + handle + '# not found');
}
mirrors[handle] = mirror;
}
response.body = mirrors;
};
......
......@@ -95,8 +95,8 @@ function listener(event, exec_state, event_data, data) {
// Test some illegal lookup requests.
lookupRequest(dcp, void 0, false);
lookupRequest(dcp, '{"handle":"a"}', false);
lookupRequest(dcp, '{"handle":-1}', false);
lookupRequest(dcp, '{"handles":["a"]}', false);
lookupRequest(dcp, '{"handles":[-1]}', false);
// Evaluate and get some handles.
var handle_o = evaluateRequest(dcp, '{"expression":"o"}');
......@@ -109,24 +109,28 @@ function listener(event, exec_state, event_data, data) {
var response;
var count;
response = lookupRequest(dcp, '{"handle":' + handle_o + '}', true);
assertEquals(handle_o, response.body.handle);
response = lookupRequest(dcp, '{"handles":[' + handle_o + ']}', true);
var obj = response.body[handle_o];
assertTrue(!!obj, 'Object not found: ' + handle_o);
assertEquals(handle_o, obj.handle);
count = 0;
for (i in response.body.properties) {
switch (response.body.properties[i].name) {
for (i in obj.properties) {
switch (obj.properties[i].name) {
case 'o':
response.body.properties[i].ref = handle_o;
obj.properties[i].ref = handle_o;
count++;
break;
case 'p':
response.body.properties[i].ref = handle_p;
obj.properties[i].ref = handle_p;
count++;
break;
}
}
assertEquals(2, count, 'Either "o" or "p" not found');
response = lookupRequest(dcp, '{"handle":' + handle_p + '}', true);
assertEquals(handle_p, response.body.handle);
response = lookupRequest(dcp, '{"handles":[' + handle_p + ']}', true);
obj = response.body[handle_p];
assertTrue(!!obj, 'Object not found: ' + handle_p);
assertEquals(handle_p, obj.handle);
// Check handles for functions on the stack.
var handle_f = evaluateRequest(dcp, '{"expression":"f"}');
......@@ -136,28 +140,31 @@ function listener(event, exec_state, event_data, data) {
assertFalse(handle_f == handle_g, "f and g have he same handle");
assertEquals(handle_g, handle_caller, "caller for f should be g");
response = lookupRequest(dcp, '{"handle":' + handle_f + '}', true);
assertEquals(handle_f, response.body.handle);
response = lookupRequest(dcp, '{"handles":[' + handle_f + ']}', true);
obj = response.body[handle_f];
assertEquals(handle_f, obj.handle);
count = 0;
for (i in response.body.properties) {
var arguments = '{"handle":' + response.body.properties[i].ref + '}'
switch (response.body.properties[i].name) {
for (i in obj.properties) {
var ref = obj.properties[i].ref;
var arguments = '{"handles":[' + ref + ']}';
switch (obj.properties[i].name) {
case 'name':
var response_name;
response_name = lookupRequest(dcp, arguments, true);
assertEquals('string', response_name.body.type);
assertEquals("f", response_name.body.value);
assertEquals('string', response_name.body[ref].type);
assertEquals("f", response_name.body[ref].value);
count++;
break;
case 'length':
var response_length;
response_length = lookupRequest(dcp, arguments, true);
assertEquals('number', response_length.body.type);
assertEquals(1, response_length.body.value);
assertEquals('number', response_length.body[ref].type);
assertEquals(1, response_length.body[ref].value);
count++;
break;
case 'caller':
assertEquals(handle_g, response.body.properties[i].ref);
assertEquals(handle_g, obj.properties[i].ref);
count++;
break;
}
......@@ -165,6 +172,49 @@ function listener(event, exec_state, event_data, data) {
assertEquals(3, count, 'Either "name", "length" or "caller" not found');
// Resolve all at once.
var refs = [];
for (i in obj.properties) {
refs.push(obj.properties[i].ref);
}
var arguments = '{"handles":[' + refs.join(',') + ']}';
response = lookupRequest(dcp, arguments, true);
count = 0;
for (i in obj.properties) {
var ref = obj.properties[i].ref;
var val = response.body[ref];
assertTrue(!!val, 'Failed to lookup "' + obj.properties[i].name + '"');
switch (obj.properties[i].name) {
case 'name':
assertEquals('string', val.type);
assertEquals("f", val.value);
count++;
break;
case 'length':
assertEquals('number', val.type);
assertEquals(1, val.value);
count++;
break;
case 'caller':
assertEquals('function', val.type);
assertEquals(handle_g, ref);
count++;
break;
}
}
assertEquals(3, count, 'Either "name", "length" or "caller" not found');
count = 0;
for (var handle in response.body) {
assertTrue(refs.indexOf(parseInt(handle)) != -1,
'Handle not in the request: ' + handle);
count++;
}
assertEquals(count, obj.properties.length,
'Unexpected number of resolved objects');
// Indicate that all was processed.
listenerComplete = true;
}
......@@ -195,5 +245,5 @@ p.p = p;
g(o);
// Make sure that the debug event listener vas invoked.
assertTrue(listenerComplete, "listener did not run to completion");
assertTrue(listenerComplete, "listener did not run to completion: " + exception);
assertFalse(exception, "exception in listener")
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