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

Side by Side Diff: client/dart.js

Issue 10702110: Added Dartium support for JS to Dart PortSync calls (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed tabbing Created 8 years, 5 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/dom/templates/html/dartium/html_dartium.darttemplate » ('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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 (function() { 48 (function() {
49 function serialize(message) { 49 function serialize(message) {
50 if (message == null) { 50 if (message == null) {
51 return null; // Convert undefined to null. 51 return null; // Convert undefined to null.
52 } else if (typeof(message) == 'string' || 52 } else if (typeof(message) == 'string' ||
53 typeof(message) == 'number' || 53 typeof(message) == 'number' ||
54 typeof(message) == 'boolean') { 54 typeof(message) == 'boolean') {
55 return message; 55 return message;
56 } else if (message instanceof LocalSendPortSync) { 56 } else if (message instanceof LocalSendPortSync) {
57 return [ 'sendport', 'nativejs', message.receivePort.id ]; 57 return [ 'sendport', 'nativejs', message.receivePort.id ];
58 } else if (message instanceof Dart2JsSendPortSync) { 58 } else if (message instanceof DartSendPortSync) {
59 return [ 'sendport', 'dart2js', message.receivePort.isolateId, 59 return [ 'sendport', 'dart', message.receivePort.isolateId,
60 message.receivePort.portId ]; 60 message.receivePort.portId ];
61 } else { 61 } else {
62 var id = 0; 62 var id = 0;
63 var keys = Object.getOwnPropertyNames(message); 63 var keys = Object.getOwnPropertyNames(message);
64 var values = new Array(keys.length); 64 var values = new Array(keys.length);
65 for (var i = 0; i < keys.length; i++) { 65 for (var i = 0; i < keys.length; i++) {
66 values[i] = message[keys[i]]; 66 values[i] = message[keys[i]];
67 } 67 }
68 return [ 'map', id, keys, values ]; 68 return [ 'map', id, keys, values ];
69 } 69 }
(...skipping 29 matching lines...) Expand all
99 } 99 }
100 return result; 100 return result;
101 } 101 }
102 102
103 function deserializeSendPort(x) { 103 function deserializeSendPort(x) {
104 var tag = x[1]; 104 var tag = x[1];
105 switch (tag) { 105 switch (tag) {
106 case 'nativejs': 106 case 'nativejs':
107 var id = x[2]; 107 var id = x[2];
108 return new LocalSendPortSync(id); 108 return new LocalSendPortSync(id);
109 case 'dart2js': 109 case 'dart':
110 var isolateId = x[2]; 110 var isolateId = x[2];
111 var portId = x[3]; 111 var portId = x[3];
112 return new Dart2JsSendPortSync(isolateId, portId); 112 return new DartSendPortSync(isolateId, portId);
113 default: 113 default:
114 throw 'Illegal SendPortSync type: $tag'; 114 throw 'Illegal SendPortSync type: $tag';
115 } 115 }
116 } 116 }
117 117
118 window.registerPort = function(name, port) { 118 window.registerPort = function(name, port) {
119 var stringified = JSON.stringify(serialize(port)); 119 var stringified = JSON.stringify(serialize(port));
120 window.localStorage['dart-port:' + name] = stringified; 120 window.localStorage['dart-port:' + name] = stringified;
121 }; 121 };
122 122
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 LocalSendPortSync.prototype = new SendPortSync(); 164 LocalSendPortSync.prototype = new SendPortSync();
165 165
166 LocalSendPortSync.prototype.callSync = function(message) { 166 LocalSendPortSync.prototype.callSync = function(message) {
167 // TODO(vsm): Do a direct deepcopy. 167 // TODO(vsm): Do a direct deepcopy.
168 message = deserialize(serialize(message)); 168 message = deserialize(serialize(message));
169 return this.receivePort.callback(message); 169 return this.receivePort.callback(message);
170 } 170 }
171 171
172 function Dart2JsSendPortSync(isolateId, portId) { 172 function DartSendPortSync(isolateId, portId) {
173 this.isolateId = isolateId; 173 this.isolateId = isolateId;
174 this.portId = portId; 174 this.portId = portId;
175 } 175 }
176 176
177 Dart2JsSendPortSync.prototype = new SendPortSync(); 177 DartSendPortSync.prototype = new SendPortSync();
178 178
179 function dispatchEvent(receiver, message) { 179 function dispatchEvent(receiver, message) {
180 var string = JSON.stringify(message); 180 var string = JSON.stringify(message);
181 var event = document.createEvent('TextEvent'); 181 var event = document.createEvent('TextEvent');
182 event.initTextEvent(receiver, false, false, window, string); 182 event.initTextEvent(receiver, false, false, window, string);
183 window.dispatchEvent(event); 183 window.dispatchEvent(event);
184 } 184 }
185 185
186 Dart2JsSendPortSync.prototype.callSync = function(message) { 186 DartSendPortSync.prototype.callSync = function(message) {
187 var serialized = serialize(message); 187 var serialized = serialize(message);
188 var target = 'dart-port-' + this.isolateId + '-' + this.portId; 188 var target = 'dart-port-' + this.isolateId + '-' + this.portId;
189 // TODO(vsm): Make this re-entrant. 189 // TODO(vsm): Make this re-entrant.
190 // TODO(vsm): Set this up set once, on the first call. 190 // TODO(vsm): Set this up set once, on the first call.
191 var source = target + '-result'; 191 var source = target + '-result';
192 var result = null; 192 var result = null;
193 var listener = function (e) { 193 var listener = function (e) {
194 result = JSON.parse(e.data); 194 result = JSON.parse(e.data);
195 }; 195 };
196 window.addEventListener(source, listener, false); 196 window.addEventListener(source, listener, false);
197 dispatchEvent(target, [source, serialized]); 197 dispatchEvent(target, [source, serialized]);
198 window.removeEventListener(source, listener, false); 198 window.removeEventListener(source, listener, false);
199 return deserialize(result); 199 return deserialize(result);
200 } 200 }
201 })(); 201 })();
OLDNEW
« no previous file with comments | « no previous file | lib/dom/templates/html/dartium/html_dartium.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698