Chromium Code Reviews| 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 /// The owner of this [ServiceObject]. This can be an [Isolate], a | 10 /// The owner of this [ServiceObject]. This can be an [Isolate], a |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 // Cache miss. Get the object from the vm directly. | 277 // Cache miss. Get the object from the vm directly. |
| 278 return getAsMap(id).then((ObservableMap map) { | 278 return getAsMap(id).then((ObservableMap map) { |
| 279 var obj = new ServiceObject._fromMap(this, map); | 279 var obj = new ServiceObject._fromMap(this, map); |
| 280 if (obj.canCache) { | 280 if (obj.canCache) { |
| 281 _cache.putIfAbsent(id, () => obj); | 281 _cache.putIfAbsent(id, () => obj); |
| 282 } | 282 } |
| 283 return obj; | 283 return obj; |
| 284 }); | 284 }); |
| 285 } | 285 } |
| 286 | 286 |
| 287 Future<ObservableMap> _processMap(ObservableMap map) { | |
| 288 // Verify that the top level response is a service map. | |
| 289 if (!_isServiceMap(map)) { | |
| 290 return new Future.error( | |
| 291 new ServiceObject._fromMap(this, toObservable({ | |
| 292 'type': 'ServiceException', | |
| 293 'id': '', | |
| 294 'kind': 'FormatException', | |
| 295 'response': map, | |
| 296 'message': 'Top level service responses must be service maps.', | |
| 297 }))); | |
| 298 } | |
| 299 // Preemptively capture ServiceError and ServiceExceptions. | |
| 300 if (map['type'] == 'ServiceError') { | |
| 301 return new Future.error(new ServiceObject._fromMap(this, map)); | |
| 302 } else if (map['type'] == 'ServiceException') { | |
| 303 return new Future.error(new ServiceObject._fromMap(this, map)); | |
| 304 } | |
| 305 // map is now guaranteed to be a non-error/exception ServiceObject. | |
| 306 return new Future.value(map); | |
| 307 } | |
| 308 | |
| 287 /// Gets [id] as an [ObservableMap] from the service directly. If | 309 /// Gets [id] as an [ObservableMap] from the service directly. If |
| 288 /// an error occurs, the future is completed as an error with a | 310 /// an error occurs, the future is completed as an error with a |
| 289 /// ServiceError or ServiceException. Therefore any chained then() calls | 311 /// ServiceError or ServiceException. Therefore any chained then() calls |
| 290 /// will only receive a map encoding a valid ServiceObject. | 312 /// will only receive a map encoding a valid ServiceObject. |
| 291 Future<ObservableMap> getAsMap(String id) { | 313 Future<ObservableMap> getAsMap(String id) { |
| 292 return getString(id).then((response) { | 314 return getString(id).then((response) { |
| 293 try { | 315 try { |
| 294 var map = toObservable(JSON.decode(response)); | 316 var map = toObservable(JSON.decode(response)); |
| 295 // Verify that the top level response is a service map. | 317 return _processMap(map); |
| 296 if (!_isServiceMap(map)) { | |
| 297 return new Future.error( | |
| 298 new ServiceObject._fromMap(this, toObservable({ | |
| 299 'type': 'ServiceException', | |
| 300 'id': '', | |
| 301 'kind': 'FormatException', | |
| 302 'response': map, | |
| 303 'message': 'Top level service responses must be service maps.', | |
| 304 }))); | |
| 305 } | |
| 306 // Preemptively capture ServiceError and ServiceExceptions. | |
| 307 if (map['type'] == 'ServiceError') { | |
| 308 return new Future.error(new ServiceObject._fromMap(this, map)); | |
| 309 } else if (map['type'] == 'ServiceException') { | |
| 310 return new Future.error(new ServiceObject._fromMap(this, map)); | |
| 311 } | |
| 312 // map is now guaranteed to be a non-error/exception ServiceObject. | |
| 313 return map; | |
| 314 } catch (e, st) { | 318 } catch (e, st) { |
| 315 print(e); | 319 // Two decode failures. |
|
turnidge
2014/05/06 18:44:22
remove comment.
| |
| 316 print(st); | |
| 317 return new Future.error( | 320 return new Future.error( |
| 318 new ServiceObject._fromMap(this, toObservable({ | 321 new ServiceObject._fromMap(this, toObservable({ |
| 319 'type': 'ServiceException', | 322 'type': 'ServiceException', |
| 320 'id': '', | 323 'id': '', |
| 321 'kind': 'DecodeException', | 324 'kind': 'DecodeException', |
| 322 'response': response, | 325 'response': |
| 326 'This is likely a result of a known V8 bug. Although the ' | |
| 327 'the bug has been fixed the fix may not be in your Chrome' | |
| 328 ' version. For more information see dartbug.com/18385. ' | |
| 329 'Observatory is still functioning and you should try your' | |
| 330 ' action again.', | |
| 323 'message': 'Could not decode JSON: $e', | 331 'message': 'Could not decode JSON: $e', |
| 324 }))); | 332 }))); |
| 325 } | 333 } |
| 326 }).catchError((error) { | 334 }).catchError((error) { |
| 327 // ServiceError, forward to VM's ServiceError stream. | 335 // ServiceError, forward to VM's ServiceError stream. |
| 328 errors.add(error); | 336 errors.add(error); |
| 329 return new Future.error(error); | 337 return new Future.error(error); |
| 330 }, test: (e) => e is ServiceError).catchError((exception) { | 338 }, test: (e) => e is ServiceError).catchError((exception) { |
| 331 // ServiceException, forward to VM's ServiceException stream. | 339 // ServiceException, forward to VM's ServiceException stream. |
| 332 exceptions.add(exception); | 340 exceptions.add(exception); |
| (...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1476 var v = list[i]; | 1484 var v = list[i]; |
| 1477 if ((v is ObservableMap) && _isServiceMap(v)) { | 1485 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 1478 list[i] = owner.getFromMap(v); | 1486 list[i] = owner.getFromMap(v); |
| 1479 } else if (v is ObservableList) { | 1487 } else if (v is ObservableList) { |
| 1480 _upgradeObservableList(v, owner); | 1488 _upgradeObservableList(v, owner); |
| 1481 } else if (v is ObservableMap) { | 1489 } else if (v is ObservableMap) { |
| 1482 _upgradeObservableMap(v, owner); | 1490 _upgradeObservableMap(v, owner); |
| 1483 } | 1491 } |
| 1484 } | 1492 } |
| 1485 } | 1493 } |
| OLD | NEW |