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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 if (this.resolved()) { | 842 if (this.resolved()) { |
843 var script = %FunctionGetScript(this.value_); | 843 var script = %FunctionGetScript(this.value_); |
844 if (script) { | 844 if (script) { |
845 return MakeMirror(script); | 845 return MakeMirror(script); |
846 } | 846 } |
847 } | 847 } |
848 }; | 848 }; |
849 | 849 |
850 | 850 |
851 /** | 851 /** |
| 852 * Returns the script source position for the function. Only makes sense |
| 853 * for functions which has a script defined. |
| 854 * @return {Number or undefined} in-script position for the function |
| 855 */ |
| 856 FunctionMirror.prototype.sourcePosition_ = function() { |
| 857 // Return script if function is resolved. Otherwise just fall through |
| 858 // to return undefined. |
| 859 if (this.resolved()) { |
| 860 return %FunctionGetScriptSourcePosition(this.value_); |
| 861 } |
| 862 }; |
| 863 |
| 864 |
| 865 /** |
| 866 * Returns the script source location object for the function. Only makes sense |
| 867 * for functions which has a script defined. |
| 868 * @return {Location or undefined} in-script location for the function begin |
| 869 */ |
| 870 FunctionMirror.prototype.sourceLocation = function() { |
| 871 if (this.resolved() && this.script()) { |
| 872 return this.script().locationFromPosition(this.sourcePosition_(), |
| 873 true); |
| 874 } |
| 875 }; |
| 876 |
| 877 |
| 878 /** |
852 * Returns objects constructed by this function. | 879 * Returns objects constructed by this function. |
853 * @param {number} opt_max_instances Optional parameter specifying the maximum | 880 * @param {number} opt_max_instances Optional parameter specifying the maximum |
854 * number of instances to return. | 881 * number of instances to return. |
855 * @return {Array or undefined} The objects constructed by this function. | 882 * @return {Array or undefined} The objects constructed by this function. |
856 */ | 883 */ |
857 FunctionMirror.prototype.constructedBy = function(opt_max_instances) { | 884 FunctionMirror.prototype.constructedBy = function(opt_max_instances) { |
858 if (this.resolved()) { | 885 if (this.resolved()) { |
859 // Find all objects constructed from this function. | 886 // Find all objects constructed from this function. |
860 var result = %DebugConstructedBy(this.value_, opt_max_instances || 0); | 887 var result = %DebugConstructedBy(this.value_, opt_max_instances || 0); |
861 | 888 |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2112 content.name = mirror.name(); | 2139 content.name = mirror.name(); |
2113 if (!IS_UNDEFINED(mirror.inferredName())) { | 2140 if (!IS_UNDEFINED(mirror.inferredName())) { |
2114 content.inferredName = mirror.inferredName(); | 2141 content.inferredName = mirror.inferredName(); |
2115 } | 2142 } |
2116 content.resolved = mirror.resolved(); | 2143 content.resolved = mirror.resolved(); |
2117 if (mirror.resolved()) { | 2144 if (mirror.resolved()) { |
2118 content.source = mirror.source(); | 2145 content.source = mirror.source(); |
2119 } | 2146 } |
2120 if (mirror.script()) { | 2147 if (mirror.script()) { |
2121 content.script = this.serializeReference(mirror.script()); | 2148 content.script = this.serializeReference(mirror.script()); |
| 2149 content.scriptId = mirror.script().id(); |
| 2150 |
| 2151 serializeLocationFields(mirror.sourceLocation(), content); |
2122 } | 2152 } |
2123 } | 2153 } |
2124 | 2154 |
2125 // Add date specific properties. | 2155 // Add date specific properties. |
2126 if (mirror.isDate()) { | 2156 if (mirror.isDate()) { |
2127 // Add date specific properties. | 2157 // Add date specific properties. |
2128 content.value = mirror.value(); | 2158 content.value = mirror.value(); |
2129 } | 2159 } |
2130 | 2160 |
2131 // Add actual properties - named properties followed by indexed properties. | 2161 // Add actual properties - named properties followed by indexed properties. |
(...skipping 12 matching lines...) Expand all Loading... |
2144 p[propertyNames.length + i] = this.serializeProperty_(propertyMirror); | 2174 p[propertyNames.length + i] = this.serializeProperty_(propertyMirror); |
2145 if (details) { | 2175 if (details) { |
2146 this.add_(propertyMirror.value()); | 2176 this.add_(propertyMirror.value()); |
2147 } | 2177 } |
2148 } | 2178 } |
2149 content.properties = p; | 2179 content.properties = p; |
2150 } | 2180 } |
2151 | 2181 |
2152 | 2182 |
2153 /** | 2183 /** |
| 2184 * Serialize location information to the following JSON format: |
| 2185 * |
| 2186 * "position":"<position>", |
| 2187 * "line":"<line>", |
| 2188 * "column":"<column>", |
| 2189 * |
| 2190 * @param {SourceLocation} location The location to serialize, may be undefined. |
| 2191 */ |
| 2192 function serializeLocationFields (location, content) { |
| 2193 if (!location) { |
| 2194 return; |
| 2195 } |
| 2196 content.position = location.position; |
| 2197 var line = location.line; |
| 2198 if (!IS_UNDEFINED(line)) { |
| 2199 content.line = line; |
| 2200 } |
| 2201 var column = location.column; |
| 2202 if (!IS_UNDEFINED(column)) { |
| 2203 content.column = column; |
| 2204 } |
| 2205 } |
| 2206 |
| 2207 |
| 2208 /** |
2154 * Serialize property information to the following JSON format for building the | 2209 * Serialize property information to the following JSON format for building the |
2155 * array of properties. | 2210 * array of properties. |
2156 * | 2211 * |
2157 * {"name":"<property name>", | 2212 * {"name":"<property name>", |
2158 * "attributes":<number>, | 2213 * "attributes":<number>, |
2159 * "propertyType":<number>, | 2214 * "propertyType":<number>, |
2160 * "ref":<number>} | 2215 * "ref":<number>} |
2161 * | 2216 * |
2162 * If the attribute for the property is PropertyAttribute.None it is not added. | 2217 * If the attribute for the property is PropertyAttribute.None it is not added. |
2163 * If the propertyType for the property is PropertyType.Normal it is not added. | 2218 * If the propertyType for the property is PropertyType.Normal it is not added. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2211 } | 2266 } |
2212 content.arguments = x; | 2267 content.arguments = x; |
2213 var x = new Array(mirror.localCount()); | 2268 var x = new Array(mirror.localCount()); |
2214 for (var i = 0; i < mirror.localCount(); i++) { | 2269 for (var i = 0; i < mirror.localCount(); i++) { |
2215 var local = {}; | 2270 var local = {}; |
2216 local.name = mirror.localName(i); | 2271 local.name = mirror.localName(i); |
2217 local.value = this.serializeReference(mirror.localValue(i)); | 2272 local.value = this.serializeReference(mirror.localValue(i)); |
2218 x[i] = local; | 2273 x[i] = local; |
2219 } | 2274 } |
2220 content.locals = x; | 2275 content.locals = x; |
2221 content.position = mirror.sourcePosition(); | 2276 serializeLocationFields(mirror.sourceLocation(), content); |
2222 var line = mirror.sourceLine(); | |
2223 if (!IS_UNDEFINED(line)) { | |
2224 content.line = line; | |
2225 } | |
2226 var column = mirror.sourceColumn(); | |
2227 if (!IS_UNDEFINED(column)) { | |
2228 content.column = column; | |
2229 } | |
2230 var source_line_text = mirror.sourceLineText(); | 2277 var source_line_text = mirror.sourceLineText(); |
2231 if (!IS_UNDEFINED(source_line_text)) { | 2278 if (!IS_UNDEFINED(source_line_text)) { |
2232 content.sourceLineText = source_line_text; | 2279 content.sourceLineText = source_line_text; |
2233 } | 2280 } |
2234 | 2281 |
2235 content.scopes = []; | 2282 content.scopes = []; |
2236 for (var i = 0; i < mirror.scopeCount(); i++) { | 2283 for (var i = 0; i < mirror.scopeCount(); i++) { |
2237 var scope = mirror.scope(i); | 2284 var scope = mirror.scope(i); |
2238 content.scopes.push({ | 2285 content.scopes.push({ |
2239 type: scope.scopeType(), | 2286 type: scope.scopeType(), |
(...skipping 28 matching lines...) Expand all Loading... |
2268 } | 2315 } |
2269 if (!isFinite(value)) { | 2316 if (!isFinite(value)) { |
2270 if (value > 0) { | 2317 if (value > 0) { |
2271 return 'Infinity'; | 2318 return 'Infinity'; |
2272 } else { | 2319 } else { |
2273 return '-Infinity'; | 2320 return '-Infinity'; |
2274 } | 2321 } |
2275 } | 2322 } |
2276 return value; | 2323 return value; |
2277 } | 2324 } |
OLD | NEW |