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 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 response.body = this.exec_state_.frame(); | 1950 response.body = this.exec_state_.frame(); |
1951 }; | 1951 }; |
1952 | 1952 |
1953 | 1953 |
1954 DebugCommandProcessor.prototype.frameForScopeRequest_ = function(request) { | 1954 DebugCommandProcessor.prototype.frameForScopeRequest_ = function(request) { |
1955 // Get the frame for which the scope or scopes are requested. | 1955 // Get the frame for which the scope or scopes are requested. |
1956 // With no frameNumber argument use the currently selected frame. | 1956 // With no frameNumber argument use the currently selected frame. |
1957 if (request.arguments && !IS_UNDEFINED(request.arguments.frameNumber)) { | 1957 if (request.arguments && !IS_UNDEFINED(request.arguments.frameNumber)) { |
1958 frame_index = request.arguments.frameNumber; | 1958 frame_index = request.arguments.frameNumber; |
1959 if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { | 1959 if (frame_index < 0 || this.exec_state_.frameCount() <= frame_index) { |
1960 return response.failed('Invalid frame number'); | 1960 throw new Error('Invalid frame number'); |
1961 } | 1961 } |
1962 return this.exec_state_.frame(frame_index); | 1962 return this.exec_state_.frame(frame_index); |
1963 } else { | 1963 } else { |
1964 return this.exec_state_.frame(); | 1964 return this.exec_state_.frame(); |
1965 } | 1965 } |
1966 }; | 1966 }; |
1967 | 1967 |
1968 | 1968 |
| 1969 // Gets scope host object from request. It is either a function |
| 1970 // ('functionHandle' argument must be specified) or a stack frame |
| 1971 // ('frameNumber' may be specified and the current frame is taken by default). |
| 1972 DebugCommandProcessor.prototype.scopeHolderForScopeRequest_ = |
| 1973 function(request) { |
| 1974 if (request.arguments && "functionHandle" in request.arguments) { |
| 1975 if (!IS_NUMBER(request.arguments.functionHandle)) { |
| 1976 throw new Error('Function handle must be a number'); |
| 1977 } |
| 1978 var function_mirror = LookupMirror(request.arguments.functionHandle); |
| 1979 if (!function_mirror) { |
| 1980 throw new Error('Failed to find function object by handle'); |
| 1981 } |
| 1982 if (!function_mirror.isFunction()) { |
| 1983 throw new Error('Value of non-function type is found by handle'); |
| 1984 } |
| 1985 return function_mirror; |
| 1986 } else { |
| 1987 // No frames no scopes. |
| 1988 if (this.exec_state_.frameCount() == 0) { |
| 1989 throw new Error('No scopes'); |
| 1990 } |
| 1991 |
| 1992 // Get the frame for which the scopes are requested. |
| 1993 var frame = this.frameForScopeRequest_(request); |
| 1994 return frame; |
| 1995 } |
| 1996 } |
| 1997 |
| 1998 |
1969 DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { | 1999 DebugCommandProcessor.prototype.scopesRequest_ = function(request, response) { |
1970 // No frames no scopes. | 2000 var scope_holder = this.scopeHolderForScopeRequest_(request); |
1971 if (this.exec_state_.frameCount() == 0) { | |
1972 return response.failed('No scopes'); | |
1973 } | |
1974 | 2001 |
1975 // Get the frame for which the scopes are requested. | 2002 // Fill all scopes for this frame or function. |
1976 var frame = this.frameForScopeRequest_(request); | 2003 var total_scopes = scope_holder.scopeCount(); |
1977 | |
1978 // Fill all scopes for this frame. | |
1979 var total_scopes = frame.scopeCount(); | |
1980 var scopes = []; | 2004 var scopes = []; |
1981 for (var i = 0; i < total_scopes; i++) { | 2005 for (var i = 0; i < total_scopes; i++) { |
1982 scopes.push(frame.scope(i)); | 2006 scopes.push(scope_holder.scope(i)); |
1983 } | 2007 } |
1984 response.body = { | 2008 response.body = { |
1985 fromScope: 0, | 2009 fromScope: 0, |
1986 toScope: total_scopes, | 2010 toScope: total_scopes, |
1987 totalScopes: total_scopes, | 2011 totalScopes: total_scopes, |
1988 scopes: scopes | 2012 scopes: scopes |
1989 }; | 2013 }; |
1990 }; | 2014 }; |
1991 | 2015 |
1992 | 2016 |
1993 DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { | 2017 DebugCommandProcessor.prototype.scopeRequest_ = function(request, response) { |
1994 // No frames no scopes. | 2018 // Get the frame or function for which the scope is requested. |
1995 if (this.exec_state_.frameCount() == 0) { | 2019 var scope_holder = this.scopeHolderForScopeRequest_(request); |
1996 return response.failed('No scopes'); | |
1997 } | |
1998 | |
1999 // Get the frame for which the scope is requested. | |
2000 var frame = this.frameForScopeRequest_(request); | |
2001 | 2020 |
2002 // With no scope argument just return top scope. | 2021 // With no scope argument just return top scope. |
2003 var scope_index = 0; | 2022 var scope_index = 0; |
2004 if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { | 2023 if (request.arguments && !IS_UNDEFINED(request.arguments.number)) { |
2005 scope_index = %ToNumber(request.arguments.number); | 2024 scope_index = %ToNumber(request.arguments.number); |
2006 if (scope_index < 0 || frame.scopeCount() <= scope_index) { | 2025 if (scope_index < 0 || scope_holder.scopeCount() <= scope_index) { |
2007 return response.failed('Invalid scope number'); | 2026 return response.failed('Invalid scope number'); |
2008 } | 2027 } |
2009 } | 2028 } |
2010 | 2029 |
2011 response.body = frame.scope(scope_index); | 2030 response.body = scope_holder.scope(scope_index); |
2012 }; | 2031 }; |
2013 | 2032 |
2014 | 2033 |
2015 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { | 2034 DebugCommandProcessor.prototype.evaluateRequest_ = function(request, response) { |
2016 if (!request.arguments) { | 2035 if (!request.arguments) { |
2017 return response.failed('Missing arguments'); | 2036 return response.failed('Missing arguments'); |
2018 } | 2037 } |
2019 | 2038 |
2020 // Pull out arguments. | 2039 // Pull out arguments. |
2021 var expression = request.arguments.expression; | 2040 var expression = request.arguments.expression; |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2607 case 'string': | 2626 case 'string': |
2608 case 'number': | 2627 case 'number': |
2609 json = value; | 2628 json = value; |
2610 break; | 2629 break; |
2611 | 2630 |
2612 default: | 2631 default: |
2613 json = null; | 2632 json = null; |
2614 } | 2633 } |
2615 return json; | 2634 return json; |
2616 } | 2635 } |
OLD | NEW |