| 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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 488 |
| 489 dynamic _reviver(dynamic key, dynamic value) { | 489 dynamic _reviver(dynamic key, dynamic value) { |
| 490 return value; | 490 return value; |
| 491 } | 491 } |
| 492 | 492 |
| 493 ObservableMap _parseJSON(String response) { | 493 ObservableMap _parseJSON(String response) { |
| 494 var map; | 494 var map; |
| 495 try { | 495 try { |
| 496 var decoder = new JsonDecoder(_reviver); | 496 var decoder = new JsonDecoder(_reviver); |
| 497 map = decoder.convert(response); | 497 map = decoder.convert(response); |
| 498 } catch (e, st) { | 498 } catch (e) { |
| 499 return null; | 499 return toObservable({ |
| 500 'type': 'ServiceException', |
| 501 'kind': 'JSONDecodeException', |
| 502 'response': map, |
| 503 'message': 'Could not decode JSON: $e', |
| 504 }); |
| 500 } | 505 } |
| 501 return toObservable(map); | 506 return toObservable(map); |
| 502 } | 507 } |
| 503 | 508 |
| 504 Future<ObservableMap> _processMap(ObservableMap map) { | 509 Future<ObservableMap> _processMap(ObservableMap map) { |
| 505 // Verify that the top level response is a service map. | 510 // Verify that the top level response is a service map. |
| 506 if (!_isServiceMap(map)) { | 511 if (!_isServiceMap(map)) { |
| 507 return new Future.error( | 512 return new Future.error( |
| 508 new ServiceObject._fromMap(this, toObservable({ | 513 new ServiceObject._fromMap(this, toObservable({ |
| 509 'type': 'ServiceException', | 514 'type': 'ServiceException', |
| 510 'id': '', | 515 'kind': 'ResponseFormatException', |
| 511 'kind': 'FormatException', | |
| 512 'response': map, | 516 'response': map, |
| 513 'message': 'Top level service responses must be service maps: ${map}.', | 517 'message': 'Top level service responses must be service maps: ${map}.', |
| 514 }))); | 518 }))); |
| 515 } | 519 } |
| 516 // Preemptively capture ServiceError and ServiceExceptions. | 520 // Preemptively capture ServiceError and ServiceExceptions. |
| 517 if (map['type'] == 'ServiceError') { | 521 if (map['type'] == 'ServiceError') { |
| 518 return new Future.error(new ServiceObject._fromMap(this, map)); | 522 return new Future.error(new ServiceObject._fromMap(this, map)); |
| 519 } else if (map['type'] == 'ServiceException') { | 523 } else if (map['type'] == 'ServiceException') { |
| 520 return new Future.error(new ServiceObject._fromMap(this, map)); | 524 return new Future.error(new ServiceObject._fromMap(this, map)); |
| 521 } | 525 } |
| 522 // map is now guaranteed to be a non-error/exception ServiceObject. | 526 // map is now guaranteed to be a non-error/exception ServiceObject. |
| 523 return new Future.value(map); | 527 return new Future.value(map); |
| 524 } | 528 } |
| 525 | 529 |
| 526 Future<ObservableMap> _decodeError(e) { | |
| 527 return new Future.error(new ServiceObject._fromMap(this, toObservable({ | |
| 528 'type': 'ServiceException', | |
| 529 'id': '', | |
| 530 'kind': 'DecodeException', | |
| 531 'response': | |
| 532 'This is likely a result of a known V8 bug. Although the ' | |
| 533 'the bug has been fixed the fix may not be in your Chrome' | |
| 534 ' version. For more information see dartbug.com/18385. ' | |
| 535 'Observatory is still functioning and you should try your' | |
| 536 ' action again.', | |
| 537 'message': 'Could not decode JSON: $e', | |
| 538 }))); | |
| 539 } | |
| 540 | |
| 541 /// Gets [id] as an [ObservableMap] from the service directly. If | 530 /// Gets [id] as an [ObservableMap] from the service directly. If |
| 542 /// an error occurs, the future is completed as an error with a | 531 /// an error occurs, the future is completed as an error with a |
| 543 /// ServiceError or ServiceException. Therefore any chained then() calls | 532 /// ServiceError or ServiceException. Therefore any chained then() calls |
| 544 /// will only receive a map encoding a valid ServiceObject. | 533 /// will only receive a map encoding a valid ServiceObject. |
| 545 Future<ObservableMap> _getAsMapDeprecated(String id) { | 534 Future<ObservableMap> _getAsMapDeprecated(String id) { |
| 546 return getStringDeprecated(id).then((response) { | 535 return getStringDeprecated(id).then((response) { |
| 547 var map = _parseJSON(response); | 536 var map = _parseJSON(response); |
| 548 if (Tracer.current != null) { | 537 if (Tracer.current != null) { |
| 549 Tracer.current.trace("Received response for ${id}", map:map); | 538 Tracer.current.trace("Received response for ${id}", map:map); |
| 550 } | 539 } |
| (...skipping 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2952 var v = list[i]; | 2941 var v = list[i]; |
| 2953 if ((v is ObservableMap) && _isServiceMap(v)) { | 2942 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 2954 list[i] = owner.getFromMap(v); | 2943 list[i] = owner.getFromMap(v); |
| 2955 } else if (v is ObservableList) { | 2944 } else if (v is ObservableList) { |
| 2956 _upgradeObservableList(v, owner); | 2945 _upgradeObservableList(v, owner); |
| 2957 } else if (v is ObservableMap) { | 2946 } else if (v is ObservableMap) { |
| 2958 _upgradeObservableMap(v, owner); | 2947 _upgradeObservableMap(v, owner); |
| 2959 } | 2948 } |
| 2960 } | 2949 } |
| 2961 } | 2950 } |
| OLD | NEW |