Chromium Code Reviews| Index: tools/dom/src/native_DOMImplementation.dart |
| diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart |
| index e54cc11752fab6f3ffdae5ef74a1b89207ac1e94..7f68ea5caa440bb2fe7f6f806d2b3f163a94e4ab 100644 |
| --- a/tools/dom/src/native_DOMImplementation.dart |
| +++ b/tools/dom/src/native_DOMImplementation.dart |
| @@ -530,33 +530,36 @@ final _pureIsolateUriBaseClosure = () { |
| "is not supported in the browser"); |
| }; |
| - class _Timer implements Timer { |
| - var _canceler; |
| +class _Timer implements Timer { |
| + const int _STATE_TIMEOUT = 0; |
| + const int _STATE_INTERVAL = 1; |
| + var _state; |
|
floitsch
2013/12/06 14:11:23
type as "int", and explain how it is used.
|
| _Timer(int milliSeconds, void callback(Timer timer), bool repeating) { |
| - |
| if (repeating) { |
| - int id = window._setInterval(() { |
| + _state = window._setInterval(() { |
| callback(this); |
| - }, milliSeconds); |
| - _canceler = () => window._clearInterval(id); |
| + }), milliSeconds) * 2 + _STATE_INTERVAL; |
|
floitsch
2013/12/06 14:11:23
I'm surprised we typed the "id" as integer.
All th
floitsch
2013/12/06 14:13:23
Hmm. Since no JS implementation guarantees the ran
Lasse Reichstein Nielsen
2013/12/09 10:17:26
That was my thought too. I think it may always be
|
| } else { |
| - int id = window._setTimeout(() { |
| - _canceler = null; |
| + _state = window._setTimeout(() { |
| + _state = null; |
| callback(this); |
| - }, milliSeconds); |
| - _canceler = () => window._clearTimeout(id); |
| + }), milliSeconds) * 2 + _STATE_TIMEOUT; |
| } |
| } |
| void cancel() { |
| - if (_canceler != null) { |
| - _canceler(); |
| + if (_state == null) return; |
| + int id = state ~/ 2; |
|
floitsch
2013/12/06 14:11:23
ditto.
|
| + if ((_state & 1) == _STATE_TIMEOUT) { |
| + window._clearTimeout(id); |
| + } else { |
| + window._clearInterval(id); |
| } |
| - _canceler = null; |
| + _state = null; |
| } |
| - bool get isActive => _canceler != null; |
| + bool get isActive => _state != null; |
| } |
| get _timerFactoryClosure => |