| 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'; | 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'; | 88 bool get isPlainInstance { |
| 44 bool get isDouble => vmType == 'Double'; | 89 return (type == 'Instance' && |
| 45 bool get isError => vmType == 'Error'; | 90 !isMirrorReference && !isWeakProperty && !isClosure); |
| 46 bool get isInstance => vmType == 'Instance'; | 91 } |
| 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 | 92 |
| 56 /// The complete service url of this object. | 93 /// The complete service url of this object. |
| 57 @reflectable String get link => _owner.relativeLink(_id); | 94 @reflectable String get link => _owner.relativeLink(_id); |
| 58 | 95 |
| 59 /// Has this object been fully loaded? | 96 /// Has this object been fully loaded? |
| 60 bool get loaded => _loaded; | 97 bool get loaded => _loaded; |
| 61 bool _loaded = false; | 98 bool _loaded = false; |
| 62 // TODO(turnidge): Make loaded observable and get rid of loading | 99 // TODO(turnidge): Make loaded observable and get rid of loading |
| 63 // from Isolate. | 100 // from Isolate. |
| 64 | 101 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 break; | 140 break; |
| 104 case 'Error': | 141 case 'Error': |
| 105 obj = new DartError._empty(owner); | 142 obj = new DartError._empty(owner); |
| 106 break; | 143 break; |
| 107 case 'Function': | 144 case 'Function': |
| 108 obj = new ServiceFunction._empty(owner); | 145 obj = new ServiceFunction._empty(owner); |
| 109 break; | 146 break; |
| 110 case 'Gauge': | 147 case 'Gauge': |
| 111 obj = new ServiceMetric._empty(owner); | 148 obj = new ServiceMetric._empty(owner); |
| 112 break; | 149 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': | 150 case 'Isolate': |
| 130 obj = new Isolate._empty(owner.vm); | 151 obj = new Isolate._empty(owner.vm); |
| 131 break; | 152 break; |
| 132 case 'Library': | 153 case 'Library': |
| 133 obj = new Library._empty(owner); | 154 obj = new Library._empty(owner); |
| 134 break; | 155 break; |
| 135 case 'ServiceError': | 156 case 'ServiceError': |
| 136 obj = new ServiceError._empty(owner); | 157 obj = new ServiceError._empty(owner); |
| 137 break; | 158 break; |
| 138 case 'ServiceEvent': | 159 case 'ServiceEvent': |
| 139 obj = new ServiceEvent._empty(owner); | 160 obj = new ServiceEvent._empty(owner); |
| 140 break; | 161 break; |
| 141 case 'ServiceException': | 162 case 'ServiceException': |
| 142 obj = new ServiceException._empty(owner); | 163 obj = new ServiceException._empty(owner); |
| 143 break; | 164 break; |
| 144 case 'Script': | 165 case 'Script': |
| 145 obj = new Script._empty(owner); | 166 obj = new Script._empty(owner); |
| 146 break; | 167 break; |
| 147 case 'Socket': | 168 case 'Socket': |
| 148 obj = new Socket._empty(owner); | 169 obj = new Socket._empty(owner); |
| 149 break; | 170 break; |
| 150 default: | 171 default: |
| 151 obj = new ServiceMap._empty(owner); | 172 if (_isInstanceType(type) || |
| 173 type == 'Sentinel') { // TODO(rmacnak): Separate this out. |
| 174 obj = new Instance._empty(owner); |
| 175 break; |
| 176 } else { |
| 177 obj = new ServiceMap._empty(owner); |
| 178 break; |
| 179 } |
| 152 } | 180 } |
| 153 obj.update(map); | 181 obj.update(map); |
| 154 return obj; | 182 return obj; |
| 155 } | 183 } |
| 156 | 184 |
| 157 /// If [this] was created from a reference, load the full object | 185 /// If [this] was created from a reference, load the full object |
| 158 /// from the service by calling [reload]. Else, return [this]. | 186 /// from the service by calling [reload]. Else, return [this]. |
| 159 Future<ServiceObject> load() { | 187 Future<ServiceObject> load() { |
| 160 if (loaded) { | 188 if (loaded) { |
| 161 return new Future.value(this); | 189 return new Future.value(this); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 178 return new Future.value(this); | 206 return new Future.value(this); |
| 179 } | 207 } |
| 180 if (_inProgressReload == null) { | 208 if (_inProgressReload == null) { |
| 181 _inProgressReload = vm.getAsMap(link).then((ObservableMap map) { | 209 _inProgressReload = vm.getAsMap(link).then((ObservableMap map) { |
| 182 var mapType = _stripRef(map['type']); | 210 var mapType = _stripRef(map['type']); |
| 183 if (mapType != _type) { | 211 if (mapType != _type) { |
| 184 // If the type changes, return a new object instead of | 212 // If the type changes, return a new object instead of |
| 185 // updating the existing one. | 213 // updating the existing one. |
| 186 // | 214 // |
| 187 // TODO(turnidge): Check for vmType changing as well? | 215 // TODO(turnidge): Check for vmType changing as well? |
| 188 assert(mapType == 'Error' || mapType == 'Null'); | 216 assert(mapType == 'Error' || mapType == 'null'); |
| 189 return new ServiceObject._fromMap(owner, map); | 217 return new ServiceObject._fromMap(owner, map); |
| 190 } | 218 } |
| 191 update(map); | 219 update(map); |
| 192 return this; | 220 return this; |
| 193 }).whenComplete(() { | 221 }).whenComplete(() { |
| 194 // This reload is complete. | 222 // This reload is complete. |
| 195 _inProgressReload = null; | 223 _inProgressReload = null; |
| 196 }); | 224 }); |
| 197 } | 225 } |
| 198 return _inProgressReload; | 226 return _inProgressReload; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 212 // It is only safe to change an id when the object isn't cacheable. | 240 // It is only safe to change an id when the object isn't cacheable. |
| 213 assert(!canCache); | 241 assert(!canCache); |
| 214 } | 242 } |
| 215 _id = map['id']; | 243 _id = map['id']; |
| 216 | 244 |
| 217 _type = mapType; | 245 _type = mapType; |
| 218 | 246 |
| 219 // When the response specifies a specific vmType, use it. | 247 // When the response specifies a specific vmType, use it. |
| 220 // Otherwise the vmType of the response is the same as the 'user' | 248 // Otherwise the vmType of the response is the same as the 'user' |
| 221 // type. | 249 // type. |
| 222 if (map.containsKey('vmType')) { | 250 if (map.containsKey('_vmType')) { |
| 223 _vmType = _stripRef(map['vmType']); | 251 _vmType = _stripRef(map['_vmType']); |
| 224 } else { | 252 } else { |
| 225 _vmType = _type; | 253 _vmType = _type; |
| 226 } | 254 } |
| 227 | 255 |
| 228 _update(map, mapIsRef); | 256 _update(map, mapIsRef); |
| 229 } | 257 } |
| 230 | 258 |
| 231 // Updates internal state from [map]. [map] can be a reference. | 259 // Updates internal state from [map]. [map] can be a reference. |
| 232 void _update(ObservableMap map, bool mapIsRef); | 260 void _update(ObservableMap map, bool mapIsRef); |
| 233 | 261 |
| (...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 var v = list[i]; | 2558 var v = list[i]; |
| 2531 if ((v is ObservableMap) && _isServiceMap(v)) { | 2559 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 2532 list[i] = owner.getFromMap(v); | 2560 list[i] = owner.getFromMap(v); |
| 2533 } else if (v is ObservableList) { | 2561 } else if (v is ObservableList) { |
| 2534 _upgradeObservableList(v, owner); | 2562 _upgradeObservableList(v, owner); |
| 2535 } else if (v is ObservableMap) { | 2563 } else if (v is ObservableMap) { |
| 2536 _upgradeObservableMap(v, owner); | 2564 _upgradeObservableMap(v, owner); |
| 2537 } | 2565 } |
| 2538 } | 2566 } |
| 2539 } | 2567 } |
| OLD | NEW |