| 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 static int LexicalSortName(ServiceObject o1, ServiceObject o2) { | 10 static int LexicalSortName(ServiceObject o1, ServiceObject o2) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 String _id; | 31 String _id; |
| 32 | 32 |
| 33 /// The user-level type of this object. | 33 /// The user-level type of this object. |
| 34 @reflectable String get type => _type; | 34 @reflectable String get type => _type; |
| 35 String _type; | 35 String _type; |
| 36 | 36 |
| 37 /// The vm type of this object. | 37 /// The vm type of this object. |
| 38 @reflectable String get vmType => _vmType; | 38 @reflectable String get vmType => _vmType; |
| 39 String _vmType; | 39 String _vmType; |
| 40 | 40 |
| 41 bool get isBool => vmType == 'Bool'; |
| 42 bool get isDouble => vmType == 'Double'; |
| 43 bool get isError => vmType == 'Error'; |
| 44 bool get isInstance => vmType == 'Instance'; |
| 45 bool get isInt => vmType == 'Smi' || vmType == 'Mint' || vmType == 'Bigint'; |
| 46 bool get isList => vmType == 'GrowableObjectArray' || vmType == 'Array'; |
| 47 bool get isNull => vmType == 'Null'; |
| 48 bool get isSentinel => vmType == 'Sentinel'; |
| 49 bool get isString => vmType == 'String'; |
| 50 bool get isType => vmType == 'Type'; |
| 51 |
| 41 /// The complete service url of this object. | 52 /// The complete service url of this object. |
| 42 @reflectable String get link => _owner.relativeLink(_id); | 53 @reflectable String get link => _owner.relativeLink(_id); |
| 43 | 54 |
| 44 /// Has this object been fully loaded? | 55 /// Has this object been fully loaded? |
| 45 bool get loaded => _loaded; | 56 bool get loaded => _loaded; |
| 46 bool _loaded = false; | 57 bool _loaded = false; |
| 47 // TODO(turnidge): Make loaded observable and get rid of loading | 58 // TODO(turnidge): Make loaded observable and get rid of loading |
| 48 // from Isolate. | 59 // from Isolate. |
| 49 | 60 |
| 50 /// Is this object cacheable? That is, is it impossible for the [id] | 61 /// Is this object cacheable? That is, is it impossible for the [id] |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 break; | 96 break; |
| 86 case 'Error': | 97 case 'Error': |
| 87 obj = new DartError._empty(owner); | 98 obj = new DartError._empty(owner); |
| 88 break; | 99 break; |
| 89 case 'Function': | 100 case 'Function': |
| 90 obj = new ServiceFunction._empty(owner); | 101 obj = new ServiceFunction._empty(owner); |
| 91 break; | 102 break; |
| 92 case 'Gauge': | 103 case 'Gauge': |
| 93 obj = new ServiceMetric._empty(owner); | 104 obj = new ServiceMetric._empty(owner); |
| 94 break; | 105 break; |
| 106 case 'Array': |
| 107 case 'Bigint': |
| 108 case 'Bool': |
| 109 case 'Double': |
| 110 case 'GrowableObjectArray': |
| 111 case 'Instance': |
| 112 case 'Mint': |
| 113 case 'Null': |
| 114 case 'Sentinel': // TODO(rmacnak): Separate this out. |
| 115 case 'Smi': |
| 116 case 'String': |
| 117 case 'Type': |
| 118 obj = new Instance._empty(owner); |
| 119 break; |
| 95 case 'Isolate': | 120 case 'Isolate': |
| 96 obj = new Isolate._empty(owner.vm); | 121 obj = new Isolate._empty(owner.vm); |
| 97 break; | 122 break; |
| 98 case 'Library': | 123 case 'Library': |
| 99 obj = new Library._empty(owner); | 124 obj = new Library._empty(owner); |
| 100 break; | 125 break; |
| 101 case 'ServiceError': | 126 case 'ServiceError': |
| 102 obj = new ServiceError._empty(owner); | 127 obj = new ServiceError._empty(owner); |
| 103 break; | 128 break; |
| 104 case 'ServiceEvent': | 129 case 'ServiceEvent': |
| (...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 | 1181 |
| 1157 String toString() => "ServiceMap($_map)"; | 1182 String toString() => "ServiceMap($_map)"; |
| 1158 } | 1183 } |
| 1159 | 1184 |
| 1160 /// A [DartError] is peered to a Dart Error object. | 1185 /// A [DartError] is peered to a Dart Error object. |
| 1161 class DartError extends ServiceObject { | 1186 class DartError extends ServiceObject { |
| 1162 DartError._empty(ServiceObject owner) : super._empty(owner); | 1187 DartError._empty(ServiceObject owner) : super._empty(owner); |
| 1163 | 1188 |
| 1164 @observable String kind; | 1189 @observable String kind; |
| 1165 @observable String message; | 1190 @observable String message; |
| 1166 @observable ServiceMap exception; | 1191 @observable Instance exception; |
| 1167 @observable ServiceMap stacktrace; | 1192 @observable ServiceMap stacktrace; |
| 1168 | 1193 |
| 1169 void _update(ObservableMap map, bool mapIsRef) { | 1194 void _update(ObservableMap map, bool mapIsRef) { |
| 1170 kind = map['kind']; | 1195 kind = map['kind']; |
| 1171 message = map['message']; | 1196 message = map['message']; |
| 1172 exception = new ServiceObject._fromMap(owner, map['exception']); | 1197 exception = new ServiceObject._fromMap(owner, map['exception']); |
| 1173 stacktrace = new ServiceObject._fromMap(owner, map['stacktrace']); | 1198 stacktrace = new ServiceObject._fromMap(owner, map['stacktrace']); |
| 1174 name = 'DartError $kind'; | 1199 name = 'DartError $kind'; |
| 1175 vmName = name; | 1200 vmName = name; |
| 1176 } | 1201 } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 subclasses.sort(ServiceObject.LexicalSortName); | 1461 subclasses.sort(ServiceObject.LexicalSortName); |
| 1437 } | 1462 } |
| 1438 | 1463 |
| 1439 Future<ServiceObject> get(String command) { | 1464 Future<ServiceObject> get(String command) { |
| 1440 return isolate.get(id + "/$command"); | 1465 return isolate.get(id + "/$command"); |
| 1441 } | 1466 } |
| 1442 | 1467 |
| 1443 String toString() => 'Class($vmName)'; | 1468 String toString() => 'Class($vmName)'; |
| 1444 } | 1469 } |
| 1445 | 1470 |
| 1471 class Instance extends ServiceObject { |
| 1472 @observable Class clazz; |
| 1473 @observable String valueAsString; |
| 1474 @observable int size; |
| 1475 @observable ServiceFunction closureFunc; // If a closure. |
| 1476 @observable String name; // If a Type. |
| 1477 |
| 1478 @observable var typeClass; |
| 1479 @observable var length; |
| 1480 @observable var fields; |
| 1481 @observable var nativeFields; |
| 1482 @observable var elements; |
| 1483 @observable var userName; |
| 1484 |
| 1485 bool get isClosure => closureFunc != null; |
| 1486 |
| 1487 Instance._empty(ServiceObjectOwner owner) : super._empty(owner); |
| 1488 |
| 1489 void _update(ObservableMap map, bool mapIsRef) { |
| 1490 // Extract full properties. |
| 1491 _upgradeCollection(map, isolate); |
| 1492 |
| 1493 clazz = map['class']; |
| 1494 valueAsString = map['valueAsString']; |
| 1495 size = map['size']; |
| 1496 closureFunc = map['closureFunc']; |
| 1497 name = map['name']; |
| 1498 |
| 1499 if (mapIsRef) { |
| 1500 return; |
| 1501 } |
| 1502 |
| 1503 nativeFields = map['nativeFields']; |
| 1504 fields = map['fields']; |
| 1505 length = map['length']; |
| 1506 elements = map['elements']; |
| 1507 typeClass = map['type_class']; |
| 1508 userName = map['user_name']; |
| 1509 |
| 1510 // We are fully loaded. |
| 1511 _loaded = true; |
| 1512 } |
| 1513 |
| 1514 String get shortName => valueAsString != null ? valueAsString : 'a ${clazz.nam
e}'; |
| 1515 |
| 1516 String toString() => 'Instance($shortName)'; |
| 1517 } |
| 1518 |
| 1446 // TODO(koda): Sync this with VM. | 1519 // TODO(koda): Sync this with VM. |
| 1447 class FunctionKind { | 1520 class FunctionKind { |
| 1448 final String _strValue; | 1521 final String _strValue; |
| 1449 FunctionKind._internal(this._strValue); | 1522 FunctionKind._internal(this._strValue); |
| 1450 toString() => _strValue; | 1523 toString() => _strValue; |
| 1451 bool isFake() => [kCollected, kNative, kTag, kReused].contains(this); | 1524 bool isFake() => [kCollected, kNative, kTag, kReused].contains(this); |
| 1452 | 1525 |
| 1453 static FunctionKind fromJSON(String value) { | 1526 static FunctionKind fromJSON(String value) { |
| 1454 switch(value) { | 1527 switch(value) { |
| 1455 case 'kRegularFunction': return kRegularFunction; | 1528 case 'kRegularFunction': return kRegularFunction; |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2353 for (var metric in metrics) { | 2426 for (var metric in metrics) { |
| 2354 metric.reload().then((m) { | 2427 metric.reload().then((m) { |
| 2355 m.addSample(new MetricSample(m.value)); | 2428 m.addSample(new MetricSample(m.value)); |
| 2356 }); | 2429 }); |
| 2357 } | 2430 } |
| 2358 } | 2431 } |
| 2359 } | 2432 } |
| 2360 | 2433 |
| 2361 // Convert any ServiceMaps representing a null instance into an actual null. | 2434 // Convert any ServiceMaps representing a null instance into an actual null. |
| 2362 _convertNull(obj) { | 2435 _convertNull(obj) { |
| 2363 if (obj is ServiceMap && | 2436 if (obj.isNull) { |
| 2364 obj.type == 'Null') { | |
| 2365 return null; | 2437 return null; |
| 2366 } | 2438 } |
| 2367 return obj; | 2439 return obj; |
| 2368 } | 2440 } |
| 2369 | 2441 |
| 2370 // Returns true if [map] is a service map. i.e. it has the following keys: | 2442 // Returns true if [map] is a service map. i.e. it has the following keys: |
| 2371 // 'id' and a 'type'. | 2443 // 'id' and a 'type'. |
| 2372 bool _isServiceMap(ObservableMap m) { | 2444 bool _isServiceMap(ObservableMap m) { |
| 2373 return (m != null) && (m['id'] != null) && (m['type'] != null); | 2445 return (m != null) && (m['id'] != null) && (m['type'] != null); |
| 2374 } | 2446 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 var v = list[i]; | 2479 var v = list[i]; |
| 2408 if ((v is ObservableMap) && _isServiceMap(v)) { | 2480 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 2409 list[i] = owner.getFromMap(v); | 2481 list[i] = owner.getFromMap(v); |
| 2410 } else if (v is ObservableList) { | 2482 } else if (v is ObservableList) { |
| 2411 _upgradeObservableList(v, owner); | 2483 _upgradeObservableList(v, owner); |
| 2412 } else if (v is ObservableMap) { | 2484 } else if (v is ObservableMap) { |
| 2413 _upgradeObservableMap(v, owner); | 2485 _upgradeObservableMap(v, owner); |
| 2414 } | 2486 } |
| 2415 } | 2487 } |
| 2416 } | 2488 } |
| OLD | NEW |