| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 |
| 6 // We don't want to import the DOM library just because of window.setTimeout, |
| 7 // so we reconstruct the Window class here. The only conflict that could happen |
| 8 // with the other DOMWindow class would be because of subclasses. |
| 9 // Currently, none of the two Dart classes have subclasses. |
| 10 typedef void _TimeoutHandler(); |
| 11 |
| 12 class _Window native "@*DOMWindow" { |
| 13 int setTimeout(_TimeoutHandler handler, int timeout) native; |
| 14 int setInterval(_TimeoutHandler handler, int timeout) native; |
| 15 } |
| 16 |
| 17 _Window get _window() => |
| 18 JS('bool', 'typeof window != "undefined"') ? JS('_Window', 'window') : null; |
| 19 |
| 20 class _Timer implements Timer { |
| 21 final bool _once; |
| 22 int _handle; |
| 23 |
| 24 _Timer(int milliSeconds, void callback(Timer timer)) |
| 25 : _once = true { |
| 26 _handle = _window.setTimeout(() => callback(this), milliSeconds); |
| 27 } |
| 28 |
| 29 _Timer.repeating(int milliSeconds, void callback(Timer timer)) |
| 30 : _once = false { |
| 31 _handle = _window.setInterval(() => callback(this), milliSeconds); |
| 32 } |
| 33 |
| 34 void cancel() { |
| 35 if (_once) { |
| 36 _window.clearTimeout(_handle); |
| 37 } else { |
| 38 _window.clearInterval(_handle); |
| 39 } |
| 40 } |
| 41 } |
| 42 |
| 43 Timer _timerFactory(int millis, void callback(Timer timer), bool repeating) => |
| 44 repeating ? new _Timer.repeating(millis, callback) |
| 45 : new _Timer(millis, callback); |
| OLD | NEW |