| 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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 'message': 'Could not decode JSON: $e', | 396 'message': 'Could not decode JSON: $e', |
| 397 }))); | 397 }))); |
| 398 } | 398 } |
| 399 | 399 |
| 400 /// Gets [id] as an [ObservableMap] from the service directly. If | 400 /// Gets [id] as an [ObservableMap] from the service directly. If |
| 401 /// an error occurs, the future is completed as an error with a | 401 /// an error occurs, the future is completed as an error with a |
| 402 /// ServiceError or ServiceException. Therefore any chained then() calls | 402 /// ServiceError or ServiceException. Therefore any chained then() calls |
| 403 /// will only receive a map encoding a valid ServiceObject. | 403 /// will only receive a map encoding a valid ServiceObject. |
| 404 Future<ObservableMap> getAsMap(String id) { | 404 Future<ObservableMap> getAsMap(String id) { |
| 405 return getString(id).then((response) { | 405 return getString(id).then((response) { |
| 406 var map; | 406 var map = _parseJSON(response); |
| 407 try { | |
| 408 map = _parseJSON(response); | |
| 409 } catch (e, st) { | |
| 410 print('Hit V8 bug.'); | |
| 411 return _decodeError(e); | |
| 412 } | |
| 413 return _processMap(map); | 407 return _processMap(map); |
| 414 }).catchError((error) { | 408 }).catchError((error) { |
| 415 // ServiceError, forward to VM's ServiceError stream. | 409 // ServiceError, forward to VM's ServiceError stream. |
| 416 errors.add(error); | 410 errors.add(error); |
| 417 return new Future.error(error); | 411 return new Future.error(error); |
| 418 }, test: (e) => e is ServiceError).catchError((exception) { | 412 }, test: (e) => e is ServiceError).catchError((exception) { |
| 419 // ServiceException, forward to VM's ServiceException stream. | 413 // ServiceException, forward to VM's ServiceException stream. |
| 420 exceptions.add(exception); | 414 exceptions.add(exception); |
| 421 return new Future.error(exception); | 415 return new Future.error(exception); |
| 422 }, test: (e) => e is ServiceException); | 416 }, test: (e) => e is ServiceException); |
| 423 } | 417 } |
| 424 | 418 |
| 425 /// Get [id] as a [String] from the service directly. See [getAsMap]. | 419 /// Get [id] as a [String] from the service directly. See [getAsMap]. |
| 426 Future<String> getString(String id); | 420 Future<String> getString(String id); |
| 421 /// Force the VM to disconnect. |
| 422 void disconnect(); |
| 423 /// Completes when the VM first connects. |
| 424 Future get onConnect; |
| 425 /// Completes when the VM disconnects or there was an error connecting. |
| 426 Future get onDisconnect; |
| 427 | 427 |
| 428 void _update(ObservableMap map, bool mapIsRef) { | 428 void _update(ObservableMap map, bool mapIsRef) { |
| 429 if (mapIsRef) { | 429 if (mapIsRef) { |
| 430 return; | 430 return; |
| 431 } | 431 } |
| 432 _loaded = true; | 432 _loaded = true; |
| 433 version = map['version']; | 433 version = map['version']; |
| 434 architecture = map['architecture']; | 434 architecture = map['architecture']; |
| 435 uptime = map['uptime']; | 435 uptime = map['uptime']; |
| 436 var dateInMillis = int.parse(map['date']); | 436 var dateInMillis = int.parse(map['date']); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 | 688 |
| 689 Future<ServiceObject> get(String id) { | 689 Future<ServiceObject> get(String id) { |
| 690 // Do not allow null ids or empty ids. | 690 // Do not allow null ids or empty ids. |
| 691 assert(id != null && id != ''); | 691 assert(id != null && id != ''); |
| 692 var obj = _cache[id]; | 692 var obj = _cache[id]; |
| 693 if (obj != null) { | 693 if (obj != null) { |
| 694 return obj.reload(); | 694 return obj.reload(); |
| 695 } | 695 } |
| 696 // Cache miss. Get the object from the vm directly. | 696 // Cache miss. Get the object from the vm directly. |
| 697 return vm.getAsMap(relativeLink(id)).then((ObservableMap map) { | 697 return vm.getAsMap(relativeLink(id)).then((ObservableMap map) { |
| 698 var obj = new ServiceObject._fromMap(this, map); | 698 var obj = new ServiceObject._fromMap(this, map); |
| 699 if (obj.canCache) { | 699 if (obj.canCache) { |
| 700 _cache.putIfAbsent(id, () => obj); | 700 _cache.putIfAbsent(id, () => obj); |
| 701 } | 701 } |
| 702 return obj; | 702 return obj; |
| 703 }); | 703 }); |
| 704 } | 704 } |
| 705 | 705 |
| 706 @observable Class objectClass; | 706 @observable Class objectClass; |
| 707 @observable final rootClasses = new ObservableList<Class>(); | 707 @observable final rootClasses = new ObservableList<Class>(); |
| 708 | 708 |
| 709 @observable Library rootLib; | 709 @observable Library rootLib; |
| 710 @observable ObservableList<Library> libraries = | 710 @observable ObservableList<Library> libraries = |
| 711 new ObservableList<Library>(); | 711 new ObservableList<Library>(); |
| 712 @observable ObservableMap topFrame; | 712 @observable ObservableMap topFrame; |
| 713 | 713 |
| (...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 var v = list[i]; | 1902 var v = list[i]; |
| 1903 if ((v is ObservableMap) && _isServiceMap(v)) { | 1903 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 1904 list[i] = owner.getFromMap(v); | 1904 list[i] = owner.getFromMap(v); |
| 1905 } else if (v is ObservableList) { | 1905 } else if (v is ObservableList) { |
| 1906 _upgradeObservableList(v, owner); | 1906 _upgradeObservableList(v, owner); |
| 1907 } else if (v is ObservableMap) { | 1907 } else if (v is ObservableMap) { |
| 1908 _upgradeObservableMap(v, owner); | 1908 _upgradeObservableMap(v, owner); |
| 1909 } | 1909 } |
| 1910 } | 1910 } |
| 1911 } | 1911 } |
| OLD | NEW |