OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1420 } else if (request.command == 'listbreakpoints') { | 1420 } else if (request.command == 'listbreakpoints') { |
1421 this.listBreakpointsRequest_(request, response); | 1421 this.listBreakpointsRequest_(request, response); |
1422 } else if (request.command == 'backtrace') { | 1422 } else if (request.command == 'backtrace') { |
1423 this.backtraceRequest_(request, response); | 1423 this.backtraceRequest_(request, response); |
1424 } else if (request.command == 'frame') { | 1424 } else if (request.command == 'frame') { |
1425 this.frameRequest_(request, response); | 1425 this.frameRequest_(request, response); |
1426 } else if (request.command == 'scopes') { | 1426 } else if (request.command == 'scopes') { |
1427 this.scopesRequest_(request, response); | 1427 this.scopesRequest_(request, response); |
1428 } else if (request.command == 'scope') { | 1428 } else if (request.command == 'scope') { |
1429 this.scopeRequest_(request, response); | 1429 this.scopeRequest_(request, response); |
1430 } else if (request.command == 'setVariableValue') { | |
1431 this.setVariableValueRequest_(request, response); | |
1430 } else if (request.command == 'evaluate') { | 1432 } else if (request.command == 'evaluate') { |
1431 this.evaluateRequest_(request, response); | 1433 this.evaluateRequest_(request, response); |
1432 } else if (lol_is_enabled && request.command == 'getobj') { | 1434 } else if (lol_is_enabled && request.command == 'getobj') { |
1433 this.getobjRequest_(request, response); | 1435 this.getobjRequest_(request, response); |
1434 } else if (request.command == 'lookup') { | 1436 } else if (request.command == 'lookup') { |
1435 this.lookupRequest_(request, response); | 1437 this.lookupRequest_(request, response); |
1436 } else if (request.command == 'references') { | 1438 } else if (request.command == 'references') { |
1437 this.referencesRequest_(request, response); | 1439 this.referencesRequest_(request, response); |
1438 } else if (request.command == 'source') { | 1440 } else if (request.command == 'source') { |
1439 this.sourceRequest_(request, response); | 1441 this.sourceRequest_(request, response); |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1946 if (index < 0 || this.exec_state_.frameCount() <= index) { | 1948 if (index < 0 || this.exec_state_.frameCount() <= index) { |
1947 return response.failed('Invalid frame number'); | 1949 return response.failed('Invalid frame number'); |
1948 } | 1950 } |
1949 | 1951 |
1950 this.exec_state_.setSelectedFrame(request.arguments.number); | 1952 this.exec_state_.setSelectedFrame(request.arguments.number); |
1951 } | 1953 } |
1952 response.body = this.exec_state_.frame(); | 1954 response.body = this.exec_state_.frame(); |
1953 }; | 1955 }; |
1954 | 1956 |
1955 | 1957 |
1956 DebugCommandProcessor.prototype.frameForScopeRequest_ = function(request) { | 1958 DebugCommandProcessor.prototype.resolveFrameFromScopeDescription_ = |
1959 function(scope_description) { | |
1957 // Get the frame for which the scope or scopes are requested. | 1960 // Get the frame for which the scope or scopes are requested. |
1958 // With no frameNumber argument use the currently selected frame. | 1961 // With no frameNumber argument use the currently selected frame. |
1959 if (request.arguments && !IS_UNDEFINED(request.arguments.frameNumber)) { | 1962 if (scope_description && !IS_UNDEFINED(scope_description.frameNumber)) { |
1960 frame_index = request.arguments.frameNumber; | 1963 frame_index = scope_description.frameNumber; |
1961 if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { | 1964 if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { |
1962 throw new Error('Invalid frame number'); | 1965 throw new Error('Invalid frame number'); |
1963 } | 1966 } |
1964 return this.exec_state_.frame(frame_index); | 1967 return this.exec_state_.frame(frame_index); |
1965 } else { | 1968 } else { |
1966 return this.exec_state_.frame(); | 1969 return this.exec_state_.frame(); |
1967 } | 1970 } |
1968 }; | 1971 }; |
1969 | 1972 |
1970 | 1973 |
1971 // Gets scope host object from request. It is either a function | 1974 // Gets scope host object from request. It is either a function |
1972 // ('functionHandle' argument must be specified) or a stack frame | 1975 // ('functionHandle' argument must be specified) or a stack frame |
1973 // ('frameNumber' may be specified and the current frame is taken by default). | 1976 // ('frameNumber' may be specified and the current frame is taken by default). |
1974 DebugCommandProcessor.prototype.scopeHolderForScopeRequest_ = | 1977 DebugCommandProcessor.prototype.resolveScopeHolder_ = |
1975 function(request) { | 1978 function(scope_description) { |
1976 if (request.arguments && "functionHandle" in request.arguments) { | 1979 if (scope_description && "functionHandle" in scope_description) { |
1977 if (!IS_NUMBER(request.arguments.functionHandle)) { | 1980 if (!IS_NUMBER(scope_description.functionHandle)) { |
1978 throw new Error('Function handle must be a number'); | 1981 throw new Error('Function handle must be a number'); |
1979 } | 1982 } |
1980 var function_mirror = LookupMirror(request.arguments.functionHandle); | 1983 var function_mirror = LookupMirror(scope_description.functionHandle); |
1981 if (!function_mirror) { | 1984 if (!function_mirror) { |
1982 throw new Error('Failed to find function object by handle'); | 1985 throw new Error('Failed to find function object by handle'); |
1983 } | 1986 } |
1984 if (!function_mirror.isFunction()) { | 1987 if (!function_mirror.isFunction()) { |
1985 throw new Error('Value of non-function type is found by handle'); | 1988 throw new Error('Value of non-function type is found by handle'); |
1986 } | 1989 } |
1987 return function_mirror; | 1990 return function_mirror; |
1988 } else { | 1991 } else { |
1989 // No frames no scopes. | 1992 // No frames no scopes. |
1990 if (this.exec_state_.frameCount() == 0) { | 1993 if (this.exec_state_.frameCount() == 0) { |
1991 throw new Error('No scopes'); | 1994 throw new Error('No scopes'); |
1992 } | 1995 } |
1993 | 1996 |
1994 // Get the frame for which the scopes are requested. | 1997 // Get the frame for which the scopes are requested. |
1995 var frame = this.frameForScopeRequest_(request); | 1998 var frame = this.resolveFrameFromScopeDescription_(scope_description); |
1996 return frame; | 1999 return frame; |
1997 } | 2000 } |
1998 } | 2001 } |
1999 | 2002 |
2000 | 2003 |
2001 DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { | 2004 DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { |
2002 var scope_holder = this.scopeHolderForScopeRequest_(request); | 2005 var scope_holder = this.resolveScopeHolder_(request.arguments); |
2003 | 2006 |
2004 // Fill all scopes for this frame or function. | 2007 // Fill all scopes for this frame or function. |
2005 var total_scopes = scope_holder.scopeCount(); | 2008 var total_scopes = scope_holder.scopeCount(); |
2006 var scopes = []; | 2009 var scopes = []; |
2007 for (var i = 0; i < total_scopes; i++) { | 2010 for (var i = 0; i < total_scopes; i++) { |
2008 scopes.push(scope_holder.scope(i)); | 2011 scopes.push(scope_holder.scope(i)); |
2009 } | 2012 } |
2010 response.body = { | 2013 response.body = { |
2011 fromScope: 0, | 2014 fromScope: 0, |
2012 toScope: total_scopes, | 2015 toScope: total_scopes, |
2013 totalScopes: total_scopes, | 2016 totalScopes: total_scopes, |
2014 scopes: scopes | 2017 scopes: scopes |
2015 }; | 2018 }; |
2016 }; | 2019 }; |
2017 | 2020 |
2018 | 2021 |
2019 DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { | 2022 DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { |
2020 // Get the frame or function for which the scope is requested. | 2023 // Get the frame or function for which the scope is requested. |
2021 var scope_holder = this.scopeHolderForScopeRequest_(request); | 2024 var scope_holder = this.resolveScopeHolder_(request.arguments); |
2022 | 2025 |
2023 // With no scope argument just return top scope. | 2026 // With no scope argument just return top scope. |
2024 var scope_index = 0; | 2027 var scope_index = 0; |
2025 if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { | 2028 if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { |
2026 scope_index = %ToNumber(request.arguments.number); | 2029 scope_index = %ToNumber(request.arguments.number); |
2027 if (scope_index < 0 || scope_holder.scopeCount() <= scope_index) { | 2030 if (scope_index < 0 || scope_holder.scopeCount() <= scope_index) { |
2028 return response.failed('Invalid scope number'); | 2031 return response.failed('Invalid scope number'); |
2029 } | 2032 } |
2030 } | 2033 } |
2031 | 2034 |
2032 response.body = scope_holder.scope(scope_index); | 2035 response.body = scope_holder.scope(scope_index); |
2033 }; | 2036 }; |
2034 | 2037 |
2035 | 2038 |
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"); | |
2049 } | |
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); | |
2058 } else { | |
2059 throw new Error("Unknown type"); | |
2060 } | |
2061 } else if ("value" in value_description) { | |
2062 return value_description.value; | |
2063 } else if (value_description.type == UNDEFINED_TYPE) { | |
2064 return void 0; | |
2065 } else if (value_description.type == NULL_TYPE) { | |
2066 return null; | |
2067 } else { | |
2068 throw new Error("Failed to parse value description"); | |
2069 } | |
2070 }; | |
2071 | |
2072 | |
2073 DebugCommandProcessor.prototype.setVariableValueRequest_ = | |
2074 function(request, response) { | |
2075 if (!request.arguments) { | |
2076 response.failed('Missing arguments'); | |
2077 return; | |
2078 } | |
2079 | |
2080 if (IS_UNDEFINED(request.arguments.name)) { | |
2081 response.failed('Missing variable name'); | |
2082 } | |
2083 var variable_name = request.arguments.name; | |
2084 | |
2085 var scope_description = request.arguments.scope; | |
2086 | |
2087 // Get the frame or function for which the scope is requested. | |
2088 var scope_holder = this.resolveScopeHolder_(scope_description); | |
Yang
2012/11/27 16:46:23
Somewhat confused. In here you pass request.argume
Peter Rybin
2012/11/27 18:24:28
I checked it again. It should be OK. For the new c
| |
2089 | |
2090 if (IS_UNDEFINED(scope_description.number)) { | |
2091 response.failed('Missing scope number'); | |
2092 } | |
2093 var scope_index = %ToNumber(scope_description.number); | |
2094 | |
2095 var scope = scope_holder.scope(scope_index); | |
2096 | |
2097 var new_value = | |
2098 DebugCommandProcessor.resolveValue_(request.arguments.newValue); | |
2099 | |
2100 scope.setVariableValue(variable_name, new_value); | |
2101 | |
2102 var new_value_mirror = MakeMirror(new_value); | |
2103 | |
2104 response.body = { | |
2105 newValue: new_value_mirror | |
2106 }; | |
2107 }; | |
2108 | |
2109 | |
2036 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { | 2110 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { |
2037 if (!request.arguments) { | 2111 if (!request.arguments) { |
2038 return response.failed('Missing arguments'); | 2112 return response.failed('Missing arguments'); |
2039 } | 2113 } |
2040 | 2114 |
2041 // Pull out arguments. | 2115 // Pull out arguments. |
2042 var expression = request.arguments.expression; | 2116 var expression = request.arguments.expression; |
2043 var frame = request.arguments.frame; | 2117 var frame = request.arguments.frame; |
2044 var global = request.arguments.global; | 2118 var global = request.arguments.global; |
2045 var disable_break = request.arguments.disable_break; | 2119 var disable_break = request.arguments.disable_break; |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2656 case 'string': | 2730 case 'string': |
2657 case 'number': | 2731 case 'number': |
2658 json = value; | 2732 json = value; |
2659 break; | 2733 break; |
2660 | 2734 |
2661 default: | 2735 default: |
2662 json = null; | 2736 json = null; |
2663 } | 2737 } |
2664 return json; | 2738 return json; |
2665 } | 2739 } |
2740 | |
2741 Debug.TestApi = { | |
2742 CommandProcessorResolveValue: DebugCommandProcessor.resolveValue_ | |
2743 }; | |
OLD | NEW |