Chromium Code Reviews| 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() native | |
|
kasperl
2012/08/09 06:15:33
Could this be using the JS helper rather than bein
Siggi Cherem (dart-lang)
2012/08/09 20:37:14
Done.
| |
| 18 "return typeof window != 'undefined' ? window : (void 0);"; | |
| 19 | |
| 20 class _Timer implements Timer { | |
| 21 bool _once; | |
|
kasperl
2012/08/09 06:15:33
It seems perfectly possible to make both fields fi
Siggi Cherem (dart-lang)
2012/08/09 20:37:14
Done for '_once'.
Can't do it for _handle, though
| |
| 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 if (repeating) { | |
|
kasperl
2012/08/09 06:15:33
Maybe use ?:.
Siggi Cherem (dart-lang)
2012/08/09 20:37:14
Done.
| |
| 45 return new _Timer.repeating(millis, callback); | |
| 46 } else { | |
| 47 return new _Timer(millis, callback); | |
| 48 } | |
| 49 } | |
| OLD | NEW |