| 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 library service_html; | 5 library service_html; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // want to connect on the default port. | 29 // want to connect on the default port. |
| 30 host = 'http://127.0.0.1:8181/'; | 30 host = 'http://127.0.0.1:8181/'; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 Future<String> getString(String id) { | 34 Future<String> getString(String id) { |
| 35 Logger.root.info('Fetching $id from $host'); | 35 Logger.root.info('Fetching $id from $host'); |
| 36 return HttpRequest.getString(host + id).catchError((error) { | 36 return HttpRequest.getString(host + id).catchError((error) { |
| 37 // If we get an error here, the network request has failed. | 37 // If we get an error here, the network request has failed. |
| 38 Logger.root.severe('HttpRequest.getString failed.'); | 38 Logger.root.severe('HttpRequest.getString failed.'); |
| 39 var request = error.target; |
| 39 return JSON.encode({ | 40 return JSON.encode({ |
| 40 'type': 'Error', | 41 'type': 'ServiceException', |
| 41 'id': '', | 42 'id': '', |
| 42 'kind': 'NetworkError', | 43 'response': error.target.responseText, |
| 44 'kind': 'NetworkException', |
| 43 'message': 'Could not connect to service. Check that you started the' | 45 'message': 'Could not connect to service. Check that you started the' |
| 44 ' VM with the following flags:\n --enable-vm-service' | 46 ' VM with the following flags:\n --enable-vm-service' |
| 45 ' --pin-isolates' | 47 ' --pause-isolates-on-exit' |
| 46 }); | 48 }); |
| 47 }); | 49 }); |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 | 52 |
| 51 class DartiumVM extends VM { | 53 class DartiumVM extends VM { |
| 52 final Map _outstandingRequests = new Map(); | 54 final Map _outstandingRequests = new Map(); |
| 53 int _requestSerial = 0; | 55 int _requestSerial = 0; |
| 54 | 56 |
| 55 DartiumVM() : super() { | 57 DartiumVM() : super() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 76 message['id'] = idString; | 78 message['id'] = idString; |
| 77 message['method'] = 'observatoryQuery'; | 79 message['method'] = 'observatoryQuery'; |
| 78 message['query'] = '/$path'; | 80 message['query'] = '/$path'; |
| 79 _requestSerial++; | 81 _requestSerial++; |
| 80 var completer = new Completer(); | 82 var completer = new Completer(); |
| 81 _outstandingRequests[idString] = completer; | 83 _outstandingRequests[idString] = completer; |
| 82 window.parent.postMessage(JSON.encode(message), '*'); | 84 window.parent.postMessage(JSON.encode(message), '*'); |
| 83 return completer.future; | 85 return completer.future; |
| 84 } | 86 } |
| 85 } | 87 } |
| OLD | NEW |