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

Side by Side Diff: client/dart.js

Issue 10960062: Fix SendPortSync dispatch for FF (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix indentation Created 8 years, 2 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 | lib/html/dart2js/html_dart2js.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) 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 // Bootstrap support for Dart scripts on the page as this script. 5 // Bootstrap support for Dart scripts on the page as this script.
6 if (navigator.webkitStartDart) { 6 if (navigator.webkitStartDart) {
7 if (!navigator.webkitStartDart()) { 7 if (!navigator.webkitStartDart()) {
8 document.body.innerHTML = 'This build has expired. Please download a new Da rtium at http://www.dartlang.org/dartium/index.html'; 8 document.body.innerHTML = 'This build has expired. Please download a new Da rtium at http://www.dartlang.org/dartium/index.html';
9 } 9 }
10 } else { 10 } else {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 ReceivePortSync.prototype.toSendPort = function() { 184 ReceivePortSync.prototype.toSendPort = function() {
185 return new LocalSendPortSync(this); 185 return new LocalSendPortSync(this);
186 }; 186 };
187 187
188 ReceivePortSync.prototype.close = function() { 188 ReceivePortSync.prototype.close = function() {
189 delete ReceivePortSync.map[this.id]; 189 delete ReceivePortSync.map[this.id];
190 }; 190 };
191 191
192 if (navigator.webkitStartDart) { 192 if (navigator.webkitStartDart) {
193 window.addEventListener('js-sync-message', function(event) { 193 window.addEventListener('js-sync-message', function(event) {
194 var data = JSON.parse(event.data); 194 var data = JSON.parse(getPortSyncEventData(event));
195 var deserialized = deserialize(data.message); 195 var deserialized = deserialize(data.message);
196 var result = ReceivePortSync.map[data.id].callback(deserialized); 196 var result = ReceivePortSync.map[data.id].callback(deserialized);
197 // TODO(vsm): Handle and propagate exceptions. 197 // TODO(vsm): Handle and propagate exceptions.
198 dispatchEvent('js-result', serialize(result)); 198 dispatchEvent('js-result', serialize(result));
199 }, false); 199 }, false);
200 } 200 }
201 201
202 function LocalSendPortSync(receivePort) { 202 function LocalSendPortSync(receivePort) {
203 this.receivePort = receivePort; 203 this.receivePort = receivePort;
204 } 204 }
205 205
206 LocalSendPortSync.prototype = new SendPortSync(); 206 LocalSendPortSync.prototype = new SendPortSync();
207 207
208 LocalSendPortSync.prototype.callSync = function(message) { 208 LocalSendPortSync.prototype.callSync = function(message) {
209 // TODO(vsm): Do a direct deepcopy. 209 // TODO(vsm): Do a direct deepcopy.
210 message = deserialize(serialize(message)); 210 message = deserialize(serialize(message));
211 return this.receivePort.callback(message); 211 return this.receivePort.callback(message);
212 } 212 }
213 213
214 function DartSendPortSync(isolateId, portId) { 214 function DartSendPortSync(isolateId, portId) {
215 this.isolateId = isolateId; 215 this.isolateId = isolateId;
216 this.portId = portId; 216 this.portId = portId;
217 } 217 }
218 218
219 DartSendPortSync.prototype = new SendPortSync(); 219 DartSendPortSync.prototype = new SendPortSync();
220 220
221 function dispatchEvent(receiver, message) { 221 function dispatchEvent(receiver, message) {
222 var string = JSON.stringify(message); 222 var string = JSON.stringify(message);
223 var event = document.createEvent('TextEvent'); 223 var event = document.createEvent('CustomEvent');
224 event.initTextEvent(receiver, false, false, window, string); 224 event.initCustomEvent(receiver, false, false, string);
225 window.dispatchEvent(event); 225 window.dispatchEvent(event);
226 } 226 }
227 227
228 function getPortSyncEventData(event) {
229 return event.detail;
230 }
231
228 DartSendPortSync.prototype.callSync = function(message) { 232 DartSendPortSync.prototype.callSync = function(message) {
229 var serialized = serialize(message); 233 var serialized = serialize(message);
230 var target = 'dart-port-' + this.isolateId + '-' + this.portId; 234 var target = 'dart-port-' + this.isolateId + '-' + this.portId;
231 // TODO(vsm): Make this re-entrant. 235 // TODO(vsm): Make this re-entrant.
232 // TODO(vsm): Set this up set once, on the first call. 236 // TODO(vsm): Set this up set once, on the first call.
233 var source = target + '-result'; 237 var source = target + '-result';
234 var result = null; 238 var result = null;
235 var listener = function (e) { 239 var listener = function (e) {
236 result = JSON.parse(e.data); 240 result = JSON.parse(getPortSyncEventData(e));
237 }; 241 };
238 window.addEventListener(source, listener, false); 242 window.addEventListener(source, listener, false);
239 dispatchEvent(target, [source, serialized]); 243 dispatchEvent(target, [source, serialized]);
240 window.removeEventListener(source, listener, false); 244 window.removeEventListener(source, listener, false);
241 return deserialize(result); 245 return deserialize(result);
242 } 246 }
243 })(); 247 })();
OLDNEW
« no previous file with comments | « no previous file | lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698