| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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() { |
| 266 // [_window] is defined in timer_provider.dart. |
| 277 if (_window != null) { | 267 if (_window != null) { |
| 278 // Run each iteration from the browser's top event loop. | 268 // Run each iteration from the browser's top event loop. |
| 279 void next() { | 269 void next() { |
| 280 if (!runIteration()) return; | 270 if (!runIteration()) return; |
| 281 _window.setTimeout(next, 0); | 271 _window.setTimeout(next, 0); |
| 282 } | 272 } |
| 283 next(); | 273 next(); |
| 284 } else { | 274 } else { |
| 285 // Run synchronously until no more iterations are available. | 275 // Run synchronously until no more iterations are available. |
| 286 while (runIteration()) {} | 276 while (runIteration()) {} |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 'command': 'start', | 536 'command': 'start', |
| 547 'id': workerId, | 537 'id': workerId, |
| 548 // Note: we serialize replyPort twice because the child worker needs to | 538 // Note: we serialize replyPort twice because the child worker needs to |
| 549 // first deserialize the worker id, before it can correctly deserialize | 539 // first deserialize the worker id, before it can correctly deserialize |
| 550 // the port (port deserialization is sensitive to what is the current | 540 // the port (port deserialization is sensitive to what is the current |
| 551 // workerId). | 541 // workerId). |
| 552 'replyTo': _serializeMessage(replyPort), | 542 'replyTo': _serializeMessage(replyPort), |
| 553 'functionName': functionName })); | 543 'functionName': functionName })); |
| 554 } | 544 } |
| 555 } | 545 } |
| OLD | NEW |