OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 | 1959 |
1960 | 1960 |
1961 DebugCommandProcessor.prototype.changeLiveRequest_ = function(request, response)
{ | 1961 DebugCommandProcessor.prototype.changeLiveRequest_ = function(request, response)
{ |
1962 if (!Debug.LiveEditChangeScript) { | 1962 if (!Debug.LiveEditChangeScript) { |
1963 return response.failed('LiveEdit feature is not supported'); | 1963 return response.failed('LiveEdit feature is not supported'); |
1964 } | 1964 } |
1965 if (!request.arguments) { | 1965 if (!request.arguments) { |
1966 return response.failed('Missing arguments'); | 1966 return response.failed('Missing arguments'); |
1967 } | 1967 } |
1968 var script_id = request.arguments.script_id; | 1968 var script_id = request.arguments.script_id; |
1969 var change_pos = parseInt(request.arguments.change_pos); | 1969 |
1970 var change_len = parseInt(request.arguments.change_len); | |
1971 var new_string = request.arguments.new_string; | |
1972 if (!IS_STRING(new_string)) { | |
1973 response.failed('Argument "new_string" is not a string value'); | |
1974 return; | |
1975 } | |
1976 | |
1977 var scripts = %DebugGetLoadedScripts(); | 1970 var scripts = %DebugGetLoadedScripts(); |
1978 | 1971 |
1979 var the_script = null; | 1972 var the_script = null; |
1980 for (var i = 0; i < scripts.length; i++) { | 1973 for (var i = 0; i < scripts.length; i++) { |
1981 if (scripts[i].id == script_id) { | 1974 if (scripts[i].id == script_id) { |
1982 the_script = scripts[i]; | 1975 the_script = scripts[i]; |
1983 } | 1976 } |
1984 } | 1977 } |
1985 if (!the_script) { | 1978 if (!the_script) { |
1986 response.failed('Script not found'); | 1979 response.failed('Script not found'); |
1987 return; | 1980 return; |
1988 } | 1981 } |
1989 | 1982 |
| 1983 // A function that calls a proper signature of LiveEdit API. |
| 1984 var invocation; |
| 1985 |
1990 var change_log = new Array(); | 1986 var change_log = new Array(); |
| 1987 |
| 1988 if (IS_STRING(request.arguments.new_source)) { |
| 1989 var new_source = request.arguments.new_source; |
| 1990 invocation = function() { |
| 1991 return Debug.LiveEdit.SetScriptSource(the_script, new_source, change_log); |
| 1992 } |
| 1993 } else { |
| 1994 var change_pos = parseInt(request.arguments.change_pos); |
| 1995 var change_len = parseInt(request.arguments.change_len); |
| 1996 var new_string = request.arguments.new_string; |
| 1997 if (!IS_STRING(new_string)) { |
| 1998 response.failed('Argument "new_string" is not a string value'); |
| 1999 return; |
| 2000 } |
| 2001 invocation = function() { |
| 2002 return Debug.LiveEditChangeScript(the_script, change_pos, change_len, |
| 2003 new_string, change_log); |
| 2004 } |
| 2005 } |
| 2006 |
1991 try { | 2007 try { |
1992 Debug.LiveEditChangeScript(the_script, change_pos, change_len, new_string, | 2008 invocation(); |
1993 change_log); | |
1994 } catch (e) { | 2009 } catch (e) { |
1995 if (e instanceof Debug.LiveEditChangeScript.Failure) { | 2010 if (e instanceof Debug.LiveEditChangeScript.Failure) { |
1996 // Let's treat it as a "success" so that body with change_log will be | 2011 // Let's treat it as a "success" so that body with change_log will be |
1997 // sent back. "change_log" will have "failure" field set. | 2012 // sent back. "change_log" will have "failure" field set. |
1998 change_log.push( { failure: true } ); | 2013 change_log.push( { failure: true } ); |
1999 } else { | 2014 } else { |
2000 throw e; | 2015 throw e; |
2001 } | 2016 } |
2002 } | 2017 } |
2003 response.body = {change_log: change_log}; | 2018 response.body = {change_log: change_log}; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 case 'string': | 2138 case 'string': |
2124 case 'number': | 2139 case 'number': |
2125 json = value; | 2140 json = value; |
2126 break | 2141 break |
2127 | 2142 |
2128 default: | 2143 default: |
2129 json = null; | 2144 json = null; |
2130 } | 2145 } |
2131 return json; | 2146 return json; |
2132 } | 2147 } |
OLD | NEW |