Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/lib/async_patch.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart b/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart |
| index 0fccce2a432b6eb93bf2af79f0d317545e165f69..e41ea86247ad7055e735c1c09987f64dc918d6e1 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/lib/async_patch.dart |
| @@ -6,16 +6,40 @@ |
| import 'dart:_isolate_helper' show TimerImpl; |
| +typedef void _TimerCallback0(); |
| +typedef void _TimerCallback1(Timer timer); |
| + |
| patch class Timer { |
| - patch factory Timer(int milliseconds, void callback(Timer timer)) { |
| - return new TimerImpl(milliseconds, callback); |
| + patch factory Timer(var duration, var callback) { |
| + // TODO(floitsch): remove these checks when we remove the deprecated |
| + // millisecond argument and the 1-argument callback. |
| + if (callback is! _TimerCallback0 && callback is! _TimerCallback1) { |
| + throw new ArgumentError(callback); |
| + } |
| + if (duration is! Duration && duration is! int) { |
| + throw new ArgumentError(duration); |
| + } |
| + int milliseconds = duration is int ? duration : duration.inMilliseconds; |
| + if (milliseconds < 0) milliseconds = 0; |
| + Timer timer; |
| + _TimerCallback0 zeroArgumentCallback = |
| + callback is _TimerCallback0 ? callback : () => callback(timer); |
|
Lasse Reichstein Nielsen
2013/02/11 13:01:21
Per VM patch file: this is duplicated code. Try to
floitsch
2013/02/11 19:21:32
Same issue.
|
| + timer = new TimerImpl(milliseconds, zeroArgumentCallback); |
| + return timer; |
| } |
| /** |
| * Creates a new repeating timer. The [callback] is invoked every |
| * [milliseconds] millisecond until cancelled. |
| */ |
| - patch factory Timer.repeating(int milliseconds, void callback(Timer timer)) { |
| + patch factory Timer.repeating(var duration, void callback(Timer timer)) { |
| + // TODO(floitsch): remove this check when we remove the deprecated |
| + // millisecond argument. |
| + if (duration is! Duration && duration is! int) { |
| + throw new ArgumentError(duration); |
| + } |
| + int milliseconds = duration is int ? duration : duration.inMilliseconds; |
| + if (milliseconds < 0) milliseconds = 0; |
| return new TimerImpl.repeating(milliseconds, callback); |
| } |
| } |