| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of service; | 5 part of service; |
| 6 | 6 |
| 7 /// A [ServiceObject] is an object known to the VM service and is tied | 7 /// A [ServiceObject] is an object known to the VM service and is tied |
| 8 /// to an owning [Isolate]. | 8 /// to an owning [Isolate]. |
| 9 abstract class ServiceObject extends Observable { | 9 abstract class ServiceObject extends Observable { |
| 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a | 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 }); | 251 }); |
| 252 } | 252 } |
| 253 | 253 |
| 254 Future<ServiceObject> get(String id) { | 254 Future<ServiceObject> get(String id) { |
| 255 assert(id.startsWith('/') == false); | 255 assert(id.startsWith('/') == false); |
| 256 // Isolates are handled specially, since they can cache sub-objects. | 256 // Isolates are handled specially, since they can cache sub-objects. |
| 257 if (id.startsWith(_isolatesPrefix)) { | 257 if (id.startsWith(_isolatesPrefix)) { |
| 258 String isolateId = _parseIsolateId(id); | 258 String isolateId = _parseIsolateId(id); |
| 259 String objectId = _parseObjectId(id); | 259 String objectId = _parseObjectId(id); |
| 260 return _getIsolate(isolateId).then((isolate) { | 260 return _getIsolate(isolateId).then((isolate) { |
| 261 if (isolate == null) { | 261 if (isolate == null) { |
| 262 // The isolate does not exist. Return the VM object instead. | 262 // The isolate does not exist. Return the VM object instead. |
| 263 // | 263 // |
| 264 // TODO(turnidge): Generate a service error? | 264 // TODO(turnidge): Generate a service error? |
| 265 return this; | 265 return this; |
| 266 } | 266 } |
| 267 if (objectId == null) { | 267 if (objectId == null) { |
| 268 return isolate.reload(); | 268 return isolate.reload(); |
| 269 } else { | 269 } else { |
| 270 return isolate.get(objectId); | 270 return isolate.get(objectId); |
| 271 } | 271 } |
| 272 }); | 272 }); |
| 273 } | 273 } |
| 274 | 274 |
| 275 var obj = _cache[id]; | 275 var obj = _cache[id]; |
| 276 if (obj != null) { | 276 if (obj != null) { |
| 277 return obj.reload(); | 277 return obj.reload(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // Cache miss. Get the object from the vm directly. | 280 // Cache miss. Get the object from the vm directly. |
| 281 return getAsMap(id).then((ObservableMap map) { | 281 return getAsMap(id).then((ObservableMap map) { |
| 282 var obj = new ServiceObject._fromMap(this, map); | 282 var obj = new ServiceObject._fromMap(this, map); |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 void _addToChildren(Class cls) { | 1114 void _addToChildren(Class cls) { |
| 1115 if (children.contains(cls)) { | 1115 if (children.contains(cls)) { |
| 1116 return; | 1116 return; |
| 1117 } | 1117 } |
| 1118 children.add(cls); | 1118 children.add(cls); |
| 1119 } | 1119 } |
| 1120 } | 1120 } |
| 1121 | 1121 |
| 1122 class ScriptLine { | 1122 class ScriptLine extends Observable { |
| 1123 @reflectable final int line; | 1123 final int line; |
| 1124 @reflectable final String text; | 1124 final String text; |
| 1125 @observable int hits; |
| 1125 ScriptLine(this.line, this.text); | 1126 ScriptLine(this.line, this.text); |
| 1126 } | 1127 } |
| 1127 | 1128 |
| 1128 class Script extends ServiceObject { | 1129 class Script extends ServiceObject { |
| 1129 @reflectable final lines = new ObservableList<ScriptLine>(); | 1130 final lines = new ObservableList<ScriptLine>(); |
| 1130 @reflectable final hits = new ObservableMap<int, int>(); | 1131 final _hits = new Map<int, int>(); |
| 1131 @observable String kind; | 1132 @observable String kind; |
| 1132 @observable int firstTokenPos; | 1133 @observable int firstTokenPos; |
| 1133 @observable int lastTokenPos; | 1134 @observable int lastTokenPos; |
| 1134 bool get canCache => true; | 1135 bool get canCache => true; |
| 1135 bool get immutable => true; | 1136 bool get immutable => true; |
| 1136 | 1137 |
| 1137 String _shortUrl; | 1138 String _shortUrl; |
| 1138 String _url; | 1139 String _url; |
| 1139 | 1140 |
| 1140 Script._empty(ServiceObjectOwner owner) : super._empty(owner); | 1141 Script._empty(ServiceObjectOwner owner) : super._empty(owner); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 lastTokenPos : tokenOffset; | 1190 lastTokenPos : tokenOffset; |
| 1190 } | 1191 } |
| 1191 _tokenToLine[tokenOffset] = lineNumber; | 1192 _tokenToLine[tokenOffset] = lineNumber; |
| 1192 _tokenToCol[tokenOffset] = colNumber; | 1193 _tokenToCol[tokenOffset] = colNumber; |
| 1193 } | 1194 } |
| 1194 } | 1195 } |
| 1195 } | 1196 } |
| 1196 | 1197 |
| 1197 void _processHits(List scriptHits) { | 1198 void _processHits(List scriptHits) { |
| 1198 // Update hits table. | 1199 // Update hits table. |
| 1200 _hits.clear(); |
| 1199 for (var i = 0; i < scriptHits.length; i += 2) { | 1201 for (var i = 0; i < scriptHits.length; i += 2) { |
| 1200 var line = scriptHits[i]; | 1202 var line = scriptHits[i]; |
| 1201 var hit = scriptHits[i + 1]; // hit status. | 1203 var hit = scriptHits[i + 1]; // hit status. |
| 1202 assert(line >= 1); // Lines start at 1. | 1204 assert(line >= 1); // Lines start at 1. |
| 1203 hits[line] = hit; | 1205 _hits[line] = hit; |
| 1204 } | 1206 } |
| 1207 _applyHitsToLines(); |
| 1205 } | 1208 } |
| 1206 | 1209 |
| 1207 void _processSource(String source) { | 1210 void _processSource(String source) { |
| 1208 // Preemptyively mark that this is not loaded. | 1211 // Preemptyively mark that this is not loaded. |
| 1209 _loaded = false; | 1212 _loaded = false; |
| 1210 if (source == null) { | 1213 if (source == null) { |
| 1211 return; | 1214 return; |
| 1212 } | 1215 } |
| 1213 var sourceLines = source.split('\n'); | 1216 var sourceLines = source.split('\n'); |
| 1214 if (sourceLines.length == 0) { | 1217 if (sourceLines.length == 0) { |
| 1215 return; | 1218 return; |
| 1216 } | 1219 } |
| 1217 // We have the source to the script. This is now loaded. | 1220 // We have the source to the script. This is now loaded. |
| 1218 _loaded = true; | 1221 _loaded = true; |
| 1219 lines.clear(); | 1222 lines.clear(); |
| 1220 Logger.root.info('Adding ${sourceLines.length} source lines for ${_url}'); | 1223 Logger.root.info('Adding ${sourceLines.length} source lines for ${_url}'); |
| 1221 for (var i = 0; i < sourceLines.length; i++) { | 1224 for (var i = 0; i < sourceLines.length; i++) { |
| 1222 lines.add(new ScriptLine(i + 1, sourceLines[i])); | 1225 lines.add(new ScriptLine(i + 1, sourceLines[i])); |
| 1223 } | 1226 } |
| 1227 _applyHitsToLines(); |
| 1228 } |
| 1229 |
| 1230 void _applyHitsToLines() { |
| 1231 if (lines.length == 0) { |
| 1232 return; |
| 1233 } |
| 1234 for (var line in lines) { |
| 1235 var hits = _hits[line.line]; |
| 1236 line.hits = hits; |
| 1237 } |
| 1224 } | 1238 } |
| 1225 } | 1239 } |
| 1226 | 1240 |
| 1227 class CodeTick { | 1241 class CodeTick { |
| 1228 final int address; | 1242 final int address; |
| 1229 final int exclusiveTicks; | 1243 final int exclusiveTicks; |
| 1230 final int inclusiveTicks; | 1244 final int inclusiveTicks; |
| 1231 CodeTick(this.address, this.exclusiveTicks, this.inclusiveTicks); | 1245 CodeTick(this.address, this.exclusiveTicks, this.inclusiveTicks); |
| 1232 } | 1246 } |
| 1233 | 1247 |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 var v = list[i]; | 1814 var v = list[i]; |
| 1801 if ((v is ObservableMap) && _isServiceMap(v)) { | 1815 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 1802 list[i] = owner.getFromMap(v); | 1816 list[i] = owner.getFromMap(v); |
| 1803 } else if (v is ObservableList) { | 1817 } else if (v is ObservableList) { |
| 1804 _upgradeObservableList(v, owner); | 1818 _upgradeObservableList(v, owner); |
| 1805 } else if (v is ObservableMap) { | 1819 } else if (v is ObservableMap) { |
| 1806 _upgradeObservableMap(v, owner); | 1820 _upgradeObservableMap(v, owner); |
| 1807 } | 1821 } |
| 1808 } | 1822 } |
| 1809 } | 1823 } |
| OLD | NEW |