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 {
}
return { value : () => value,
isUndefined : () => isUndefined
isUndefined : () => isUndefined,
type : () => obj.type,
className : () => obj.className
};
}
......
......@@ -35,30 +35,15 @@ var exception = false;
function listener(event, exec_state, event_data, data) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor();
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);
var a = exec_state.frame(0).evaluate("a");
assertEquals('object', a.type());
assertEquals('Object', a.className());
// Indicate that all was processed.
listenerComplete = true;
}
} catch (e) {
print(e);
exception = e
};
};
......
......@@ -32,40 +32,6 @@ Debug = debug.Debug
listenerComplete = 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.
function listener(event, exec_state, event_data, data) {
try {
......@@ -76,23 +42,6 @@ function listener(event, exec_state, event_data, data) {
assertEquals(2, exec_state.evaluateGlobal('g()', true).value());
assertEquals(1, exec_state.frame(0).evaluate('f()', 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.
listenerComplete = true;
}
......
......@@ -29,8 +29,6 @@
// Get the Debug object exposed from the debug context global object.
Debug = debug.Debug
var evaluate_callback;
function listener(event, exec_state, event_data, data) {
if (event !== Debug.DebugEvent.Break) return;
try {
......@@ -39,37 +37,45 @@ function listener(event, exec_state, event_data, data) {
// Try in frame's scope.
var local_expression =
"(what_is_capybara ? what_is_capybara : 'a beast') + '/' + what_is_parrot";
var result = evaluate_callback.in_top_frame(exec_state, local_expression, context);
"(what_is_capybara ? what_is_capybara : 'a beast')" +
" + '/' + what_is_parrot";
var result = evaluate_callback.in_top_frame(
exec_state, local_expression, context);
assertEquals('a fish/a bird', result);
// 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);
// Try in frame's scope, without context.
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);
// Try in global additional scope.
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);
// Try in global scope with overridden global variables.
var context_with_undefined = { undefined: 'kitten' };
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);
// 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);
// Try in global scope without additional context.
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);
listenerComplete = true;
......@@ -101,45 +107,14 @@ function runF() {
evaluate_callback = {
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) {
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();
......@@ -32,91 +32,22 @@ Debug = debug.Debug
listenerComplete = 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) {
try {
if (event == Debug.DebugEvent.Break) {
// Get the debug command processor.
var dcp = exec_state.debugCommandProcessor("unspecified_running_state");
// Test some illegal evaluate requests.
testRequest(dcp, void 0, false);
testRequest(dcp, '{"expression":"1","global"=true}', false);
testRequest(dcp, '{"expression":"a","frame":4}', false);
assertEquals(3, exec_state.frame(0).evaluate("1+2").value());
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 legal evaluate requests.
testRequest(dcp, '{"expression":"1+2"}', true, 3);
testRequest(dcp, '{"expression":"a+2"}', true, 5);
testRequest(dcp, '{"expression":"({\\"a\\":1,\\"b\\":2}).b+2"}', true, 4);
assertEquals(3, exec_state.frame(0).evaluate("a").value());
assertEquals(2, exec_state.frame(1).evaluate("a").value());
assertEquals(1, exec_state.frame(2).evaluate("a").value());
// Test evaluation of a in the stack frames and the global context.
testRequest(dcp, '{"expression":"a"}', true, 3);
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);
assertEquals(1, exec_state.evaluateGlobal("a").value());
assertEquals(1, exec_state.evaluateGlobal("this.a").value());
// Test that the whole string text is returned if maxStringLength
// parameter is passed.
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);
assertEquals(longString,
exec_state.evaluateGlobal("this.longString").value());
// Indicate that all was processed.
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