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

Side by Side Diff: runtime/vm/service/message.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: edits 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
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; 5 part of vmservice;
6 6
7 class Message { 7 class Message {
8 final Completer _completer = new Completer.sync(); 8 final Completer _completer = new Completer.sync();
9 bool get completed => _completer.isCompleted; 9 bool get completed => _completer.isCompleted;
10 /// Future of response. 10 /// Future of response.
(...skipping 15 matching lines...) Expand all
26 return; 26 return;
27 } 27 }
28 pathSegments.forEach((String segment) { 28 pathSegments.forEach((String segment) {
29 if (segment == null || segment == '') { 29 if (segment == null || segment == '') {
30 return; 30 return;
31 } 31 }
32 path.add(segment); 32 path.add(segment);
33 }); 33 });
34 } 34 }
35 35
36 Message.fromJsonRpc(Map map) : serial = map['id'], method = map['method'] { 36 Message.fromJsonRpc(Map map)
37 : serial = map['id'], method = map['method'] {
37 params.addAll(map['params']); 38 params.addAll(map['params']);
38 } 39 }
39 40
40 static String _methodNameFromUri(Uri uri) { 41 static String _methodNameFromUri(Uri uri) {
41 if (uri == null) { 42 if (uri == null) {
42 return ''; 43 return '';
43 } 44 }
44 if (uri.pathSegments.length == 0) { 45 if (uri.pathSegments.length == 0) {
45 return ''; 46 return '';
46 } 47 }
47 return uri.pathSegments[0]; 48 return uri.pathSegments[0];
48 } 49 }
49 50
50 Message.fromUri(Uri uri) : method = _methodNameFromUri(uri) { 51 Message.fromUri(Uri uri)
52 : method = _methodNameFromUri(uri) {
51 params.addAll(uri.queryParameters); 53 params.addAll(uri.queryParameters);
52 } 54 }
53 55
54 dynamic toJson() { 56 dynamic toJson() {
55 return { 57 return {
56 'path': path, 58 'path': path,
57 'params': params 59 'params': params
58 }; 60 };
59 } 61 }
60 62
(...skipping 16 matching lines...) Expand all
77 79
78 Future<String> send(SendPort sendPort) { 80 Future<String> send(SendPort sendPort) {
79 final receivePort = new RawReceivePort(); 81 final receivePort = new RawReceivePort();
80 receivePort.handler = (value) { 82 receivePort.handler = (value) {
81 receivePort.close(); 83 receivePort.close();
82 assert(value is String); 84 assert(value is String);
83 _completer.complete(value); 85 _completer.complete(value);
84 }; 86 };
85 var keys = _makeAllString(params.keys.toList(growable:false)); 87 var keys = _makeAllString(params.keys.toList(growable:false));
86 var values = _makeAllString(params.values.toList(growable:false)); 88 var values = _makeAllString(params.values.toList(growable:false));
87 var request = new List(5) 89 var request = new List(6)
88 ..[0] = 0 // Make room for OOB message type. 90 ..[0] = 0 // Make room for OOB message type.
89 ..[1] = receivePort.sendPort 91 ..[1] = receivePort.sendPort
90 ..[2] = method 92 ..[2] = serial.toString()
91 ..[3] = keys 93 ..[3] = method
92 ..[4] = values; 94 ..[4] = keys
95 ..[5] = values;
93 if (!sendIsolateServiceMessage(sendPort, request)) { 96 if (!sendIsolateServiceMessage(sendPort, request)) {
94 _completer.complete(JSON.encode({ 97 _completer.complete(JSON.encode({
95 'type': 'ServiceError', 98 'type': 'ServiceError',
96 'id': '', 99 'id': '',
97 'kind': 'InternalError', 100 'kind': 'InternalError',
98 'message': 'could not send message [${serial}] to isolate', 101 'message': 'could not send message [${serial}] to isolate',
99 })); 102 }));
100 } 103 }
101 return _completer.future; 104 return _completer.future;
102 } 105 }
103 106
104 Future<String> sendToVM() { 107 Future<String> sendToVM() {
105 final receivePort = new RawReceivePort(); 108 final receivePort = new RawReceivePort();
106 receivePort.handler = (value) { 109 receivePort.handler = (value) {
107 receivePort.close(); 110 receivePort.close();
108 assert(value is String); 111 assert(value is String);
109 _completer.complete(value); 112 _completer.complete(value);
110 }; 113 };
111 var keys = _makeAllString(params.keys.toList(growable:false)); 114 var keys = _makeAllString(params.keys.toList(growable:false));
112 var values = _makeAllString(params.values.toList(growable:false)); 115 var values = _makeAllString(params.values.toList(growable:false));
113 var request = new List(5) 116 var request = new List(6)
114 ..[0] = 0 // Make room for OOB message type. 117 ..[0] = 0 // Make room for OOB message type.
115 ..[1] = receivePort.sendPort 118 ..[1] = receivePort.sendPort
116 ..[2] = method 119 ..[2] = serial.toString()
117 ..[3] = keys 120 ..[3] = method
118 ..[4] = values; 121 ..[4] = keys
122 ..[5] = values;
119 sendRootServiceMessage(request); 123 sendRootServiceMessage(request);
120 return _completer.future; 124 return _completer.future;
121 } 125 }
122 126
123 void setResponse(String response) { 127 void setResponse(String response) {
124 _completer.complete(response); 128 _completer.complete(response);
125 } 129 }
126 130
127 void setErrorResponse(String error) { 131 void setErrorResponse(String message) {
128 _completer.complete(JSON.encode({ 132 var response = {
129 'type': 'ServiceError', 133 'id': serial,
130 'id': '', 134 'result' : {
131 'kind': 'RequestError', 135 'type': 'Error',
132 'message': error, 136 'message': message,
133 'path': path, 137 'request': {
134 'params': params 138 'method': method,
135 })); 139 'params': params
140 }
141 }
142 };
143 _completer.complete(JSON.encode(response));
136 } 144 }
137 } 145 }
138 146
139 bool sendIsolateServiceMessage(SendPort sp, List m) 147 bool sendIsolateServiceMessage(SendPort sp, List m)
140 native "VMService_SendIsolateServiceMessage"; 148 native "VMService_SendIsolateServiceMessage";
141 149
142 void sendRootServiceMessage(List m) 150 void sendRootServiceMessage(List m)
143 native "VMService_SendRootServiceMessage"; 151 native "VMService_SendRootServiceMessage";
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698