Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: runtime/bin/vmservice/observatory/lib/src/service/object.dart

Issue 509563004: Give instances their own model class; move DartErrors out of instance-ref into their own error-ref. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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' && id == 'objects/null';
44 bool get isPsuedoNull => serviceType == 'Null' && id != 'objects/null';
45 bool get isString => serviceType == 'String';
46 bool get isType => serviceType == 'Type';
Cutch 2014/08/28 14:46:05 Should these be on Instance and not ServiceObject?
rmacnak 2014/08/28 19:41:05 I think it makes sense to ask these questions of a
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 28 matching lines...) Expand all
75 break; 86 break;
76 case 'Code': 87 case 'Code':
77 obj = new Code._empty(owner); 88 obj = new Code._empty(owner);
78 break; 89 break;
79 case 'Error': 90 case 'Error':
80 obj = new DartError._empty(owner); 91 obj = new DartError._empty(owner);
81 break; 92 break;
82 case 'Function': 93 case 'Function':
83 obj = new ServiceFunction._empty(owner); 94 obj = new ServiceFunction._empty(owner);
84 break; 95 break;
96 case 'Array':
97 case 'Bigint':
98 case 'Bool':
99 case 'Double':
100 case 'GrowableObjectArray':
101 case 'Instance':
102 case 'Mint':
103 case 'Null':
104 case 'Smi':
105 case 'String':
106 case 'Type':
107 obj = new Instance._empty(owner);
108 break;
85 case 'Isolate': 109 case 'Isolate':
86 obj = new Isolate._empty(owner.vm); 110 obj = new Isolate._empty(owner.vm);
87 break; 111 break;
88 case 'Library': 112 case 'Library':
89 obj = new Library._empty(owner); 113 obj = new Library._empty(owner);
90 break; 114 break;
91 case 'ServiceError': 115 case 'ServiceError':
92 obj = new ServiceError._empty(owner); 116 obj = new ServiceError._empty(owner);
93 break; 117 break;
94 case 'ServiceEvent': 118 case 'ServiceEvent':
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1132
1109 String toString() => "ServiceMap($_map)"; 1133 String toString() => "ServiceMap($_map)";
1110 } 1134 }
1111 1135
1112 /// A [DartError] is peered to a Dart Error object. 1136 /// A [DartError] is peered to a Dart Error object.
1113 class DartError extends ServiceObject { 1137 class DartError extends ServiceObject {
1114 DartError._empty(ServiceObject owner) : super._empty(owner); 1138 DartError._empty(ServiceObject owner) : super._empty(owner);
1115 1139
1116 @observable String kind; 1140 @observable String kind;
1117 @observable String message; 1141 @observable String message;
1118 @observable ServiceMap exception; 1142 @observable Instance exception;
1119 @observable ServiceMap stacktrace; 1143 @observable ServiceMap stacktrace;
1120 1144
1121 void _update(ObservableMap map, bool mapIsRef) { 1145 void _update(ObservableMap map, bool mapIsRef) {
1122 kind = map['kind']; 1146 kind = map['kind'];
1123 message = map['message']; 1147 message = map['message'];
1124 exception = new ServiceObject._fromMap(owner, map['exception']); 1148 exception = new ServiceObject._fromMap(owner, map['exception']);
1125 stacktrace = new ServiceObject._fromMap(owner, map['stacktrace']); 1149 stacktrace = new ServiceObject._fromMap(owner, map['stacktrace']);
1126 name = 'DartError $kind'; 1150 name = 'DartError $kind';
1127 vmName = name; 1151 vmName = name;
1128 } 1152 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 subclasses.sort(ServiceObject.LexicalSortName); 1412 subclasses.sort(ServiceObject.LexicalSortName);
1389 } 1413 }
1390 1414
1391 Future<ServiceObject> get(String command) { 1415 Future<ServiceObject> get(String command) {
1392 return isolate.get(id + "/$command"); 1416 return isolate.get(id + "/$command");
1393 } 1417 }
1394 1418
1395 String toString() => 'Class($vmName)'; 1419 String toString() => 'Class($vmName)';
1396 } 1420 }
1397 1421
1422 class Instance extends ServiceObject {
1423 @observable Class clazz;
1424 @observable String valueAsString;
1425 @observable int size;
1426 @observable ServiceFunction closureFunc; // If a closure.
1427 @observable String name; // If a Type.
1428
1429 @observable var type_class;
Cutch 2014/08/28 14:46:05 typeClass
rmacnak 2014/08/28 19:41:05 Fixed
1430 @observable var length;
1431 @observable var fields;
1432 @observable var nativeFields;
1433 @observable var elements;
1434 @observable var user_name;
Cutch 2014/08/28 14:46:05 userName
rmacnak 2014/08/28 19:41:05 Fixed
1435
1436 bool get isClosure => closureFunc != null;
1437
1438 Instance._empty(ServiceObjectOwner owner) : super._empty(owner);
1439
1440 void _update(ObservableMap map, bool mapIsRef) {
1441 // Extract full properties.
1442 _upgradeCollection(map, isolate);
1443
1444 clazz = map['class'];
1445 valueAsString = map['valueAsString'];
1446 size = map['size'];
1447 closureFunc = map['closureFunc'];
1448 name = map['name'];
1449
1450 if (mapIsRef) {
1451 return;
1452 }
1453
1454 nativeFields = map['nativeFields'];
1455 fields = map['fields'];
1456 length = map['length'];
1457 elements = map['elements'];
1458 type_class = map['type_class'];
1459 user_name = map['user_name'];
1460
1461 // We are fully loaded.
1462 _loaded = true;
1463 }
1464
1465 String get shortName => valueAsString != null ? valueAsString : 'a ${clazz.nam e}';
1466
1467 String toString() => 'Instance($shortName)';
1468 }
1469
1398 // TODO(koda): Sync this with VM. 1470 // TODO(koda): Sync this with VM.
1399 class FunctionKind { 1471 class FunctionKind {
1400 final String _strValue; 1472 final String _strValue;
1401 FunctionKind._internal(this._strValue); 1473 FunctionKind._internal(this._strValue);
1402 toString() => _strValue; 1474 toString() => _strValue;
1403 bool isFake() => [kCollected, kNative, kTag, kReused].contains(this); 1475 bool isFake() => [kCollected, kNative, kTag, kReused].contains(this);
1404 1476
1405 static FunctionKind fromJSON(String value) { 1477 static FunctionKind fromJSON(String value) {
1406 switch(value) { 1478 switch(value) {
1407 case 'kRegularFunction': return kRegularFunction; 1479 case 'kRegularFunction': return kRegularFunction;
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
2214 remoteAddress = map['remoteAddress']; 2286 remoteAddress = map['remoteAddress'];
2215 remotePort = map['remotePort']; 2287 remotePort = map['remotePort'];
2216 2288
2217 fd = map['fd']; 2289 fd = map['fd'];
2218 socketOwner = map['owner']; 2290 socketOwner = map['owner'];
2219 } 2291 }
2220 } 2292 }
2221 2293
2222 // Convert any ServiceMaps representing a null instance into an actual null. 2294 // Convert any ServiceMaps representing a null instance into an actual null.
2223 _convertNull(obj) { 2295 _convertNull(obj) {
2224 if (obj is ServiceMap && 2296 if (obj.isNull) {
2225 obj.serviceType == 'Null') {
2226 return null; 2297 return null;
2227 } 2298 }
2228 return obj; 2299 return obj;
2229 } 2300 }
2230 2301
2231 // Returns true if [map] is a service map. i.e. it has the following keys: 2302 // Returns true if [map] is a service map. i.e. it has the following keys:
2232 // 'id' and a 'type'. 2303 // 'id' and a 'type'.
2233 bool _isServiceMap(ObservableMap m) { 2304 bool _isServiceMap(ObservableMap m) {
2234 return (m != null) && (m['id'] != null) && (m['type'] != null); 2305 return (m != null) && (m['id'] != null) && (m['type'] != null);
2235 } 2306 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 var v = list[i]; 2339 var v = list[i];
2269 if ((v is ObservableMap) && _isServiceMap(v)) { 2340 if ((v is ObservableMap) && _isServiceMap(v)) {
2270 list[i] = owner.getFromMap(v); 2341 list[i] = owner.getFromMap(v);
2271 } else if (v is ObservableList) { 2342 } else if (v is ObservableList) {
2272 _upgradeObservableList(v, owner); 2343 _upgradeObservableList(v, owner);
2273 } else if (v is ObservableMap) { 2344 } else if (v is ObservableMap) {
2274 _upgradeObservableMap(v, owner); 2345 _upgradeObservableMap(v, owner);
2275 } 2346 }
2276 } 2347 }
2277 } 2348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698