| 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 part of html; | 5 part of html; |
| 6 | 6 |
| 7 typedef void _MicrotaskCallback(); | 7 typedef void _MicrotaskCallback(); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * This class attempts to invoke a callback as soon as the current event stack | 10 * This class attempts to invoke a callback as soon as the current event stack |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 _nextMicrotaskFrameScheduled = false; | 55 _nextMicrotaskFrameScheduled = false; |
| 56 this._callback(); | 56 this._callback(); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Scheduler which uses window.postMessage to schedule events. | 61 * Scheduler which uses window.postMessage to schedule events. |
| 62 */ | 62 */ |
| 63 class _PostMessageScheduler extends _MicrotaskScheduler { | 63 class _PostMessageScheduler extends _MicrotaskScheduler { |
| 64 const _MICROTASK_MESSAGE = "DART-MICROTASK"; | 64 final _MICROTASK_MESSAGE = "DART-MICROTASK"; |
| 65 | 65 |
| 66 _PostMessageScheduler(_MicrotaskCallback callback): super(callback) { | 66 _PostMessageScheduler(_MicrotaskCallback callback): super(callback) { |
| 67 // Messages from other windows do not cause a security risk as | 67 // Messages from other windows do not cause a security risk as |
| 68 // all we care about is that _handleMessage is called | 68 // all we care about is that _handleMessage is called |
| 69 // after the current event loop is unwound and calling the function is | 69 // after the current event loop is unwound and calling the function is |
| 70 // a noop when zero requests are pending. | 70 // a noop when zero requests are pending. |
| 71 window.onMessage.listen(this._handleMessage); | 71 window.onMessage.listen(this._handleMessage); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void _schedule() { | 74 void _schedule() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 /** | 147 /** |
| 148 * Complete all pending microtasks. | 148 * Complete all pending microtasks. |
| 149 */ | 149 */ |
| 150 void _completeMicrotasks() { | 150 void _completeMicrotasks() { |
| 151 var callbacks = _pendingMicrotasks; | 151 var callbacks = _pendingMicrotasks; |
| 152 _pendingMicrotasks = null; | 152 _pendingMicrotasks = null; |
| 153 for (var callback in callbacks) { | 153 for (var callback in callbacks) { |
| 154 callback(); | 154 callback(); |
| 155 } | 155 } |
| 156 } | 156 } |
| OLD | NEW |