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