2009-01-26 13:44:37 +00:00
|
|
|
// Copyright 2009 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
|
|
|
|
// Get the Debug object exposed from the debug context global object.
|
|
|
|
Debug = debug.Debug
|
|
|
|
|
|
|
|
listenerComplete = false;
|
|
|
|
exception = false;
|
|
|
|
|
|
|
|
function safeEval(code) {
|
|
|
|
try {
|
|
|
|
return eval('(' + code + ')');
|
|
|
|
} catch (e) {
|
|
|
|
assertEquals(void 0, e);
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Send an evaluation request and return the handle of the result.
|
2009-10-15 20:06:08 +00:00
|
|
|
function evaluateRequest(exec_state, arguments) {
|
|
|
|
// Get the debug command processor.
|
|
|
|
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
|
|
|
|
|
2009-01-26 13:44:37 +00:00
|
|
|
// The base part of all evaluate requests.
|
|
|
|
var base_request = '"seq":0,"type":"request","command":"evaluate"'
|
|
|
|
|
|
|
|
// Generate request with the supplied arguments.
|
|
|
|
var request;
|
|
|
|
if (arguments) {
|
|
|
|
request = '{' + base_request + ',"arguments":' + arguments + '}';
|
|
|
|
} else {
|
|
|
|
request = '{' + base_request + '}'
|
|
|
|
}
|
|
|
|
|
|
|
|
var response = safeEval(dcp.processDebugJSONRequest(request));
|
|
|
|
assertTrue(response.success, request + ' -> ' + response.message);
|
|
|
|
|
|
|
|
return response.body.handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Send a lookup request and return the evaluated JSON response.
|
2009-10-15 20:06:08 +00:00
|
|
|
function lookupRequest(exec_state, arguments, success) {
|
|
|
|
// Get the debug command processor.
|
|
|
|
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
|
|
|
|
|
2009-01-26 13:44:37 +00:00
|
|
|
// The base part of all lookup requests.
|
|
|
|
var base_request = '"seq":0,"type":"request","command":"lookup"'
|
|
|
|
|
|
|
|
// Generate request with the supplied arguments.
|
|
|
|
var request;
|
|
|
|
if (arguments) {
|
|
|
|
request = '{' + base_request + ',"arguments":' + arguments + '}';
|
|
|
|
} else {
|
|
|
|
request = '{' + base_request + '}'
|
|
|
|
}
|
|
|
|
|
|
|
|
var response = safeEval(dcp.processDebugJSONRequest(request));
|
|
|
|
if (success) {
|
|
|
|
assertTrue(response.success, request + ' -> ' + response.message);
|
|
|
|
} else {
|
|
|
|
assertFalse(response.success, request + ' -> ' + response.message);
|
|
|
|
}
|
2009-10-15 20:06:08 +00:00
|
|
|
assertEquals(response.running, dcp.isRunning(), request + ' -> expected not running');
|
2009-01-26 13:44:37 +00:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function listener(event, exec_state, event_data, data) {
|
|
|
|
try {
|
|
|
|
if (event == Debug.DebugEvent.Break) {
|
|
|
|
// Test some illegal lookup requests.
|
2009-10-15 20:06:08 +00:00
|
|
|
lookupRequest(exec_state, void 0, false);
|
|
|
|
lookupRequest(exec_state, '{"handles":["a"]}', false);
|
|
|
|
lookupRequest(exec_state, '{"handles":[-1]}', false);
|
2009-01-26 13:44:37 +00:00
|
|
|
|
|
|
|
// Evaluate and get some handles.
|
2009-10-15 20:06:08 +00:00
|
|
|
var handle_o = evaluateRequest(exec_state, '{"expression":"o"}');
|
|
|
|
var handle_p = evaluateRequest(exec_state, '{"expression":"p"}');
|
|
|
|
var handle_b = evaluateRequest(exec_state, '{"expression":"a"}');
|
|
|
|
var handle_a = evaluateRequest(exec_state, '{"expression":"b","frame":1}');
|
2009-01-26 13:44:37 +00:00
|
|
|
assertEquals(handle_o, handle_a);
|
|
|
|
assertEquals(handle_a, handle_b);
|
|
|
|
assertFalse(handle_o == handle_p, "o and p have he same handle");
|
|
|
|
|
|
|
|
var response;
|
|
|
|
var count;
|
2009-10-15 20:06:08 +00:00
|
|
|
response = lookupRequest(exec_state, '{"handles":[' + handle_o + ']}', true);
|
2009-04-16 06:03:17 +00:00
|
|
|
var obj = response.body[handle_o];
|
|
|
|
assertTrue(!!obj, 'Object not found: ' + handle_o);
|
|
|
|
assertEquals(handle_o, obj.handle);
|
2009-01-26 13:44:37 +00:00
|
|
|
count = 0;
|
2009-04-16 06:03:17 +00:00
|
|
|
for (i in obj.properties) {
|
|
|
|
switch (obj.properties[i].name) {
|
2009-01-26 13:44:37 +00:00
|
|
|
case 'o':
|
2009-04-16 06:03:17 +00:00
|
|
|
obj.properties[i].ref = handle_o;
|
2009-01-26 13:44:37 +00:00
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
case 'p':
|
2009-04-16 06:03:17 +00:00
|
|
|
obj.properties[i].ref = handle_p;
|
2009-01-26 13:44:37 +00:00
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertEquals(2, count, 'Either "o" or "p" not found');
|
2009-10-15 20:06:08 +00:00
|
|
|
response = lookupRequest(exec_state, '{"handles":[' + handle_p + ']}', true);
|
2009-04-16 06:03:17 +00:00
|
|
|
obj = response.body[handle_p];
|
|
|
|
assertTrue(!!obj, 'Object not found: ' + handle_p);
|
|
|
|
assertEquals(handle_p, obj.handle);
|
2009-01-26 13:44:37 +00:00
|
|
|
|
|
|
|
// Check handles for functions on the stack.
|
2009-10-15 20:06:08 +00:00
|
|
|
var handle_f = evaluateRequest(exec_state, '{"expression":"f"}');
|
|
|
|
var handle_g = evaluateRequest(exec_state, '{"expression":"g"}');
|
|
|
|
var handle_caller = evaluateRequest(exec_state, '{"expression":"f.caller"}');
|
2009-01-26 13:44:37 +00:00
|
|
|
|
|
|
|
assertFalse(handle_f == handle_g, "f and g have he same handle");
|
|
|
|
assertEquals(handle_g, handle_caller, "caller for f should be g");
|
|
|
|
|
2009-10-15 20:06:08 +00:00
|
|
|
response = lookupRequest(exec_state, '{"handles":[' + handle_f + ']}', true);
|
2009-04-16 06:03:17 +00:00
|
|
|
obj = response.body[handle_f];
|
|
|
|
assertEquals(handle_f, obj.handle);
|
|
|
|
|
2009-01-26 13:44:37 +00:00
|
|
|
count = 0;
|
2009-04-16 06:03:17 +00:00
|
|
|
for (i in obj.properties) {
|
|
|
|
var ref = obj.properties[i].ref;
|
|
|
|
var arguments = '{"handles":[' + ref + ']}';
|
|
|
|
switch (obj.properties[i].name) {
|
2009-01-26 13:44:37 +00:00
|
|
|
case 'name':
|
|
|
|
var response_name;
|
2009-10-15 20:06:08 +00:00
|
|
|
response_name = lookupRequest(exec_state, arguments, true);
|
2009-04-16 06:03:17 +00:00
|
|
|
assertEquals('string', response_name.body[ref].type);
|
|
|
|
assertEquals("f", response_name.body[ref].value);
|
2009-01-26 13:44:37 +00:00
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
case 'length':
|
|
|
|
var response_length;
|
2009-10-15 20:06:08 +00:00
|
|
|
response_length = lookupRequest(exec_state, arguments, true);
|
2009-04-16 06:03:17 +00:00
|
|
|
assertEquals('number', response_length.body[ref].type);
|
|
|
|
assertEquals(1, response_length.body[ref].value);
|
2009-01-26 13:44:37 +00:00
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
case 'caller':
|
2009-04-16 06:03:17 +00:00
|
|
|
assertEquals(handle_g, obj.properties[i].ref);
|
2009-01-26 13:44:37 +00:00
|
|
|
count++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertEquals(3, count, 'Either "name", "length" or "caller" not found');
|
|
|
|
|
|
|
|
|
2009-04-16 06:03:17 +00:00
|
|
|
// Resolve all at once.
|
|
|
|
var refs = [];
|
|
|
|
for (i in obj.properties) {
|
|
|
|
refs.push(obj.properties[i].ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
var arguments = '{"handles":[' + refs.join(',') + ']}';
|
2009-10-15 20:06:08 +00:00
|
|
|
response = lookupRequest(exec_state, arguments, true);
|
2009-04-16 06:03:17 +00:00
|
|
|
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');
|
|
|
|
|
|
|
|
|
2009-01-26 13:44:37 +00:00
|
|
|
// Indicate that all was processed.
|
|
|
|
listenerComplete = true;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
exception = e
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add the debug event listener.
|
2009-02-03 07:59:12 +00:00
|
|
|
Debug.setListener(listener);
|
2009-01-26 13:44:37 +00:00
|
|
|
|
|
|
|
function f(a) {
|
|
|
|
debugger;
|
|
|
|
};
|
|
|
|
|
|
|
|
function g(b) {
|
|
|
|
f(b);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set a break point at return in f and invoke g to hit the breakpoint.
|
|
|
|
Debug.setBreakPoint(f, 2, 0);
|
|
|
|
o = {};
|
|
|
|
p = {}
|
|
|
|
o.o = o;
|
|
|
|
o.p = p;
|
|
|
|
p.o = o;
|
|
|
|
p.p = p;
|
|
|
|
g(o);
|
|
|
|
|
2009-10-15 20:06:08 +00:00
|
|
|
assertFalse(exception, "exception in listener")
|
2009-01-26 13:44:37 +00:00
|
|
|
// Make sure that the debug event listener vas invoked.
|
2009-04-16 06:03:17 +00:00
|
|
|
assertTrue(listenerComplete, "listener did not run to completion: " + exception);
|