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] represents a persistent object within the vm. | 7 /// A [ServiceObject] represents a persistent object within the vm. |
| 8 abstract class ServiceObject extends Observable { | 8 abstract class ServiceObject extends Observable { |
| 9 static int LexicalSortName(ServiceObject o1, ServiceObject o2) { | 9 static int LexicalSortName(ServiceObject o1, ServiceObject o2) { |
| 10 return o1.name.compareTo(o2.name); | 10 return o1.name.compareTo(o2.name); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 update(toObservable({'id':'vm', 'type':'@VM'})); | 362 update(toObservable({'id':'vm', 'type':'@VM'})); |
| 363 } | 363 } |
| 364 | 364 |
| 365 final StreamController<ServiceException> exceptions = | 365 final StreamController<ServiceException> exceptions = |
| 366 new StreamController.broadcast(); | 366 new StreamController.broadcast(); |
| 367 final StreamController<ServiceError> errors = | 367 final StreamController<ServiceError> errors = |
| 368 new StreamController.broadcast(); | 368 new StreamController.broadcast(); |
| 369 final StreamController<ServiceEvent> events = | 369 final StreamController<ServiceEvent> events = |
| 370 new StreamController.broadcast(); | 370 new StreamController.broadcast(); |
| 371 | 371 |
| 372 void postServiceEvent(String response, ByteData data) { | 372 void postServiceEvent(Map response, ByteData data) { |
| 373 var map; | 373 var map = toObservable(response); |
| 374 try { | 374 assert(!map.containsKey('_data')); |
| 375 map = _parseJSON(response); | 375 if (data != null) { |
| 376 assert(!map.containsKey('_data')); | 376 map['_data'] = data; |
| 377 if (data != null) { | |
| 378 map['_data'] = data; | |
| 379 } | |
| 380 } catch (_) { | |
| 381 Logger.root.severe('Ignoring malformed event response: ${response}'); | |
| 382 return; | |
| 383 } | 377 } |
| 384 if (map['type'] != 'ServiceEvent') { | 378 if (map['type'] != 'ServiceEvent') { |
| 385 Logger.root.severe( | 379 Logger.root.severe( |
| 386 "Expected 'ServiceEvent' but found '${map['type']}'"); | 380 "Expected 'ServiceEvent' but found '${map['type']}'"); |
| 387 return; | 381 return; |
| 388 } | 382 } |
| 389 | 383 |
| 390 var eventIsolate = map['isolate']; | 384 var eventIsolate = map['isolate']; |
| 391 if (eventIsolate == null) { | 385 if (eventIsolate == null) { |
| 392 var event = new ServiceObject._fromMap(vm, map); | 386 var event = new ServiceObject._fromMap(vm, map); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 // Note that this function does not reload the isolate if it found | 452 // Note that this function does not reload the isolate if it found |
| 459 // in the cache. | 453 // in the cache. |
| 460 Future<ServiceObject> getIsolate(String isolateId) { | 454 Future<ServiceObject> getIsolate(String isolateId) { |
| 461 if (!loaded) { | 455 if (!loaded) { |
| 462 // Trigger a VM load, then get the isolate. | 456 // Trigger a VM load, then get the isolate. |
| 463 return load().then((_) => getIsolate(isolateId)).catchError(_ignoreError); | 457 return load().then((_) => getIsolate(isolateId)).catchError(_ignoreError); |
| 464 } | 458 } |
| 465 return new Future.value(_isolateCache[isolateId]); | 459 return new Future.value(_isolateCache[isolateId]); |
| 466 } | 460 } |
| 467 | 461 |
| 468 dynamic _reviver(dynamic key, dynamic value) { | |
| 469 return value; | |
| 470 } | |
| 471 | |
| 472 ObservableMap _parseJSON(String response) { | |
| 473 var map; | |
| 474 try { | |
| 475 var decoder = new JsonDecoder(_reviver); | |
| 476 map = decoder.convert(response); | |
| 477 } catch (e) { | |
| 478 return toObservable({ | |
| 479 'type': 'ServiceException', | |
| 480 'kind': 'JSONDecodeException', | |
| 481 'response': map, | |
| 482 'message': 'Could not decode JSON: $e', | |
| 483 }); | |
| 484 } | |
| 485 return toObservable(map); | |
| 486 } | |
| 487 | |
| 488 Future<ObservableMap> _processMap(ObservableMap map) { | 462 Future<ObservableMap> _processMap(ObservableMap map) { |
| 489 // Verify that the top level response is a service map. | 463 // Verify that the top level response is a service map. |
| 490 if (!_isServiceMap(map)) { | 464 if (!_isServiceMap(map)) { |
| 491 return new Future.error( | 465 return new Future.error( |
| 492 new ServiceObject._fromMap(this, toObservable({ | 466 new ServiceObject._fromMap(this, toObservable({ |
| 493 'type': 'ServiceException', | 467 'type': 'ServiceException', |
| 494 'kind': 'ResponseFormatException', | 468 'kind': 'ResponseFormatException', |
| 495 'response': map, | 469 'response': map, |
| 496 'message': 'Top level service responses must be service maps: ${map}.', | 470 'message': 'Top level service responses must be service maps: ${map}.', |
|
Cutch
2015/04/21 23:38:53
Drop the ${map} it is included as 'response'.
'me
turnidge
2015/04/23 17:51:59
Done.
| |
| 497 }))); | 471 }))); |
| 498 } | 472 } |
| 499 // Preemptively capture ServiceError and ServiceExceptions. | 473 // Preemptively capture ServiceError and ServiceExceptions. |
| 500 if (map['type'] == 'ServiceError') { | 474 if (map['type'] == 'ServiceError') { |
| 501 return new Future.error(new ServiceObject._fromMap(this, map)); | 475 return new Future.error(new ServiceObject._fromMap(this, map)); |
| 502 } else if (map['type'] == 'ServiceException') { | 476 } else if (map['type'] == 'ServiceException') { |
| 503 return new Future.error(new ServiceObject._fromMap(this, map)); | 477 return new Future.error(new ServiceObject._fromMap(this, map)); |
| 504 } | 478 } |
| 505 // map is now guaranteed to be a non-error/exception ServiceObject. | 479 // map is now guaranteed to be a non-error/exception ServiceObject. |
| 506 return new Future.value(map); | 480 return new Future.value(map); |
| 507 } | 481 } |
| 508 | 482 |
| 509 // Implemented in subclass. | 483 // Implemented in subclass. |
| 510 Future<String> invokeRpcRaw(String method, Map params); | 484 Future<Map> invokeRpcRaw(String method, Map params); |
| 511 | 485 |
| 512 Future<ObservableMap> invokeRpcNoUpgrade(String method, Map params) { | 486 Future<ObservableMap> invokeRpcNoUpgrade(String method, Map params) { |
| 513 return invokeRpcRaw(method, params).then((String response) { | 487 return invokeRpcRaw(method, params).then((Map response) { |
| 514 var map = _parseJSON(response); | 488 var map = toObservable(response); |
| 515 if (Tracer.current != null) { | 489 if (Tracer.current != null) { |
| 516 Tracer.current.trace("Received response for ${method}/${params}}", | 490 Tracer.current.trace("Received response for ${method}/${params}}", |
| 517 map:map); | 491 map:map); |
| 518 } | 492 } |
| 519 | 493 |
| 520 // Check for ill-formed responses. | 494 // Check for ill-formed responses. |
| 521 return _processMap(map); | 495 return _processMap(map); |
| 522 }).catchError((error) { | 496 }).catchError((error) { |
| 523 | 497 |
| 524 // ServiceError, forward to VM's ServiceError stream. | 498 // ServiceError, forward to VM's ServiceError stream. |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1402 static const kPauseExit = 'PauseExit'; | 1376 static const kPauseExit = 'PauseExit'; |
| 1403 static const kPauseBreakpoint = 'PauseBreakpoint'; | 1377 static const kPauseBreakpoint = 'PauseBreakpoint'; |
| 1404 static const kPauseInterrupted = 'PauseInterrupted'; | 1378 static const kPauseInterrupted = 'PauseInterrupted'; |
| 1405 static const kPauseException = 'PauseException'; | 1379 static const kPauseException = 'PauseException'; |
| 1406 static const kResume = 'Resume'; | 1380 static const kResume = 'Resume'; |
| 1407 static const kBreakpointAdded = 'BreakpointAdded'; | 1381 static const kBreakpointAdded = 'BreakpointAdded'; |
| 1408 static const kBreakpointResolved = 'BreakpointResolved'; | 1382 static const kBreakpointResolved = 'BreakpointResolved'; |
| 1409 static const kBreakpointRemoved = 'BreakpointRemoved'; | 1383 static const kBreakpointRemoved = 'BreakpointRemoved'; |
| 1410 static const kGraph = '_Graph'; | 1384 static const kGraph = '_Graph'; |
| 1411 static const kGC = 'GC'; | 1385 static const kGC = 'GC'; |
| 1412 static const kVMDisconnected = 'VMDisconnected'; | 1386 static const kConnectionClosed = 'ConnectionClosed'; |
| 1413 | 1387 |
| 1414 ServiceEvent._empty(ServiceObjectOwner owner) : super._empty(owner); | 1388 ServiceEvent._empty(ServiceObjectOwner owner) : super._empty(owner); |
| 1415 | 1389 |
| 1416 ServiceEvent.vmDisconencted() : super._empty(null) { | 1390 ServiceEvent.connectionClosed(this.reason) : super._empty(null) { |
| 1417 eventType = kVMDisconnected; | 1391 eventType = kConnectionClosed; |
| 1418 } | 1392 } |
| 1419 | 1393 |
| 1420 @observable String eventType; | 1394 @observable String eventType; |
| 1421 @observable Breakpoint breakpoint; | 1395 @observable Breakpoint breakpoint; |
| 1422 @observable ServiceMap topFrame; | 1396 @observable ServiceMap topFrame; |
| 1423 @observable ServiceMap exception; | 1397 @observable ServiceMap exception; |
| 1424 @observable ByteData data; | 1398 @observable ByteData data; |
| 1425 @observable int count; | 1399 @observable int count; |
| 1400 @observable String reason; | |
| 1426 | 1401 |
| 1427 void _update(ObservableMap map, bool mapIsRef) { | 1402 void _update(ObservableMap map, bool mapIsRef) { |
| 1428 _loaded = true; | 1403 _loaded = true; |
| 1429 _upgradeCollection(map, owner); | 1404 _upgradeCollection(map, owner); |
| 1430 assert(map['isolate'] == null || owner == map['isolate']); | 1405 assert(map['isolate'] == null || owner == map['isolate']); |
| 1431 eventType = map['eventType']; | 1406 eventType = map['eventType']; |
| 1432 name = 'ServiceEvent $eventType'; | 1407 name = 'ServiceEvent $eventType'; |
| 1433 vmName = name; | 1408 vmName = name; |
| 1434 if (map['breakpoint'] != null) { | 1409 if (map['breakpoint'] != null) { |
| 1435 breakpoint = map['breakpoint']; | 1410 breakpoint = map['breakpoint']; |
| (...skipping 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2945 var v = list[i]; | 2920 var v = list[i]; |
| 2946 if ((v is ObservableMap) && _isServiceMap(v)) { | 2921 if ((v is ObservableMap) && _isServiceMap(v)) { |
| 2947 list[i] = owner.getFromMap(v); | 2922 list[i] = owner.getFromMap(v); |
| 2948 } else if (v is ObservableList) { | 2923 } else if (v is ObservableList) { |
| 2949 _upgradeObservableList(v, owner); | 2924 _upgradeObservableList(v, owner); |
| 2950 } else if (v is ObservableMap) { | 2925 } else if (v is ObservableMap) { |
| 2951 _upgradeObservableMap(v, owner); | 2926 _upgradeObservableMap(v, owner); |
| 2952 } | 2927 } |
| 2953 } | 2928 } |
| 2954 } | 2929 } |
| OLD | NEW |