Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(771)

Side by Side Diff: runtime/bin/vmservice/server.dart

Issue 1093043004: Do not JSON encode the 'result' of a service rpc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/observatory/lib/service.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 vmservice_io; 5 part of vmservice_io;
6 6
7 class WebSocketClient extends Client { 7 class WebSocketClient extends Client {
8 static const int PARSE_ERROR_CODE = 4000; 8 static const int PARSE_ERROR_CODE = 4000;
9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001;
10 static const int NOT_MAP_ERROR_CODE = 4002; 10 static const int NOT_MAP_ERROR_CODE = 4002;
(...skipping 17 matching lines...) Expand all
28 socket.close(NOT_MAP_ERROR_CODE, 'Message must be a JSON map.'); 28 socket.close(NOT_MAP_ERROR_CODE, 'Message must be a JSON map.');
29 return; 29 return;
30 } 30 }
31 var serial = map['id']; 31 var serial = map['id'];
32 onMessage(serial, new Message.fromJsonRpc(map)); 32 onMessage(serial, new Message.fromJsonRpc(map));
33 } else { 33 } else {
34 socket.close(BINARY_MESSAGE_ERROR_CODE, 'Message must be a string.'); 34 socket.close(BINARY_MESSAGE_ERROR_CODE, 'Message must be a string.');
35 } 35 }
36 } 36 }
37 37
38 void post(var serial, dynamic result) { 38 void post(dynamic result) {
39 try { 39 try {
40 if (serial == null && result is! String) { 40 socket.add(result);
41 socket.add(result);
42 } else {
43 Map map = {
44 'id': serial,
45 'result': result
46 };
47 socket.add(JSON.encode(map));
48 }
49 } catch (_) { 41 } catch (_) {
50 print("Ignoring error posting over WebSocket."); 42 print("Ignoring error posting over WebSocket.");
51 } 43 }
52 } 44 }
53 45
54 dynamic toJson() { 46 dynamic toJson() {
55 Map map = super.toJson(); 47 Map map = super.toJson();
56 map['type'] = 'WebSocketClient'; 48 map['type'] = 'WebSocketClient';
57 map['socket'] = '$socket'; 49 map['socket'] = '$socket';
58 return map; 50 return map;
59 } 51 }
60 } 52 }
61 53
62 54
63 class HttpRequestClient extends Client { 55 class HttpRequestClient extends Client {
64 static ContentType jsonContentType = 56 static ContentType jsonContentType =
65 new ContentType("application", "json", charset: "utf-8"); 57 new ContentType("application", "json", charset: "utf-8");
66 final HttpRequest request; 58 final HttpRequest request;
67 59
68 HttpRequestClient(this.request, VMService service) 60 HttpRequestClient(this.request, VMService service)
69 : super(service, sendEvents:false); 61 : super(service, sendEvents:false);
70 62
71 void post(var serial, String result) { 63 void post(String result) {
72 request.response..headers.contentType = jsonContentType 64 request.response..headers.contentType = jsonContentType
73 ..write(result) 65 ..write(result)
74 ..close(); 66 ..close();
75 close(); 67 close();
76 } 68 }
77 69
78 dynamic toJson() { 70 dynamic toJson() {
79 Map map = super.toJson(); 71 Map map = super.toJson();
80 map['type'] = 'HttpRequestClient'; 72 map['type'] = 'HttpRequestClient';
81 map['request'] = '$request'; 73 map['request'] = '$request';
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); 202 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n');
211 _notifyServerState("", 0); 203 _notifyServerState("", 0);
212 return this; 204 return this;
213 }); 205 });
214 } 206 }
215 207
216 } 208 }
217 209
218 void _notifyServerState(String ip, int port) 210 void _notifyServerState(String ip, int port)
219 native "VMServiceIO_NotifyServerState"; 211 native "VMServiceIO_NotifyServerState";
OLDNEW
« no previous file with comments | « no previous file | runtime/observatory/lib/service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698