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

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

Issue 10830230: Add Timer implementation for dart2js. Also moves tests to appropriate location. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 * Concepts used here: 6 * Concepts used here:
7 * 7 *
8 * "manager" - A manager contains one or more isolates, schedules their 8 * "manager" - A manager contains one or more isolates, schedules their
9 * execution, and performs other plumbing on their behalf. The isolate 9 * execution, and performs other plumbing on their behalf. The isolate
10 * present at the creation of the manager is designated as its "root isolate". 10 * present at the creation of the manager is designated as its "root isolate".
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 /** Unregister a port on this isolate. */ 211 /** Unregister a port on this isolate. */
212 void unregister(int portId) { 212 void unregister(int portId) {
213 ports.remove(portId); 213 ports.remove(portId);
214 if (ports.isEmpty()) { 214 if (ports.isEmpty()) {
215 _globalState.isolates.remove(id); // indicate this isolate is not active 215 _globalState.isolates.remove(id); // indicate this isolate is not active
216 } 216 }
217 } 217 }
218 } 218 }
219 219
220 // We don't want to import the DOM library just because of window.setTimeout,
221 // so we reconstruct the Window class here. The only conflict that could happen
222 // with the other DOMWindow class would be because of subclasses.
223 // Currently, none of the two Dart classes have subclasses.
224 typedef void _TimeoutHandler();
225 class _Window native "@*DOMWindow" {
226 int setTimeout(_TimeoutHandler handler, int timeout) native;
227 }
228 _Window get _window() native
229 """return typeof window != 'undefined' ? window : (void 0);""";
230
231 /** Represent the event loop on a javascript thread (DOM or worker). */ 220 /** Represent the event loop on a javascript thread (DOM or worker). */
232 class _EventLoop { 221 class _EventLoop {
233 Queue<_IsolateEvent> events; 222 Queue<_IsolateEvent> events;
234 223
235 _EventLoop() : events = new Queue<_IsolateEvent>(); 224 _EventLoop() : events = new Queue<_IsolateEvent>();
236 225
237 void enqueue(isolate, fn, msg) { 226 void enqueue(isolate, fn, msg) {
238 events.addLast(new _IsolateEvent(isolate, fn, msg)); 227 events.addLast(new _IsolateEvent(isolate, fn, msg));
239 } 228 }
240 229
(...skipping 26 matching lines...) Expand all
267 } 256 }
268 event.process(); 257 event.process();
269 return true; 258 return true;
270 } 259 }
271 260
272 /** 261 /**
273 * Runs multiple iterations of the run-loop. If possible, each iteration is 262 * Runs multiple iterations of the run-loop. If possible, each iteration is
274 * run asynchronously. 263 * run asynchronously.
275 */ 264 */
276 void _runHelper() { 265 void _runHelper() {
277 if (_window != null) { 266 if (_window != null) { // (defined in timer_provider.dart)
kasperl 2012/08/09 06:15:33 Turn comment into a proper sentence and mention th
Siggi Cherem (dart-lang) 2012/08/09 20:37:14 Done.
278 // Run each iteration from the browser's top event loop. 267 // Run each iteration from the browser's top event loop.
279 void next() { 268 void next() {
280 if (!runIteration()) return; 269 if (!runIteration()) return;
281 _window.setTimeout(next, 0); 270 _window.setTimeout(next, 0);
282 } 271 }
283 next(); 272 next();
284 } else { 273 } else {
285 // Run synchronously until no more iterations are available. 274 // Run synchronously until no more iterations are available.
286 while (runIteration()) {} 275 while (runIteration()) {}
287 } 276 }
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 'command': 'start', 535 'command': 'start',
547 'id': workerId, 536 'id': workerId,
548 // Note: we serialize replyPort twice because the child worker needs to 537 // Note: we serialize replyPort twice because the child worker needs to
549 // first deserialize the worker id, before it can correctly deserialize 538 // first deserialize the worker id, before it can correctly deserialize
550 // the port (port deserialization is sensitive to what is the current 539 // the port (port deserialization is sensitive to what is the current
551 // workerId). 540 // workerId).
552 'replyTo': _serializeMessage(replyPort), 541 'replyTo': _serializeMessage(replyPort),
553 'functionName': functionName })); 542 'functionName': functionName }));
554 } 543 }
555 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698