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

Side by Side Diff: lib/html/src/Isolates.dart

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 | « lib/html/frog/html_frog.dart ('k') | tests/html/html.status » ('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 // DO NOT EDIT
6 // Auto-generated dart:html library.
7
8 #library('html');
9
10 #import('dart:isolate');
11 #import('dart:json');
12
13 $!GENERATED_DART_FILES
14
15 #source('../../dom/src/EventListener.dart');
16 #source('../../dom/src/KeyLocation.dart');
17 #source('../../dom/src/KeyName.dart');
18 #source('../../dom/src/ReadyState.dart');
19 #source('../../dom/src/_Collections.dart');
20 #source('../../dom/src/_XMLHttpRequestUtils.dart');
21 #source('../../html/src/IDBOpenDBRequest.dart');
22 #source('../../html/src/Measurement.dart');
23 #source('../../html/src/shared_FactoryProviders.dart');
24 #source('../../html/src/frog_DOMImplementation.dart');
25 #source('../../html/src/frog_FactoryProviders.dart');
26 #source('../../html/src/frog_IDBKeyRangeFactoryProvider.dart');
27 #source('../../html/src/frog_IDBOpenDBRequestImplementation.dart');
28 #source('../../html/src/frog_LocationWrapper.dart');
29 #source('../../dom/src/frog_TypedArrayFactoryProvider.dart');
30 #source('../../html/src/_Testing.dart');
31 #source('../../html/src/Device.dart');
32 #source('../../dom/src/_ListIterators.dart');
33 #source('../../dom/src/_Lists.dart');
34 #source('../../isolate/serialization.dart');
35
36
37 Window get window() native "return window;";
38 _WindowImpl get _window() native "return window;";
39
40 Document get document() native "return document;";
41
42 _DocumentImpl get _document() native "return document;";
43
44 Element query(String selector) => _document.query(selector);
45 ElementList queryAll(String selector) => _document.queryAll(selector);
46
47 // Workaround for tags like <cite> that lack their own Element subclass --
48 // Dart issue 1990.
49 class _HTMLElementImpl extends _ElementImpl native "*HTMLElement" {
50 }
51
52 // TODO(vsm): Move this to a separate Isolates.dart file.
53 _serialize(var message) { 5 _serialize(var message) {
54 return new _JsSerializer().traverse(message); 6 return new _JsSerializer().traverse(message);
55 } 7 }
56 8
57 class _JsSerializer extends _Serializer { 9 class _JsSerializer extends _Serializer {
58 10
59 visitSendPortSync(SendPortSync x) { 11 visitSendPortSync(SendPortSync x) {
60 if (x is _JsSendPortSync) return visitJsSendPortSync(x); 12 if (x is _JsSendPortSync) return visitJsSendPortSync(x);
61 if (x is _LocalSendPortSync) return visitLocalSendPortSync(x); 13 if (x is _LocalSendPortSync) return visitLocalSendPortSync(x);
62 if (x is _RemoteSendPortSync) return visitRemoteSendPortSync(x); 14 if (x is _RemoteSendPortSync) return visitRemoteSendPortSync(x);
63 throw "Illegal underlying port $x"; 15 throw "Illegal underlying port $x";
64 } 16 }
65 17
66 visitJsSendPortSync(_JsSendPortSync x) { 18 visitJsSendPortSync(_JsSendPortSync x) {
67 return [ 'sendport', 'nativejs', x._id ]; 19 return [ 'sendport', 'nativejs', x._id ];
68 } 20 }
69 21
70 visitLocalSendPortSync(_LocalSendPortSync x) { 22 visitLocalSendPortSync(_LocalSendPortSync x) {
71 return [ 'sendport', 'dart2js', 23 return [ 'sendport', 'dart',
72 ReceivePortSync._isolateId, x._receivePort._portId ]; 24 ReceivePortSync._isolateId, x._receivePort._portId ];
73 } 25 }
74 26
75 visitRemoteSendPortSync(_RemoteSendPortSync x) { 27 visitRemoteSendPortSync(_RemoteSendPortSync x) {
76 return [ 'sendport', 'dart2js', 28 return [ 'sendport', 'dart',
77 x._receivePort._isolateId, x._receivePort._portId ]; 29 x._receivePort._isolateId, x._receivePort._portId ];
78 } 30 }
79 } 31 }
80 32
81 _deserialize(var message) { 33 _deserialize(var message) {
82 return new _JsDeserializer().deserialize(message); 34 return new _JsDeserializer().deserialize(message);
83 } 35 }
84 36
85 class _JsDeserializer extends _Deserializer { 37 class _JsDeserializer extends _Deserializer {
86 38
87 deserializeSendPort(List x) { 39 deserializeSendPort(List x) {
88 String tag = x[1]; 40 String tag = x[1];
89 switch (tag) { 41 switch (tag) {
90 case 'nativejs': 42 case 'nativejs':
91 num id = x[2]; 43 num id = x[2];
92 return new _JsSendPortSync(id); 44 return new _JsSendPortSync(id);
93 case 'dart2js': 45 case 'dart':
94 num isolateId = x[2]; 46 num isolateId = x[2];
95 num portId = x[3]; 47 num portId = x[3];
96 return ReceivePortSync._lookup(isolateId, portId); 48 return ReceivePortSync._lookup(isolateId, portId);
97 default: 49 default:
98 throw 'Illegal SendPortSync type: $tag'; 50 throw 'Illegal SendPortSync type: $tag';
99 } 51 }
100 } 52 }
101 53
102 } 54 }
103 55
104 // The receiver is JS. 56 // The receiver is JS.
105 class _JsSendPortSync implements SendPortSync { 57 class _JsSendPortSync implements SendPortSync {
106 58
107 num _id; 59 num _id;
108 _JsSendPortSync(this._id); 60 _JsSendPortSync(this._id);
109 61
110 callSync(var message) { 62 callSync(var message) {
111 var serialized = _serialize(message); 63 var serialized = _serialize(message);
112 var result = 64 var result = _callPortSync(_id, serialized);
113 JS('var', @'ReceivePortSync.dispatchCall(#, #)', _id, serialized);
114 return _deserialize(result); 65 return _deserialize(result);
115 } 66 }
116 67
117 } 68 }
118 69
119 // TODO(vsm): Handle Dartium isolates. 70 // TODO(vsm): Differentiate between Dart2Js and Dartium isolates.
120 // The receiver is a different Dart isolate, compiled to JS. 71 // The receiver is a different Dart isolate, compiled to JS.
121 class _RemoteSendPortSync implements SendPortSync { 72 class _RemoteSendPortSync implements SendPortSync {
122 73
123 int _isolateId; 74 int _isolateId;
124 int _portId; 75 int _portId;
125 _RemoteSendPortSync(this._isolateId, this._portId); 76 _RemoteSendPortSync(this._isolateId, this._portId);
126 77
127 callSync(var message) { 78 callSync(var message) {
128 var serialized = _serialize(message); 79 var serialized = _serialize(message);
129 var result = _call(_isolateId, _portId, serialized); 80 var result = _call(_isolateId, _portId, serialized);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 112 }
162 } 113 }
163 114
164 // TODO(vsm): Move this to dart:isolate. This will take some 115 // TODO(vsm): Move this to dart:isolate. This will take some
165 // refactoring as there are dependences here on the DOM. Users 116 // refactoring as there are dependences here on the DOM. Users
166 // interact with this class (or interface if we change it) directly - 117 // interact with this class (or interface if we change it) directly -
167 // new ReceivePortSync. I think most of the DOM logic could be 118 // new ReceivePortSync. I think most of the DOM logic could be
168 // delayed until the corresponding SendPort is registered on the 119 // delayed until the corresponding SendPort is registered on the
169 // window. 120 // window.
170 121
171 // A Dart2JS ReceivePortSync (tagged 'dart2js' when serialized) is 122 // A Dart ReceivePortSync (tagged 'dart' when serialized) is
172 // identifiable / resolvable by the combination of its isolateid and 123 // identifiable / resolvable by the combination of its isolateid and
173 // portid. When a corresponding SendPort is used within the same 124 // portid. When a corresponding SendPort is used within the same
174 // isolate, the _portMap below can be used to obtain the 125 // isolate, the _portMap below can be used to obtain the
175 // ReceivePortSync directly. Across isolates (or from JS), an 126 // ReceivePortSync directly. Across isolates (or from JS), an
176 // EventListener can be used to communicate with the port indirectly. 127 // EventListener can be used to communicate with the port indirectly.
177 class ReceivePortSync { 128 class ReceivePortSync {
178 129
179 static Map<int, ReceivePortSync> _portMap; 130 static Map<int, ReceivePortSync> _portMap;
180 static int _portIdCount; 131 static int _portIdCount;
181 static int _cachedIsolateId; 132 static int _cachedIsolateId;
(...skipping 12 matching lines...) Expand all
194 } 145 }
195 146
196 static int get _isolateId() { 147 static int get _isolateId() {
197 // TODO(vsm): Make this coherent with existing isolate code. 148 // TODO(vsm): Make this coherent with existing isolate code.
198 if (_cachedIsolateId == null) { 149 if (_cachedIsolateId == null) {
199 _cachedIsolateId = _getNewIsolateId(); 150 _cachedIsolateId = _getNewIsolateId();
200 } 151 }
201 return _cachedIsolateId; 152 return _cachedIsolateId;
202 } 153 }
203 154
204 static int _getNewIsolateId() native @'''
205 if (!window.$dart$isolate$counter) {
206 window.$dart$isolate$counter = 1;
207 }
208 return window.$dart$isolate$counter++;
209 ''';
210
211 static String _getListenerName(isolateId, portId) => 155 static String _getListenerName(isolateId, portId) =>
212 'dart-port-$isolateId-$portId'; 156 'dart-port-$isolateId-$portId';
213 String get _listenerName() => _getListenerName(_isolateId, _portId); 157 String get _listenerName() => _getListenerName(_isolateId, _portId);
214 158
215 void receive(callback(var message)) { 159 void receive(callback(var message)) {
216 // Clear old listener. 160 // Clear old listener.
217 if (_callback != null) { 161 if (_callback != null) {
218 window.on[_listenerName].remove(_listener); 162 window.on[_listenerName].remove(_listener);
219 } 163 }
220 164
(...skipping 27 matching lines...) Expand all
248 return new _RemoteSendPortSync(isolateId, portId); 192 return new _RemoteSendPortSync(isolateId, portId);
249 } 193 }
250 } 194 }
251 } 195 }
252 196
253 void _dispatchEvent(String receiver, var message) { 197 void _dispatchEvent(String receiver, var message) {
254 var event = document.$dom_createEvent('TextEvent'); 198 var event = document.$dom_createEvent('TextEvent');
255 event.initTextEvent(receiver, false, false, window, JSON.stringify(message)); 199 event.initTextEvent(receiver, false, false, window, JSON.stringify(message));
256 window.$dom_dispatchEvent(event); 200 window.$dom_dispatchEvent(event);
257 } 201 }
OLDNEW
« no previous file with comments | « lib/html/frog/html_frog.dart ('k') | tests/html/html.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698