1940
DebugCommandProcessor.prototype.frameForScopeRequest_ = function(request) {
1941
// Get the frame for which the scope or scopes are requested. With no frameNumber
1942
// argument use the currently selected frame.
1943
if (request.arguments && !IS_UNDEFINED(request.arguments.frameNumber)) {
1944
frame_index = request.arguments.frameNumber;
1958
DebugCommandProcessor.prototype.resolveFrameFromScopeDescription_ =
1959
function(scope_description) {
1960
// Get the frame for which the scope or scopes are requested.
1961
// With no frameNumber argument use the currently selected frame.
1962
if (scope_description && !IS_UNDEFINED(scope_description.frameNumber)) {
1963
frame_index = scope_description.frameNumber;
1945
1964
if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) {
1946
return response.failed('Invalid frame number');
1965
throw new Error('Invalid frame number');
1948
1967
return this.exec_state_.frame(frame_index);
1950
1969
return this.exec_state_.frame();
1974
// Gets scope host object from request. It is either a function
1975
// ('functionHandle' argument must be specified) or a stack frame
1976
// ('frameNumber' may be specified and the current frame is taken by default).
1977
DebugCommandProcessor.prototype.resolveScopeHolder_ =
1978
function(scope_description) {
1979
if (scope_description && "functionHandle" in scope_description) {
1980
if (!IS_NUMBER(scope_description.functionHandle)) {
1981
throw new Error('Function handle must be a number');
1983
var function_mirror = LookupMirror(scope_description.functionHandle);
1984
if (!function_mirror) {
1985
throw new Error('Failed to find function object by handle');
1987
if (!function_mirror.isFunction()) {
1988
throw new Error('Value of non-function type is found by handle');
1990
return function_mirror;
1992
// No frames no scopes.
1993
if (this.exec_state_.frameCount() == 0) {
1994
throw new Error('No scopes');
1997
// Get the frame for which the scopes are requested.
1998
var frame = this.resolveFrameFromScopeDescription_(scope_description);
1955
2004
DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) {
1956
// No frames no scopes.
1957
if (this.exec_state_.frameCount() == 0) {
1958
return response.failed('No scopes');
1961
// Get the frame for which the scopes are requested.
1962
var frame = this.frameForScopeRequest_(request);
1964
// Fill all scopes for this frame.
1965
var total_scopes = frame.scopeCount();
2005
var scope_holder = this.resolveScopeHolder_(request.arguments);
2007
// Fill all scopes for this frame or function.
2008
var total_scopes = scope_holder.scopeCount();
1966
2009
var scopes = [];
1967
2010
for (var i = 0; i < total_scopes; i++) {
1968
scopes.push(frame.scope(i));
2011
scopes.push(scope_holder.scope(i));
1970
2013
response.body = {
1972
2015
toScope: total_scopes,
1973
2016
totalScopes: total_scopes,
1979
2022
DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) {
1980
// No frames no scopes.
1981
if (this.exec_state_.frameCount() == 0) {
1982
return response.failed('No scopes');
1985
// Get the frame for which the scope is requested.
1986
var frame = this.frameForScopeRequest_(request);
2023
// Get the frame or function for which the scope is requested.
2024
var scope_holder = this.resolveScopeHolder_(request.arguments);
1988
2026
// With no scope argument just return top scope.
1989
2027
var scope_index = 0;
1990
2028
if (request.arguments && !IS_UNDEFINED(request.arguments.number)) {
1991
2029
scope_index = %ToNumber(request.arguments.number);
1992
if (scope_index < 0 || frame.scopeCount() <= scope_index) {
2030
if (scope_index < 0 || scope_holder.scopeCount() <= scope_index) {
1993
2031
return response.failed('Invalid scope number');
1997
response.body = frame.scope(scope_index);
2035
response.body = scope_holder.scope(scope_index);
2039
// Reads value from protocol description. Description may be in form of type
2040
// (for singletons), raw value (primitive types supported in JSON),
2041
// string value description plus type (for primitive values) or handle id.
2042
// Returns raw value or throws exception.
2043
DebugCommandProcessor.resolveValue_ = function(value_description) {
2044
if ("handle" in value_description) {
2045
var value_mirror = LookupMirror(value_description.handle);
2046
if (!value_mirror) {
2047
throw new Error("Failed to resolve value by handle, ' #" +
2048
mapping.handle + "# not found");
2050
return value_mirror.value();
2051
} else if ("stringDescription" in value_description) {
2052
if (value_description.type == BOOLEAN_TYPE) {
2053
return Boolean(value_description.stringDescription);
2054
} else if (value_description.type == NUMBER_TYPE) {
2055
return Number(value_description.stringDescription);
2056
} if (value_description.type == STRING_TYPE) {
2057
return String(value_description.stringDescription);
2059
throw new Error("Unknown type");
2061
} else if ("value" in value_description) {
2062
return value_description.value;
2063
} else if (value_description.type == UNDEFINED_TYPE) {
2065
} else if (value_description.type == NULL_TYPE) {
2068
throw new Error("Failed to parse value description");
2073
DebugCommandProcessor.prototype.setVariableValueRequest_ =
2074
function(request, response) {
2075
if (!request.arguments) {
2076
response.failed('Missing arguments');
2080
if (IS_UNDEFINED(request.arguments.name)) {
2081
response.failed('Missing variable name');
2083
var variable_name = request.arguments.name;
2085
var scope_description = request.arguments.scope;
2087
// Get the frame or function for which the scope is requested.
2088
var scope_holder = this.resolveScopeHolder_(scope_description);
2090
if (IS_UNDEFINED(scope_description.number)) {
2091
response.failed('Missing scope number');
2093
var scope_index = %ToNumber(scope_description.number);
2095
var scope = scope_holder.scope(scope_index);
2098
DebugCommandProcessor.resolveValue_(request.arguments.newValue);
2100
scope.setVariableValue(variable_name, new_value);
2102
var new_value_mirror = MakeMirror(new_value);
2105
newValue: new_value_mirror
2474
DebugCommandProcessor.prototype.restartFrameRequest_ = function(
2475
request, response) {
2476
if (!request.arguments) {
2477
return response.failed('Missing arguments');
2479
var frame = request.arguments.frame;
2481
// No frames to evaluate in frame.
2482
if (this.exec_state_.frameCount() == 0) {
2483
return response.failed('No frames');
2487
// Check whether a frame was specified.
2488
if (!IS_UNDEFINED(frame)) {
2489
var frame_number = %ToNumber(frame);
2490
if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) {
2491
return response.failed('Invalid frame "' + frame + '"');
2493
// Restart specified frame.
2494
frame_mirror = this.exec_state_.frame(frame_number);
2496
// Restart selected frame.
2497
frame_mirror = this.exec_state_.frame();
2500
var result_description = Debug.LiveEdit.RestartFrame(frame_mirror);
2501
response.body = {result: result_description};
2366
2505
DebugCommandProcessor.prototype.debuggerFlagsRequest_ = function(request,
2368
2507
// Check for legal request.