Commit e1470db7 authored by yangguo's avatar yangguo Committed by Commit bot

[debug] remove debug command processor from debug evaluate tests.

R=jgruber@chromium.org
BUG=v8:5510

Review-Url: https://codereview.chromium.org/2532893002
Cr-Commit-Position: refs/heads/master@{#41308}
parent b31cbbd4
...@@ -639,7 +639,9 @@ class DebugWrapper { ...@@ -639,7 +639,9 @@ class DebugWrapper {
} }
return { value : () => value, return { value : () => value,
isUndefined : () => isUndefined isUndefined : () => isUndefined,
type : () => obj.type,
className : () => obj.className
}; };
} }
......
...@@ -35,30 +35,15 @@ var exception = false; ...@@ -35,30 +35,15 @@ var exception = false;
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) {
// Get the debug command processor. var a = exec_state.frame(0).evaluate("a");
var dcp = exec_state.debugCommandProcessor(); assertEquals('object', a.type());
assertEquals('Object', a.className());
var request = {
seq: 0,
type: 'request',
command: 'evaluate',
arguments: {
expression: 'a',
frame: 0
}
};
request = JSON.stringify(request);
var resp = dcp.processDebugJSONRequest(request);
var response = JSON.parse(resp);
assertTrue(response.success, 'Command failed: ' + resp);
assertEquals('object', response.body.type);
assertEquals('Object', response.body.className);
// Indicate that all was processed. // Indicate that all was processed.
listenerComplete = true; listenerComplete = true;
} }
} catch (e) { } catch (e) {
print(e);
exception = e exception = e
}; };
}; };
......
...@@ -32,40 +32,6 @@ Debug = debug.Debug ...@@ -32,40 +32,6 @@ Debug = debug.Debug
listenerComplete = false; listenerComplete = false;
exception = false; exception = false;
// The base part of all evaluate requests.
var base_request = '"seq":0,"type":"request","command":"evaluate"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testRequest(exec_state, arguments, success, result) {
// Get the debug command processor in paused state.
var dcp = exec_state.debugCommandProcessor(false);
// 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);
assertEquals(result, response.body.value);
} else {
assertFalse(response.success, request + ' -> ' + response.message);
}
assertFalse(response.running, request + ' -> expected not running');
}
// Event listener which evaluates with break disabled. // Event listener which evaluates with break disabled.
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
try { try {
...@@ -76,23 +42,6 @@ function listener(event, exec_state, event_data, data) { ...@@ -76,23 +42,6 @@ function listener(event, exec_state, event_data, data) {
assertEquals(2, exec_state.evaluateGlobal('g()', true).value()); assertEquals(2, exec_state.evaluateGlobal('g()', true).value());
assertEquals(1, exec_state.frame(0).evaluate('f()', true).value()); assertEquals(1, exec_state.frame(0).evaluate('f()', true).value());
assertEquals(2, exec_state.frame(0).evaluate('g()', true).value()); assertEquals(2, exec_state.frame(0).evaluate('g()', true).value());
// Call functions with break using the JSON protocol. Tests that argument
// disable_break is default true.
testRequest(exec_state, '{"expression":"f()"}', true, 1);
testRequest(exec_state, '{"expression":"f()","frame":0}', true, 1);
testRequest(exec_state, '{"expression":"g()"}', true, 2);
testRequest(exec_state, '{"expression":"g()","frame":0}', true, 2);
// Call functions with break using the JSON protocol. Tests passing
// argument disable_break is default true.
testRequest(exec_state, '{"expression":"f()","disable_break":true}', true, 1);
testRequest(exec_state, '{"expression":"f()","frame":0,"disable_break":true}',
true, 1);
testRequest(exec_state, '{"expression":"g()","disable_break":true}', true, 2);
testRequest(exec_state, '{"expression":"g()","frame":0,"disable_break":true}',
true, 2);
// Indicate that all was processed. // Indicate that all was processed.
listenerComplete = true; listenerComplete = true;
} }
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
// Get the Debug object exposed from the debug context global object. // Get the Debug object exposed from the debug context global object.
Debug = debug.Debug Debug = debug.Debug
var evaluate_callback;
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
if (event !== Debug.DebugEvent.Break) return; if (event !== Debug.DebugEvent.Break) return;
try { try {
...@@ -39,37 +37,45 @@ function listener(event, exec_state, event_data, data) { ...@@ -39,37 +37,45 @@ function listener(event, exec_state, event_data, data) {
// Try in frame's scope. // Try in frame's scope.
var local_expression = var local_expression =
"(what_is_capybara ? what_is_capybara : 'a beast') + '/' + what_is_parrot"; "(what_is_capybara ? what_is_capybara : 'a beast')" +
var result = evaluate_callback.in_top_frame(exec_state, local_expression, context); " + '/' + what_is_parrot";
var result = evaluate_callback.in_top_frame(
exec_state, local_expression, context);
assertEquals('a fish/a bird', result); assertEquals('a fish/a bird', result);
// Try in frame's scope with overrididen local variables. // Try in frame's scope with overrididen local variables.
var result = evaluate_callback.in_top_frame(exec_state, local_expression, context2); var result = evaluate_callback.in_top_frame(
exec_state, local_expression, context2);
assertEquals('a fish/a beard', result); assertEquals('a fish/a beard', result);
// Try in frame's scope, without context. // Try in frame's scope, without context.
var local_expression2 = "what_is_parrot"; var local_expression2 = "what_is_parrot";
var result = evaluate_callback.in_top_frame(exec_state, local_expression2, void 0); var result = evaluate_callback.in_top_frame(
exec_state, local_expression2, void 0);
assertEquals('a bird', result); assertEquals('a bird', result);
// Try in global additional scope. // Try in global additional scope.
var global_expression = "what_is_capybara ? what_is_capybara : 'a beast'"; var global_expression = "what_is_capybara ? what_is_capybara : 'a beast'";
var result = evaluate_callback.globally(exec_state, global_expression, context); var result = evaluate_callback.globally(
exec_state, global_expression, context);
assertEquals('a fish', result); assertEquals('a fish', result);
// Try in global scope with overridden global variables. // Try in global scope with overridden global variables.
var context_with_undefined = { undefined: 'kitten' }; var context_with_undefined = { undefined: 'kitten' };
var global_expression2 = "'cat' + '/' + undefined"; var global_expression2 = "'cat' + '/' + undefined";
var result = evaluate_callback.globally(exec_state, global_expression2, context_with_undefined); var result = evaluate_callback.globally(
exec_state, global_expression2, context_with_undefined);
assertEquals('cat/kitten', result); assertEquals('cat/kitten', result);
// Try in global scope with no overridden global variables. // Try in global scope with no overridden global variables.
var result = evaluate_callback.globally(exec_state, global_expression2, void 0); var result = evaluate_callback.globally(
exec_state, global_expression2, void 0);
assertEquals('cat/undefined', result); assertEquals('cat/undefined', result);
// Try in global scope without additional context. // Try in global scope without additional context.
var global_expression3 = "'cat' + '/' + 'dog'"; var global_expression3 = "'cat' + '/' + 'dog'";
var result = evaluate_callback.globally(exec_state, global_expression3, void 0); var result = evaluate_callback.globally(
exec_state, global_expression3, void 0);
assertEquals('cat/dog', result); assertEquals('cat/dog', result);
listenerComplete = true; listenerComplete = true;
...@@ -101,45 +107,14 @@ function runF() { ...@@ -101,45 +107,14 @@ function runF() {
evaluate_callback = { evaluate_callback = {
in_top_frame: function(exec_state, expression, additional_context) { in_top_frame: function(exec_state, expression, additional_context) {
return exec_state.frame(0).evaluate(expression, void 0, additional_context).value(); return exec_state.frame(0).evaluate(
expression, void 0, additional_context).value();
}, },
globally: function(exec_state, expression, additional_context) { globally: function(exec_state, expression, additional_context) {
return exec_state.evaluateGlobal(expression, void 0, additional_context).value(); return exec_state.evaluateGlobal(
expression, void 0, additional_context).value();
}, },
}; };
runF();
// Now try all the same, but via debug protocol.
function evaluateViaProtocol(exec_state, expression, additional_context, frame_argument_adder) {
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
request_json = {"seq":17,"type":"request","command":"evaluate", arguments: { "expression": expression } };
frame_argument_adder(request_json.arguments);
if (additional_context) {
var context_json = [];
for (var key in additional_context) {
context_json.push({ name: key, handle: Debug.MakeMirror(additional_context[key]).handle() });
}
request_json.arguments.additional_context = context_json;
}
var request = JSON.stringify(request_json);
var response_json = dcp.processDebugJSONRequest(request);
var response = JSON.parse(response_json);
assertTrue(response.success);
var str_result = response.body.value;
return str_result;
}
evaluate_callback = {
in_top_frame: function(exec_state, expression, additional_context) {
return evaluateViaProtocol(exec_state, expression, additional_context, function(args) { args.frame = 0; });
},
globally: function(exec_state, expression, additional_context) {
return evaluateViaProtocol(exec_state, expression, additional_context, function(args) { args.global = true; });
},
};
runF(); runF();
...@@ -32,91 +32,22 @@ Debug = debug.Debug ...@@ -32,91 +32,22 @@ Debug = debug.Debug
listenerComplete = false; listenerComplete = false;
exception = false; exception = false;
// The base part of all evaluate requests.
var base_request = '"seq":0,"type":"request","command":"evaluate"'
function safeEval(code) {
try {
return eval('(' + code + ')');
} catch (e) {
assertEquals(void 0, e);
return undefined;
}
}
function testRequest(dcp, arguments, success, result) {
// 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);
assertEquals(result, response.body.value);
} else {
assertFalse(response.success, request + ' -> ' + response.message);
}
assertEquals(response.running, "unspecified_running_state",
request + ' -> expected not running');
}
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) {
// Get the debug command processor. assertEquals(3, exec_state.frame(0).evaluate("1+2").value());
var dcp = exec_state.debugCommandProcessor("unspecified_running_state"); assertEquals(5, exec_state.frame(0).evaluate("a+2").value());
assertEquals(4, exec_state.frame(0).evaluate("({a:1,b:2}).b+2").value());
// Test some illegal evaluate requests.
testRequest(dcp, void 0, false);
testRequest(dcp, '{"expression":"1","global"=true}', false);
testRequest(dcp, '{"expression":"a","frame":4}', false);
// Test some legal evaluate requests. assertEquals(3, exec_state.frame(0).evaluate("a").value());
testRequest(dcp, '{"expression":"1+2"}', true, 3); assertEquals(2, exec_state.frame(1).evaluate("a").value());
testRequest(dcp, '{"expression":"a+2"}', true, 5); assertEquals(1, exec_state.frame(2).evaluate("a").value());
testRequest(dcp, '{"expression":"({\\"a\\":1,\\"b\\":2}).b+2"}', true, 4);
// Test evaluation of a in the stack frames and the global context. assertEquals(1, exec_state.evaluateGlobal("a").value());
testRequest(dcp, '{"expression":"a"}', true, 3); assertEquals(1, exec_state.evaluateGlobal("this.a").value());
testRequest(dcp, '{"expression":"a","frame":0}', true, 3);
testRequest(dcp, '{"expression":"a","frame":1}', true, 2);
testRequest(dcp, '{"expression":"a","frame":2}', true, 1);
testRequest(dcp, '{"expression":"a","global":true}', true, 1);
testRequest(dcp, '{"expression":"this.a","global":true}', true, 1);
// Test that the whole string text is returned if maxStringLength assertEquals(longString,
// parameter is passed. exec_state.evaluateGlobal("this.longString").value());
testRequest(
dcp,
'{"expression":"this.longString","global":true,"maxStringLength":-1}',
true,
longString);
testRequest(
dcp,
'{"expression":"this.longString","global":true,"maxStringLength":' +
longString.length + '}',
true,
longString);
var truncatedStringSuffix = '... (length: ' + longString.length + ')';
testRequest(
dcp,
'{"expression":"this.longString","global":true,"maxStringLength":0}',
true,
truncatedStringSuffix);
testRequest(
dcp,
'{"expression":"this.longString","global":true,"maxStringLength":1}',
true,
longString.charAt(0) + truncatedStringSuffix);
// Test that by default string is truncated to first 80 chars.
testRequest(
dcp,
'{"expression":"this.longString","global":true}',
true,
longString.substring(0, 80) + truncatedStringSuffix);
// Indicate that all was processed. // Indicate that all was processed.
listenerComplete = true; listenerComplete = 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