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

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

Issue 547703002: Rework how types work in the VM Service. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review 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 20 matching lines...) Expand all
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'; 41 static bool _isInstanceType(String type) {
42 switch (type) {
43 case 'BoundedType':
44 case 'Instance':
45 case 'List':
46 case 'String':
47 case 'Type':
48 case 'TypeParameter':
49 case 'TypeRef':
50 case 'bool':
51 case 'double':
52 case 'int':
53 case 'null':
54 return true;
55 default:
56 return false;
57 }
58 }
59
60 static bool _isTypeType(String type) {
61 switch (type) {
62 case 'BoundedType':
63 case 'Type':
64 case 'TypeParameter':
65 case 'TypeRef':
66 return true;
67 default:
68 return false;
69 }
70 }
71
72 bool get isAbstractType => _isTypeType(type);
73 bool get isBool => type == 'bool';
74 bool get isContext => type == 'Context';
75 bool get isDouble => type == 'double';
76 bool get isError => type == 'Error';
77 bool get isInstance => _isInstanceType(type);
78 bool get isInt => type == 'int';
79 bool get isList => type == 'List';
80 bool get isNull => type == 'null';
81 bool get isSentinel => type == 'Sentinel';
82 bool get isString => type == 'String';
83
84 // Kinds of Instance.
85 bool get isMirrorReference => vmType == 'MirrorReference';
86 bool get isWeakProperty => vmType == 'WeakProperty';
42 bool get isClosure => false; 87 bool get isClosure => false;
43 bool get isContext => vmType == 'Context';
44 bool get isDouble => vmType == 'Double';
45 bool get isError => vmType == 'Error';
46 bool get isInstance => vmType == 'Instance';
47 bool get isInt => vmType == 'Smi' || vmType == 'Mint' || vmType == 'Bigint';
48 bool get isList => vmType == 'GrowableObjectArray' || vmType == 'Array';
49 bool get isMirrorReference => vmType == 'MirrorReference';
50 bool get isNull => vmType == 'Null';
51 bool get isSentinel => vmType == 'Sentinel';
52 bool get isString => vmType == 'String';
53 bool get isType => vmType == 'Type';
54 bool get isWeakProperty => vmType == 'WeakProperty';
55 88
56 /// The complete service url of this object. 89 /// The complete service url of this object.
57 @reflectable String get link => _owner.relativeLink(_id); 90 @reflectable String get link => _owner.relativeLink(_id);
58 91
59 /// Has this object been fully loaded? 92 /// Has this object been fully loaded?
60 bool get loaded => _loaded; 93 bool get loaded => _loaded;
61 bool _loaded = false; 94 bool _loaded = false;
62 // TODO(turnidge): Make loaded observable and get rid of loading 95 // TODO(turnidge): Make loaded observable and get rid of loading
63 // from Isolate. 96 // from Isolate.
64 97
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 break; 136 break;
104 case 'Error': 137 case 'Error':
105 obj = new DartError._empty(owner); 138 obj = new DartError._empty(owner);
106 break; 139 break;
107 case 'Function': 140 case 'Function':
108 obj = new ServiceFunction._empty(owner); 141 obj = new ServiceFunction._empty(owner);
109 break; 142 break;
110 case 'Gauge': 143 case 'Gauge':
111 obj = new ServiceMetric._empty(owner); 144 obj = new ServiceMetric._empty(owner);
112 break; 145 break;
113 case 'Array':
114 case 'Bigint':
115 case 'Bool':
116 case 'Double':
117 case 'GrowableObjectArray':
118 case 'Instance':
119 case 'Mint':
120 case 'MirrorReference':
121 case 'Null':
122 case 'Sentinel': // TODO(rmacnak): Separate this out.
123 case 'Smi':
124 case 'String':
125 case 'Type':
126 case 'WeakProperty':
127 obj = new Instance._empty(owner);
128 break;
129 case 'Isolate': 146 case 'Isolate':
130 obj = new Isolate._empty(owner.vm); 147 obj = new Isolate._empty(owner.vm);
131 break; 148 break;
132 case 'Library': 149 case 'Library':
133 obj = new Library._empty(owner); 150 obj = new Library._empty(owner);
134 break; 151 break;
135 case 'ServiceError': 152 case 'ServiceError':
136 obj = new ServiceError._empty(owner); 153 obj = new ServiceError._empty(owner);
137 break; 154 break;
138 case 'ServiceEvent': 155 case 'ServiceEvent':
139 obj = new ServiceEvent._empty(owner); 156 obj = new ServiceEvent._empty(owner);
140 break; 157 break;
141 case 'ServiceException': 158 case 'ServiceException':
142 obj = new ServiceException._empty(owner); 159 obj = new ServiceException._empty(owner);
143 break; 160 break;
144 case 'Script': 161 case 'Script':
145 obj = new Script._empty(owner); 162 obj = new Script._empty(owner);
146 break; 163 break;
147 case 'Socket': 164 case 'Socket':
148 obj = new Socket._empty(owner); 165 obj = new Socket._empty(owner);
149 break; 166 break;
150 default: 167 default:
151 obj = new ServiceMap._empty(owner); 168 if (_isInstanceType(type) ||
169 type == 'Sentinel') { // TODO(rmacnak): Separate this out.
170 obj = new Instance._empty(owner);
171 break;
172 } else {
173 obj = new ServiceMap._empty(owner);
174 break;
175 }
152 } 176 }
153 obj.update(map); 177 obj.update(map);
154 return obj; 178 return obj;
155 } 179 }
156 180
157 /// If [this] was created from a reference, load the full object 181 /// If [this] was created from a reference, load the full object
158 /// from the service by calling [reload]. Else, return [this]. 182 /// from the service by calling [reload]. Else, return [this].
159 Future<ServiceObject> load() { 183 Future<ServiceObject> load() {
160 if (loaded) { 184 if (loaded) {
161 return new Future.value(this); 185 return new Future.value(this);
(...skipping 16 matching lines...) Expand all
178 return new Future.value(this); 202 return new Future.value(this);
179 } 203 }
180 if (_inProgressReload == null) { 204 if (_inProgressReload == null) {
181 _inProgressReload = vm.getAsMap(link).then((ObservableMap map) { 205 _inProgressReload = vm.getAsMap(link).then((ObservableMap map) {
182 var mapType = _stripRef(map['type']); 206 var mapType = _stripRef(map['type']);
183 if (mapType != _type) { 207 if (mapType != _type) {
184 // If the type changes, return a new object instead of 208 // If the type changes, return a new object instead of
185 // updating the existing one. 209 // updating the existing one.
186 // 210 //
187 // TODO(turnidge): Check for vmType changing as well? 211 // TODO(turnidge): Check for vmType changing as well?
188 assert(mapType == 'Error' || mapType == 'Null'); 212 assert(mapType == 'Error' || mapType == 'null');
189 return new ServiceObject._fromMap(owner, map); 213 return new ServiceObject._fromMap(owner, map);
190 } 214 }
191 update(map); 215 update(map);
192 return this; 216 return this;
193 }).whenComplete(() { 217 }).whenComplete(() {
194 // This reload is complete. 218 // This reload is complete.
195 _inProgressReload = null; 219 _inProgressReload = null;
196 }); 220 });
197 } 221 }
198 return _inProgressReload; 222 return _inProgressReload;
(...skipping 13 matching lines...) Expand all
212 // It is only safe to change an id when the object isn't cacheable. 236 // It is only safe to change an id when the object isn't cacheable.
213 assert(!canCache); 237 assert(!canCache);
214 } 238 }
215 _id = map['id']; 239 _id = map['id'];
216 240
217 _type = mapType; 241 _type = mapType;
218 242
219 // When the response specifies a specific vmType, use it. 243 // When the response specifies a specific vmType, use it.
220 // Otherwise the vmType of the response is the same as the 'user' 244 // Otherwise the vmType of the response is the same as the 'user'
221 // type. 245 // type.
222 if (map.containsKey('vmType')) { 246 if (map.containsKey('_vmType')) {
223 _vmType = _stripRef(map['vmType']); 247 _vmType = _stripRef(map['_vmType']);
224 } else { 248 } else {
225 _vmType = _type; 249 _vmType = _type;
226 } 250 }
227 251
228 _update(map, mapIsRef); 252 _update(map, mapIsRef);
229 } 253 }
230 254
231 // Updates internal state from [map]. [map] can be a reference. 255 // Updates internal state from [map]. [map] can be a reference.
232 void _update(ObservableMap map, bool mapIsRef); 256 void _update(ObservableMap map, bool mapIsRef);
233 257
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 var v = list[i]; 2554 var v = list[i];
2531 if ((v is ObservableMap) && _isServiceMap(v)) { 2555 if ((v is ObservableMap) && _isServiceMap(v)) {
2532 list[i] = owner.getFromMap(v); 2556 list[i] = owner.getFromMap(v);
2533 } else if (v is ObservableList) { 2557 } else if (v is ObservableList) {
2534 _upgradeObservableList(v, owner); 2558 _upgradeObservableList(v, owner);
2535 } else if (v is ObservableMap) { 2559 } else if (v is ObservableMap) {
2536 _upgradeObservableMap(v, owner); 2560 _upgradeObservableMap(v, owner);
2537 } 2561 }
2538 } 2562 }
2539 } 2563 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698