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

Side by Side Diff: lib/isolate/frog/isolateimpl.dart

Issue 9677019: Enable isolate tests with leg and legium. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 /** 5 /**
6 * A native object that is shared across isolates. This object is visible to all 6 * A native object that is shared across isolates. This object is visible to all
7 * isolates running on the same worker (either UI or background web worker). 7 * isolates running on the same worker (either UI or background web worker).
8 * 8 *
9 * This is code that is intended to 'escape' the isolate boundaries in order to 9 * This is code that is intended to 'escape' the isolate boundaries in order to
10 * implement the semantics of isolates in JavaScript. Without this we would have 10 * implement the semantics of isolates in JavaScript. Without this we would have
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 /** Unregister a port on this isolate. */ 191 /** Unregister a port on this isolate. */
192 void unregister(int portId) { 192 void unregister(int portId) {
193 ports.remove(portId); 193 ports.remove(portId);
194 if (ports.isEmpty()) { 194 if (ports.isEmpty()) {
195 _globalState.isolates.remove(id); // indicate this isolate is not active 195 _globalState.isolates.remove(id); // indicate this isolate is not active
196 } 196 }
197 } 197 }
198 } 198 }
199 199
200 // We don't want to import the DOM library just because of window.setTimeout,
201 // so we reconstruct the Window class here. The only conflict that could happen
202 // with the other DOMWindow class would be because of subclasses.
203 // Currently, none of the two Dart classes have subclasses.
ngeoffray 2012/03/12 23:18:36 This is more of a cleanup than a hack IMO. Siggi,
Siggi Cherem (dart-lang) 2012/03/12 23:40:58 looks good to me. I'm working on adding Timer to c
ngeoffray 2012/03/13 12:51:37 Sounds good.
Siggi Cherem (dart-lang) 2012/03/14 23:23:12 It would be supported standalone in the VM, but no
ngeoffray 2012/03/15 09:30:56 Oh I see. So I guess you want to throw a runtime e
204 typedef void _TimeoutHandler();
205 class _Window native "@*DOMWindow" {
206 int setTimeout(_TimeoutHandler handler, int timeout) native;
Siggi Cherem (dart-lang) 2012/03/12 23:40:58 is this _TimeoutHandler needed, or can we simply d
ngeoffray 2012/03/13 12:51:37 Leg does not handle function type parameters very
Siggi Cherem (dart-lang) 2012/03/14 23:23:12 good to know. Thx.
207 }
208 _Window get _window() native
209 """return typeof window != 'undefined' ? window : (void 0);""";
200 210
201 /** Represent the event loop on a javascript thread (DOM or worker). */ 211 /** Represent the event loop on a javascript thread (DOM or worker). */
202 class _EventLoop { 212 class _EventLoop {
203 Queue<_IsolateEvent> events; 213 Queue<_IsolateEvent> events;
204 214
205 _EventLoop() : events = new Queue<_IsolateEvent>(); 215 _EventLoop() : events = new Queue<_IsolateEvent>();
206 216
207 void enqueue(isolate, fn, msg) { 217 void enqueue(isolate, fn, msg) {
208 events.addLast(new _IsolateEvent(isolate, fn, msg)); 218 events.addLast(new _IsolateEvent(isolate, fn, msg));
209 } 219 }
210 220
211 _IsolateEvent dequeue() { 221 _IsolateEvent dequeue() {
212 if (events.isEmpty()) return null; 222 if (events.isEmpty()) return null;
213 return events.removeFirst(); 223 return events.removeFirst();
214 } 224 }
215 225
216 /** Process a single event, if any. */ 226 /** Process a single event, if any. */
217 bool runIteration() { 227 bool runIteration() {
218 final event = dequeue(); 228 final event = dequeue();
219 if (event == null) { 229 if (event == null) {
220 _globalState.closeWorker(); 230 _globalState.closeWorker();
221 return false; 231 return false;
222 } 232 }
223 event.process(); 233 event.process();
224 return true; 234 return true;
225 } 235 }
226 236
227 /** Function equivalent to [:window.setTimeout:] when available, or null. */
228 static Function _wrapSetTimeout() native """
229 return typeof window != 'undefined' ?
230 function(a, b) { window.setTimeout(a, b); } : undefined;
231 """;
232
233 /** 237 /**
234 * Runs multiple iterations of the run-loop. If possible, each iteration is 238 * Runs multiple iterations of the run-loop. If possible, each iteration is
235 * run asynchronously. 239 * run asynchronously.
236 */ 240 */
237 void _runHelper() { 241 void _runHelper() {
238 final setTimeout = _wrapSetTimeout(); 242 if (_window != null) {
239 if (setTimeout != null) {
240 // Run each iteration from the browser's top event loop. 243 // Run each iteration from the browser's top event loop.
241 void next() { 244 void next() {
242 if (!runIteration()) return; 245 if (!runIteration()) return;
243 setTimeout(next, 0); 246 _window.setTimeout(next, 0);
244 } 247 }
245 next(); 248 next();
246 } else { 249 } else {
247 // Run synchronously until no more iterations are available. 250 // Run synchronously until no more iterations are available.
248 while (runIteration()) {} 251 while (runIteration()) {}
249 } 252 }
250 } 253 }
251 254
252 /** 255 /**
253 * Call [_runHelper] but ensure that worker exceptions are propragated. Note 256 * Call [_runHelper] but ensure that worker exceptions are propragated. Note
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 'command': 'start2', 632 'command': 'start2',
630 'id': workerId, 633 'id': workerId,
631 // Note: we serialize replyPort twice because the child worker needs to 634 // Note: we serialize replyPort twice because the child worker needs to
632 // first deserialize the worker id, before it can correctly deserialize 635 // first deserialize the worker id, before it can correctly deserialize
633 // the port (port deserialization is sensitive to what is the current 636 // the port (port deserialization is sensitive to what is the current
634 // workerId). 637 // workerId).
635 'replyTo': _serializeMessage(replyPort), 638 'replyTo': _serializeMessage(replyPort),
636 'functionName': functionName })); 639 'functionName': functionName }));
637 } 640 }
638 } 641 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698