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 patch class Timer { | 5 patch class Timer { |
6 /*patch*/ static Timer _createTimer(Duration duration, void callback()) { | 6 /*patch*/ static Timer _createTimer(Duration duration, void callback()) { |
| 7 // TODO(iposva): Remove _TimerFactory and use VMLibraryHooks exclusively. |
| 8 if (_TimerFactory._factory == null) { |
| 9 _TimerFactory._factory = VMLibraryHooks.timerFactory; |
| 10 } |
7 if (_TimerFactory._factory == null) { | 11 if (_TimerFactory._factory == null) { |
8 throw new UnsupportedError("Timer interface not supported."); | 12 throw new UnsupportedError("Timer interface not supported."); |
9 } | 13 } |
10 int milliseconds = duration.inMilliseconds; | 14 int milliseconds = duration.inMilliseconds; |
11 if (milliseconds < 0) milliseconds = 0; | 15 if (milliseconds < 0) milliseconds = 0; |
12 return _TimerFactory._factory(milliseconds, (_) { callback(); }, false); | 16 return _TimerFactory._factory(milliseconds, (_) { callback(); }, false); |
13 } | 17 } |
14 | 18 |
15 /*patch*/ static Timer _createPeriodicTimer(Duration duration, | 19 /*patch*/ static Timer _createPeriodicTimer(Duration duration, |
16 void callback(Timer timer)) { | 20 void callback(Timer timer)) { |
| 21 // TODO(iposva): Remove _TimerFactory and use VMLibraryHooks exclusively. |
| 22 if (_TimerFactory._factory == null) { |
| 23 _TimerFactory._factory = VMLibraryHooks.timerFactory; |
| 24 } |
17 if (_TimerFactory._factory == null) { | 25 if (_TimerFactory._factory == null) { |
18 throw new UnsupportedError("Timer interface not supported."); | 26 throw new UnsupportedError("Timer interface not supported."); |
19 } | 27 } |
20 int milliseconds = duration.inMilliseconds; | 28 int milliseconds = duration.inMilliseconds; |
21 if (milliseconds < 0) milliseconds = 0; | 29 if (milliseconds < 0) milliseconds = 0; |
22 return _TimerFactory._factory(milliseconds, callback, true); | 30 return _TimerFactory._factory(milliseconds, callback, true); |
23 } | 31 } |
24 } | 32 } |
25 | 33 |
26 typedef Timer _TimerFactoryClosure(int milliseconds, | 34 typedef Timer _TimerFactoryClosure(int milliseconds, |
27 void callback(Timer timer), | 35 void callback(Timer timer), |
28 bool repeating); | 36 bool repeating); |
29 | 37 |
| 38 // Warning: Dartium sets _TimerFactory._factory instead of setting things up |
| 39 // through VMLibraryHooks.timerFactory. |
30 class _TimerFactory { | 40 class _TimerFactory { |
31 static _TimerFactoryClosure _factory; | 41 static _TimerFactoryClosure _factory; |
32 } | 42 } |
33 | |
34 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets | |
35 // [_TimerFactory._factory] directly. | |
36 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { | |
37 _TimerFactory._factory = closure; | |
38 } | |
OLD | NEW |