OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function (global, utils) { | 5 (function (global, utils) { |
6 "use strict"; | 6 "use strict"; |
7 | 7 |
8 // ---------------------------------------------------------------------------- | 8 // ---------------------------------------------------------------------------- |
9 // Imports | 9 // Imports |
10 | 10 |
11 var FrameMirror = global.FrameMirror; | 11 var FrameMirror = global.FrameMirror; |
12 var GlobalArray = global.Array; | 12 var GlobalArray = global.Array; |
13 var GlobalRegExp = global.RegExp; | 13 var GlobalRegExp = global.RegExp; |
14 var IsNaN = global.isNaN; | 14 var IsNaN = global.isNaN; |
15 var JSONParse = global.JSON.parse; | 15 var JSONParse = global.JSON.parse; |
16 var JSONStringify = global.JSON.stringify; | 16 var JSONStringify = global.JSON.stringify; |
17 var LookupMirror = global.LookupMirror; | 17 var LookupMirror = global.LookupMirror; |
18 var MakeMirror = global.MakeMirror; | 18 var MakeMirror = global.MakeMirror; |
19 var MakeMirrorSerializer = global.MakeMirrorSerializer; | 19 var MakeMirrorSerializer = global.MakeMirrorSerializer; |
20 var MathMin = global.Math.min; | 20 var MathMin = global.Math.min; |
21 var Mirror = global.Mirror; | 21 var Mirror = global.Mirror; |
22 var MirrorType; | 22 var MirrorType; |
23 var ParseInt = global.parseInt; | 23 var ParseInt = global.parseInt; |
24 var ToBoolean; | |
25 var ValueMirror = global.ValueMirror; | 24 var ValueMirror = global.ValueMirror; |
26 | 25 |
27 utils.Import(function(from) { | 26 utils.Import(function(from) { |
28 MirrorType = from.MirrorType; | 27 MirrorType = from.MirrorType; |
29 ToBoolean = from.ToBoolean; | |
30 }); | 28 }); |
31 | 29 |
32 //---------------------------------------------------------------------------- | 30 //---------------------------------------------------------------------------- |
33 | 31 |
34 // Default number of frames to include in the response to backtrace request. | 32 // Default number of frames to include in the response to backtrace request. |
35 var kDefaultBacktraceLength = 10; | 33 var kDefaultBacktraceLength = 10; |
36 | 34 |
37 var Debug = {}; | 35 var Debug = {}; |
38 | 36 |
39 // Regular expression to skip "crud" at the beginning of a source line which is | 37 // Regular expression to skip "crud" at the beginning of a source line which is |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 BreakPoint.prototype.isTriggered = function(exec_state) { | 221 BreakPoint.prototype.isTriggered = function(exec_state) { |
224 // Break point not active - not triggered. | 222 // Break point not active - not triggered. |
225 if (!this.active()) return false; | 223 if (!this.active()) return false; |
226 | 224 |
227 // Check for conditional break point. | 225 // Check for conditional break point. |
228 if (this.condition()) { | 226 if (this.condition()) { |
229 // If break point has condition try to evaluate it in the top frame. | 227 // If break point has condition try to evaluate it in the top frame. |
230 try { | 228 try { |
231 var mirror = exec_state.frame(0).evaluate(this.condition()); | 229 var mirror = exec_state.frame(0).evaluate(this.condition()); |
232 // If no sensible mirror or non true value break point not triggered. | 230 // If no sensible mirror or non true value break point not triggered. |
233 if (!(mirror instanceof ValueMirror) || !ToBoolean(mirror.value_)) { | 231 if (!(mirror instanceof ValueMirror) || !mirror.value_) { |
234 return false; | 232 return false; |
235 } | 233 } |
236 } catch (e) { | 234 } catch (e) { |
237 // Exception evaluating condition counts as not triggered. | 235 // Exception evaluating condition counts as not triggered. |
238 return false; | 236 return false; |
239 } | 237 } |
240 } | 238 } |
241 | 239 |
242 // Update the hit count. | 240 // Update the hit count. |
243 this.hit_count_++; | 241 this.hit_count_++; |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 if (!IS_UNDEFINED(opt_callframe)) { | 950 if (!IS_UNDEFINED(opt_callframe)) { |
953 callFrameId = opt_callframe.details_.frameId(); | 951 callFrameId = opt_callframe.details_.frameId(); |
954 } | 952 } |
955 | 953 |
956 return %PrepareStep(this.break_id, action, count, callFrameId); | 954 return %PrepareStep(this.break_id, action, count, callFrameId); |
957 }; | 955 }; |
958 | 956 |
959 ExecutionState.prototype.evaluateGlobal = function(source, disable_break, | 957 ExecutionState.prototype.evaluateGlobal = function(source, disable_break, |
960 opt_additional_context) { | 958 opt_additional_context) { |
961 return MakeMirror(%DebugEvaluateGlobal(this.break_id, source, | 959 return MakeMirror(%DebugEvaluateGlobal(this.break_id, source, |
962 ToBoolean(disable_break), | 960 TO_BOOLEAN(disable_break), |
963 opt_additional_context)); | 961 opt_additional_context)); |
964 }; | 962 }; |
965 | 963 |
966 ExecutionState.prototype.frameCount = function() { | 964 ExecutionState.prototype.frameCount = function() { |
967 return %GetFrameCount(this.break_id); | 965 return %GetFrameCount(this.break_id); |
968 }; | 966 }; |
969 | 967 |
970 ExecutionState.prototype.threadCount = function() { | 968 ExecutionState.prototype.threadCount = function() { |
971 return %GetThreadCount(this.break_id); | 969 return %GetThreadCount(this.break_id); |
972 }; | 970 }; |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1981 DebugCommandProcessor.resolveValue_ = function(value_description) { | 1979 DebugCommandProcessor.resolveValue_ = function(value_description) { |
1982 if ("handle" in value_description) { | 1980 if ("handle" in value_description) { |
1983 var value_mirror = LookupMirror(value_description.handle); | 1981 var value_mirror = LookupMirror(value_description.handle); |
1984 if (!value_mirror) { | 1982 if (!value_mirror) { |
1985 throw MakeError(kDebugger, "Failed to resolve value by handle, ' #" + | 1983 throw MakeError(kDebugger, "Failed to resolve value by handle, ' #" + |
1986 value_description.handle + "# not found"); | 1984 value_description.handle + "# not found"); |
1987 } | 1985 } |
1988 return value_mirror.value(); | 1986 return value_mirror.value(); |
1989 } else if ("stringDescription" in value_description) { | 1987 } else if ("stringDescription" in value_description) { |
1990 if (value_description.type == MirrorType.BOOLEAN_TYPE) { | 1988 if (value_description.type == MirrorType.BOOLEAN_TYPE) { |
1991 return ToBoolean(value_description.stringDescription); | 1989 return TO_BOOLEAN(value_description.stringDescription); |
1992 } else if (value_description.type == MirrorType.NUMBER_TYPE) { | 1990 } else if (value_description.type == MirrorType.NUMBER_TYPE) { |
1993 return TO_NUMBER(value_description.stringDescription); | 1991 return TO_NUMBER(value_description.stringDescription); |
1994 } if (value_description.type == MirrorType.STRING_TYPE) { | 1992 } if (value_description.type == MirrorType.STRING_TYPE) { |
1995 return TO_STRING(value_description.stringDescription); | 1993 return TO_STRING(value_description.stringDescription); |
1996 } else { | 1994 } else { |
1997 throw MakeError(kDebugger, "Unknown type"); | 1995 throw MakeError(kDebugger, "Unknown type"); |
1998 } | 1996 } |
1999 } else if ("value" in value_description) { | 1997 } else if ("value" in value_description) { |
2000 return value_description.value; | 1998 return value_description.value; |
2001 } else if (value_description.type == MirrorType.UNDEFINED_TYPE) { | 1999 } else if (value_description.type == MirrorType.UNDEFINED_TYPE) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2083 | 2081 |
2084 var raw_value = DebugCommandProcessor.resolveValue_(mapping); | 2082 var raw_value = DebugCommandProcessor.resolveValue_(mapping); |
2085 additional_context_object[mapping.name] = raw_value; | 2083 additional_context_object[mapping.name] = raw_value; |
2086 } | 2084 } |
2087 } | 2085 } |
2088 | 2086 |
2089 // Global evaluate. | 2087 // Global evaluate. |
2090 if (global) { | 2088 if (global) { |
2091 // Evaluate in the native context. | 2089 // Evaluate in the native context. |
2092 response.body = this.exec_state_.evaluateGlobal( | 2090 response.body = this.exec_state_.evaluateGlobal( |
2093 expression, ToBoolean(disable_break), additional_context_object); | 2091 expression, TO_BOOLEAN(disable_break), additional_context_object); |
2094 return; | 2092 return; |
2095 } | 2093 } |
2096 | 2094 |
2097 // Default value for disable_break is true. | 2095 // Default value for disable_break is true. |
2098 if (IS_UNDEFINED(disable_break)) { | 2096 if (IS_UNDEFINED(disable_break)) { |
2099 disable_break = true; | 2097 disable_break = true; |
2100 } | 2098 } |
2101 | 2099 |
2102 // No frames no evaluate in frame. | 2100 // No frames no evaluate in frame. |
2103 if (this.exec_state_.frameCount() == 0) { | 2101 if (this.exec_state_.frameCount() == 0) { |
2104 return response.failed('No frames'); | 2102 return response.failed('No frames'); |
2105 } | 2103 } |
2106 | 2104 |
2107 // Check whether a frame was specified. | 2105 // Check whether a frame was specified. |
2108 if (!IS_UNDEFINED(frame)) { | 2106 if (!IS_UNDEFINED(frame)) { |
2109 var frame_number = TO_NUMBER(frame); | 2107 var frame_number = TO_NUMBER(frame); |
2110 if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) { | 2108 if (frame_number < 0 || frame_number >= this.exec_state_.frameCount()) { |
2111 return response.failed('Invalid frame "' + frame + '"'); | 2109 return response.failed('Invalid frame "' + frame + '"'); |
2112 } | 2110 } |
2113 // Evaluate in the specified frame. | 2111 // Evaluate in the specified frame. |
2114 response.body = this.exec_state_.frame(frame_number).evaluate( | 2112 response.body = this.exec_state_.frame(frame_number).evaluate( |
2115 expression, ToBoolean(disable_break), additional_context_object); | 2113 expression, TO_BOOLEAN(disable_break), additional_context_object); |
2116 return; | 2114 return; |
2117 } else { | 2115 } else { |
2118 // Evaluate in the selected frame. | 2116 // Evaluate in the selected frame. |
2119 response.body = this.exec_state_.frame().evaluate( | 2117 response.body = this.exec_state_.frame().evaluate( |
2120 expression, ToBoolean(disable_break), additional_context_object); | 2118 expression, TO_BOOLEAN(disable_break), additional_context_object); |
2121 return; | 2119 return; |
2122 } | 2120 } |
2123 }; | 2121 }; |
2124 | 2122 |
2125 | 2123 |
2126 DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) { | 2124 DebugCommandProcessor.prototype.lookupRequest_ = function(request, response) { |
2127 if (!request.arguments) { | 2125 if (!request.arguments) { |
2128 return response.failed('Missing arguments'); | 2126 return response.failed('Missing arguments'); |
2129 } | 2127 } |
2130 | 2128 |
2131 // Pull out arguments. | 2129 // Pull out arguments. |
2132 var handles = request.arguments.handles; | 2130 var handles = request.arguments.handles; |
2133 | 2131 |
2134 // Check for legal arguments. | 2132 // Check for legal arguments. |
2135 if (IS_UNDEFINED(handles)) { | 2133 if (IS_UNDEFINED(handles)) { |
2136 return response.failed('Argument "handles" missing'); | 2134 return response.failed('Argument "handles" missing'); |
2137 } | 2135 } |
2138 | 2136 |
2139 // Set 'includeSource' option for script lookup. | 2137 // Set 'includeSource' option for script lookup. |
2140 if (!IS_UNDEFINED(request.arguments.includeSource)) { | 2138 if (!IS_UNDEFINED(request.arguments.includeSource)) { |
2141 var includeSource = ToBoolean(request.arguments.includeSource); | 2139 var includeSource = TO_BOOLEAN(request.arguments.includeSource); |
2142 response.setOption('includeSource', includeSource); | 2140 response.setOption('includeSource', includeSource); |
2143 } | 2141 } |
2144 | 2142 |
2145 // Lookup handles. | 2143 // Lookup handles. |
2146 var mirrors = {}; | 2144 var mirrors = {}; |
2147 for (var i = 0; i < handles.length; i++) { | 2145 for (var i = 0; i < handles.length; i++) { |
2148 var handle = handles[i]; | 2146 var handle = handles[i]; |
2149 var mirror = LookupMirror(handle); | 2147 var mirror = LookupMirror(handle); |
2150 if (!mirror) { | 2148 if (!mirror) { |
2151 return response.failed('Object #' + handle + '# not found'); | 2149 return response.failed('Object #' + handle + '# not found'); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2243 // Pull out arguments. | 2241 // Pull out arguments. |
2244 if (!IS_UNDEFINED(request.arguments.types)) { | 2242 if (!IS_UNDEFINED(request.arguments.types)) { |
2245 types = TO_NUMBER(request.arguments.types); | 2243 types = TO_NUMBER(request.arguments.types); |
2246 if (IsNaN(types) || types < 0) { | 2244 if (IsNaN(types) || types < 0) { |
2247 return response.failed('Invalid types "' + | 2245 return response.failed('Invalid types "' + |
2248 request.arguments.types + '"'); | 2246 request.arguments.types + '"'); |
2249 } | 2247 } |
2250 } | 2248 } |
2251 | 2249 |
2252 if (!IS_UNDEFINED(request.arguments.includeSource)) { | 2250 if (!IS_UNDEFINED(request.arguments.includeSource)) { |
2253 includeSource = ToBoolean(request.arguments.includeSource); | 2251 includeSource = TO_BOOLEAN(request.arguments.includeSource); |
2254 response.setOption('includeSource', includeSource); | 2252 response.setOption('includeSource', includeSource); |
2255 } | 2253 } |
2256 | 2254 |
2257 if (IS_ARRAY(request.arguments.ids)) { | 2255 if (IS_ARRAY(request.arguments.ids)) { |
2258 idsToInclude = {}; | 2256 idsToInclude = {}; |
2259 var ids = request.arguments.ids; | 2257 var ids = request.arguments.ids; |
2260 for (var i = 0; i < ids.length; i++) { | 2258 for (var i = 0; i < ids.length; i++) { |
2261 idsToInclude[ids[i]] = true; | 2259 idsToInclude[ids[i]] = true; |
2262 } | 2260 } |
2263 } | 2261 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 "IsBreakPointTriggered", IsBreakPointTriggered, | 2614 "IsBreakPointTriggered", IsBreakPointTriggered, |
2617 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, | 2615 "UpdateScriptBreakPoints", UpdateScriptBreakPoints, |
2618 ]); | 2616 ]); |
2619 | 2617 |
2620 // Export to liveedit.js | 2618 // Export to liveedit.js |
2621 utils.Export(function(to) { | 2619 utils.Export(function(to) { |
2622 to.GetScriptBreakPoints = GetScriptBreakPoints; | 2620 to.GetScriptBreakPoints = GetScriptBreakPoints; |
2623 }); | 2621 }); |
2624 | 2622 |
2625 }) | 2623 }) |
OLD | NEW |