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

Side by Side Diff: tools/dom/src/Isolates.dart

Issue 23596007: Remove usage of dart:json. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 7 years, 3 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 html; 5 part of html;
6 6
7 _serialize(var message) { 7 _serialize(var message) {
8 return new _JsSerializer().traverse(message); 8 return new _JsSerializer().traverse(message);
9 } 9 }
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return _deserialize(result); 93 return _deserialize(result);
94 } 94 }
95 95
96 static _call(int isolateId, int portId, var message) { 96 static _call(int isolateId, int portId, var message) {
97 var target = 'dart-port-$isolateId-$portId'; 97 var target = 'dart-port-$isolateId-$portId';
98 // TODO(vsm): Make this re-entrant. 98 // TODO(vsm): Make this re-entrant.
99 // TODO(vsm): Set this up set once, on the first call. 99 // TODO(vsm): Set this up set once, on the first call.
100 var source = '$target-result'; 100 var source = '$target-result';
101 var result = null; 101 var result = null;
102 window.on[source].first.then((Event e) { 102 window.on[source].first.then((Event e) {
103 result = json.parse(_getPortSyncEventData(e)); 103 result = JSON.decode(_getPortSyncEventData(e));
104 }); 104 });
105 _dispatchEvent(target, [source, message]); 105 _dispatchEvent(target, [source, message]);
106 return result; 106 return result;
107 } 107 }
108 108
109 bool operator==(var other) { 109 bool operator==(var other) {
110 return (other is _RemoteSendPortSync) && (_isolateId == other._isolateId) 110 return (other is _RemoteSendPortSync) && (_isolateId == other._isolateId)
111 && (_portId == other._portId); 111 && (_portId == other._portId);
112 } 112 }
113 113
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 178
179 static String _getListenerName(isolateId, portId) => 179 static String _getListenerName(isolateId, portId) =>
180 'dart-port-$isolateId-$portId'; 180 'dart-port-$isolateId-$portId';
181 String get _listenerName => _getListenerName(_isolateId, _portId); 181 String get _listenerName => _getListenerName(_isolateId, _portId);
182 182
183 void receive(callback(var message)) { 183 void receive(callback(var message)) {
184 _callback = callback; 184 _callback = callback;
185 if (_portSubscription == null) { 185 if (_portSubscription == null) {
186 _portSubscription = window.on[_listenerName].listen((Event e) { 186 _portSubscription = window.on[_listenerName].listen((Event e) {
187 var data = json.parse(_getPortSyncEventData(e)); 187 var data = JSON.decode(_getPortSyncEventData(e));
188 var replyTo = data[0]; 188 var replyTo = data[0];
189 var message = _deserialize(data[1]); 189 var message = _deserialize(data[1]);
190 var result = _callback(message); 190 var result = _callback(message);
191 _dispatchEvent(replyTo, _serialize(result)); 191 _dispatchEvent(replyTo, _serialize(result));
192 }); 192 });
193 } 193 }
194 } 194 }
195 195
196 void close() { 196 void close() {
197 _portMap.remove(_portId); 197 _portMap.remove(_portId);
(...skipping 10 matching lines...) Expand all
208 } else { 208 } else {
209 return new _RemoteSendPortSync(isolateId, portId); 209 return new _RemoteSendPortSync(isolateId, portId);
210 } 210 }
211 } 211 }
212 } 212 }
213 213
214 get _isolateId => ReceivePortSync._isolateId; 214 get _isolateId => ReceivePortSync._isolateId;
215 215
216 void _dispatchEvent(String receiver, var message) { 216 void _dispatchEvent(String receiver, var message) {
217 var event = new CustomEvent(receiver, canBubble: false, cancelable:false, 217 var event = new CustomEvent(receiver, canBubble: false, cancelable:false,
218 detail: json.stringify(message)); 218 detail: JSON.encode(message));
219 window.dispatchEvent(event); 219 window.dispatchEvent(event);
220 } 220 }
221 221
222 String _getPortSyncEventData(CustomEvent event) => event.detail; 222 String _getPortSyncEventData(CustomEvent event) => event.detail;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698