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_ = function(sco pe_description) { |
Yang
2012/11/19 17:00:55
80 character limit.
Peter Rybin
2012/11/20 22:27:21
Done.
| |
1957 // Get the frame for which the scope or scopes are requested. | 1959 // Get the frame for which the scope or scopes are requested. |
1958 // With no frameNumber argument use the currently selected frame. | 1960 // With no frameNumber argument use the currently selected frame. |
1959 if (request.arguments && !IS_UNDEFINED(request.arguments.frameNumber)) { | 1961 if (scope_description && !IS_UNDEFINED(scope_description.frameNumber)) { |
1960 frame_index = request.arguments.frameNumber; | 1962 frame_index = scope_description.frameNumber; |
1961 if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { | 1963 if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { |
1962 throw new Error('Invalid frame number'); | 1964 throw new Error('Invalid frame number'); |
1963 } | 1965 } |
1964 return this.exec_state_.frame(frame_index); | 1966 return this.exec_state_.frame(frame_index); |
1965 } else { | 1967 } else { |
1966 return this.exec_state_.frame(); | 1968 return this.exec_state_.frame(); |
1967 } | 1969 } |
1968 }; | 1970 }; |
1969 | 1971 |
1970 | 1972 |
1971 // Gets scope host object from request. It is either a function | 1973 // Gets scope host object from request. It is either a function |
1972 // ('functionHandle' argument must be specified) or a stack frame | 1974 // ('functionHandle' argument must be specified) or a stack frame |
1973 // ('frameNumber' may be specified and the current frame is taken by default). | 1975 // ('frameNumber' may be specified and the current frame is taken by default). |
1974 DebugCommandProcessor.prototype.scopeHolderForScopeRequest_ = | 1976 DebugCommandProcessor.prototype.resolveScopeHolder_ = |
1975 function(request) { | 1977 function(scope_description) { |
1976 if (request.arguments && "functionHandle" in request.arguments) { | 1978 if (scope_description && "functionHandle" in scope_description) { |
1977 if (!IS_NUMBER(request.arguments.functionHandle)) { | 1979 if (!IS_NUMBER(scope_description.functionHandle)) { |
1978 throw new Error('Function handle must be a number'); | 1980 throw new Error('Function handle must be a number'); |
1979 } | 1981 } |
1980 var function_mirror = LookupMirror(request.arguments.functionHandle); | 1982 var function_mirror = LookupMirror(scope_description.functionHandle); |
1981 if (!function_mirror) { | 1983 if (!function_mirror) { |
1982 throw new Error('Failed to find function object by handle'); | 1984 throw new Error('Failed to find function object by handle'); |
1983 } | 1985 } |
1984 if (!function_mirror.isFunction()) { | 1986 if (!function_mirror.isFunction()) { |
1985 throw new Error('Value of non-function type is found by handle'); | 1987 throw new Error('Value of non-function type is found by handle'); |
1986 } | 1988 } |
1987 return function_mirror; | 1989 return function_mirror; |
1988 } else { | 1990 } else { |
1989 // No frames no scopes. | 1991 // No frames no scopes. |
1990 if (this.exec_state_.frameCount() == 0) { | 1992 if (this.exec_state_.frameCount() == 0) { |
1991 throw new Error('No scopes'); | 1993 throw new Error('No scopes'); |
1992 } | 1994 } |
1993 | 1995 |
1994 // Get the frame for which the scopes are requested. | 1996 // Get the frame for which the scopes are requested. |
1995 var frame = this.frameForScopeRequest_(request); | 1997 var frame = this.resolveFrameFromScopeDescription_(scope_description); |
1996 return frame; | 1998 return frame; |
1997 } | 1999 } |
1998 } | 2000 } |
1999 | 2001 |
2000 | 2002 |
2001 DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { | 2003 DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { |
2002 var scope_holder = this.scopeHolderForScopeRequest_(request); | 2004 var scope_holder = this.resolveScopeHolder_(request.arguments); |
2003 | 2005 |
2004 // Fill all scopes for this frame or function. | 2006 // Fill all scopes for this frame or function. |
2005 var total_scopes = scope_holder.scopeCount(); | 2007 var total_scopes = scope_holder.scopeCount(); |
2006 var scopes = []; | 2008 var scopes = []; |
2007 for (var i = 0; i < total_scopes; i++) { | 2009 for (var i = 0; i < total_scopes; i++) { |
2008 scopes.push(scope_holder.scope(i)); | 2010 scopes.push(scope_holder.scope(i)); |
2009 } | 2011 } |
2010 response.body = { | 2012 response.body = { |
2011 fromScope: 0, | 2013 fromScope: 0, |
2012 toScope: total_scopes, | 2014 toScope: total_scopes, |
2013 totalScopes: total_scopes, | 2015 totalScopes: total_scopes, |
2014 scopes: scopes | 2016 scopes: scopes |
2015 }; | 2017 }; |
2016 }; | 2018 }; |
2017 | 2019 |
2018 | 2020 |
2019 DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { | 2021 DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { |
2020 // Get the frame or function for which the scope is requested. | 2022 // Get the frame or function for which the scope is requested. |
2021 var scope_holder = this.scopeHolderForScopeRequest_(request); | 2023 var scope_holder = this.resolveScopeHolder_(request.arguments); |
2022 | 2024 |
2023 // With no scope argument just return top scope. | 2025 // With no scope argument just return top scope. |
2024 var scope_index = 0; | 2026 var scope_index = 0; |
2025 if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { | 2027 if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { |
2026 scope_index = %ToNumber(request.arguments.number); | 2028 scope_index = %ToNumber(request.arguments.number); |
2027 if (scope_index < 0 || scope_holder.scopeCount() <= scope_index) { | 2029 if (scope_index < 0 || scope_holder.scopeCount() <= scope_index) { |
2028 return response.failed('Invalid scope number'); | 2030 return response.failed('Invalid scope number'); |
2029 } | 2031 } |
2030 } | 2032 } |
2031 | 2033 |
2032 response.body = scope_holder.scope(scope_index); | 2034 response.body = scope_holder.scope(scope_index); |
2033 }; | 2035 }; |
2034 | 2036 |
2035 | 2037 |
2038 // Reads value from protocol description. Description may be in form of type | |
2039 // (for singletons), raw value (primitive types supported in JSON), | |
2040 // string value description plus type (for primitive values) or handle id. | |
2041 // Returns raw value or throws exception. | |
2042 DebugCommandProcessor.prototype.resolveValue_ = function(value_description) { | |
2043 if ("handle" in value_description) { | |
2044 var value_mirror = LookupMirror(value_description.handle); | |
2045 if (!context_value_mirror) { | |
Yang
2012/11/19 17:00:55
where does context_value_mirror come from?
you ma
Peter Rybin
2012/11/20 22:27:21
That's a bad error. Fixed. Added.
| |
2046 throw new Error("Failed to resolve value by handle, ' #" + | |
2047 mapping.handle + "# not found"); | |
2048 } | |
2049 return value_mirror.value(); | |
2050 } else if ("stringDescription" in value_description) { | |
2051 if (value_description.type == BOOLEAN_TYPE) { | |
2052 return Boolean(value_description.stringDescription); | |
2053 } else if (value_description.type == NUMBER_TYPE) { | |
2054 return Number(value_description.stringDescription); | |
2055 } if (value_description.type == STRING_TYPE) { | |
2056 return String(value_description.stringDescription); | |
2057 } else { | |
2058 throw new Error("Unknown type"); | |
2059 } | |
2060 } else if ("value" in value_description) { | |
2061 return value_description.value; | |
2062 } else if (value_description.type == UNDEFINED_TYPE) { | |
2063 return void 0; | |
2064 } else if (value_description.type == NULL_TYPE) { | |
2065 return null; | |
2066 } else { | |
2067 throw new Error("Failed to parse value description"); | |
2068 } | |
2069 }; | |
2070 | |
2071 | |
2072 DebugCommandProcessor.prototype.setVariableValueRequest_ = | |
2073 function(request, response) { | |
2074 if (!request.arguments) { | |
2075 response.failed('Missing arguments'); | |
2076 return; | |
2077 } | |
2078 | |
2079 if (IS_UNDEFINED(request.arguments.name)) { | |
2080 response.failed('Missing variable name'); | |
2081 } | |
2082 var variable_name = request.arguments.name; | |
2083 | |
2084 var scope_description = request.arguments.scope; | |
2085 | |
2086 // Get the frame or function for which the scope is requested. | |
2087 var scope_holder = this.resolveScopeHolder_(scope_description); | |
2088 | |
2089 if (IS_UNDEFINED(scope_description.number)) { | |
2090 response.failed('Missing scope number'); | |
2091 } | |
2092 var scope_index = %ToNumber(scope_description.number); | |
2093 | |
2094 var scope = scope_holder.scope(scope_index); | |
2095 | |
2096 var new_value = this.resolveValue_(request.arguments.newValue); | |
2097 | |
2098 scope.setVariableValue(variable_name, new_value); | |
2099 | |
2100 var new_value_mirror = MakeMirror(new_value); | |
2101 | |
2102 response.body = { | |
2103 newValue: new_value_mirror | |
2104 }; | |
2105 }; | |
2106 | |
2107 | |
2108 | |
2036 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { | 2109 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { |
2037 if (!request.arguments) { | 2110 if (!request.arguments) { |
2038 return response.failed('Missing arguments'); | 2111 return response.failed('Missing arguments'); |
2039 } | 2112 } |
2040 | 2113 |
2041 // Pull out arguments. | 2114 // Pull out arguments. |
2042 var expression = request.arguments.expression; | 2115 var expression = request.arguments.expression; |
2043 var frame = request.arguments.frame; | 2116 var frame = request.arguments.frame; |
2044 var global = request.arguments.global; | 2117 var global = request.arguments.global; |
2045 var disable_break = request.arguments.disable_break; | 2118 var disable_break = request.arguments.disable_break; |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2656 case 'string': | 2729 case 'string': |
2657 case 'number': | 2730 case 'number': |
2658 json = value; | 2731 json = value; |
2659 break; | 2732 break; |
2660 | 2733 |
2661 default: | 2734 default: |
2662 json = null; | 2735 json = null; |
2663 } | 2736 } |
2664 return json; | 2737 return json; |
2665 } | 2738 } |
OLD | NEW |