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 /// Recursively upgrades all [ServiceObject]s inside [collection] which must | 7 /// Recursively upgrades all [ServiceObject]s inside [collection] which must |
8 /// be an [ObservableMap] or an [ObservableList]. Upgraded elements will be | 8 /// be an [ObservableMap] or an [ObservableList]. Upgraded elements will be |
9 /// associated with [vm] and [isolate]. | 9 /// associated with [vm] and [isolate]. |
10 void upgradeCollection(collection, VM vm, Isolate isolate) { | 10 void upgradeCollection(collection, VM vm, Isolate isolate) { |
(...skipping 26 matching lines...) Expand all Loading... |
37 } else if (v is ObservableMap) { | 37 } else if (v is ObservableMap) { |
38 _upgradeObservableMap(v, vm, isolate); | 38 _upgradeObservableMap(v, vm, isolate); |
39 } | 39 } |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 /// Upgrades response ([m]) from [vm] and [isolate] to a [ServiceObject]. | 43 /// Upgrades response ([m]) from [vm] and [isolate] to a [ServiceObject]. |
44 /// This acts like a factory which consumes an ObservableMap and returns | 44 /// This acts like a factory which consumes an ObservableMap and returns |
45 /// a fully upgraded ServiceObject. | 45 /// a fully upgraded ServiceObject. |
46 ServiceObject _upgradeToServiceObject(VM vm, Isolate isolate, ObservableMap m) { | 46 ServiceObject _upgradeToServiceObject(VM vm, Isolate isolate, ObservableMap m) { |
47 if (m == null) { | |
48 return null; | |
49 } | |
50 if (!ServiceObject.isServiceMap(m)) { | |
51 Logger.root.severe("Malformed service object: $m"); | |
52 } | |
53 assert(ServiceObject.isServiceMap(m)); | 47 assert(ServiceObject.isServiceMap(m)); |
54 var type = ServiceObject.stripRef(m['type']); | 48 var type = ServiceObject.stripRef(m['type']); |
| 49 // ServiceError and ServiceExceptions are handled before we attempt |
| 50 // to upgrade. |
| 51 assert(type != 'ServiceError'); |
| 52 assert(type != 'ServiceException'); |
55 switch (type) { | 53 switch (type) { |
56 case 'Error': | 54 case 'Error': |
57 if (isolate != null) { | 55 if (isolate != null) { |
58 return new ServiceError.fromMap(isolate, m); | 56 return new DartError.fromMap(isolate, m); |
59 } else { | 57 } else { |
60 return new ServiceError.fromMap(vm, m); | 58 return new DartError.fromMap(vm, m); |
61 } | 59 } |
62 break; | 60 break; |
63 case 'Script': | 61 case 'Script': |
64 return isolate.scripts.putIfAbsent(m); | 62 return isolate.scripts.putIfAbsent(m); |
65 case 'Code': | 63 case 'Code': |
66 return isolate.codes.putIfAbsent(m); | 64 return isolate.codes.putIfAbsent(m); |
67 case 'Isolate': | 65 case 'Isolate': |
68 return vm.isolates.getIsolateFromMap(m); | 66 return vm.isolates.getIsolateFromMap(m); |
69 case 'Class': | 67 case 'Class': |
70 return isolate.classes.putIfAbsent(m); | 68 return isolate.classes.putIfAbsent(m); |
71 case 'Function': | 69 case 'Function': |
72 return isolate.functions.putIfAbsent(m); | 70 return isolate.functions.putIfAbsent(m); |
73 case 'VM': | 71 case 'VM': |
74 return vm.update(m); | 72 return vm.update(m); |
75 } | 73 } |
76 return new ServiceMap.fromMap(isolate, m); | 74 return new ServiceMap.fromMap(isolate, m); |
77 } | 75 } |
OLD | NEW |