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 89f139410824c907f28b772ff438896480913901..1e90885dfe9a8e873a6bb60280750d7894085b3d 100644 |
| --- a/tools/dom/src/native_DOMImplementation.dart |
| +++ b/tools/dom/src/native_DOMImplementation.dart |
| @@ -198,31 +198,44 @@ final _pureIsolatePrintClosure = (s) { |
| final _forwardingPrintClosure = _Utils.forwardingPrint; |
| -class _Timer implements Timer { |
| - final canceller; |
| + class _Timer implements Timer { |
|
floitsch
2013/07/02 11:27:19
Remove leading space.
zarah
2013/07/02 11:43:12
Done.
|
| + final _canceler; |
|
floitsch
2013/07/02 11:27:19
Can not be final, since you change it.
zarah
2013/07/02 11:43:12
Done, of course!
|
| + |
| + _Timer(int milliSeconds, void callback(Timer timer), bool repeating) { |
| + |
| + if (repeating) { |
| + int id = window._setInterval(() { |
| + _canceler = null; |
|
floitsch
2013/07/02 11:27:19
No. Don't remove the canceler for repeating timers
zarah
2013/07/02 11:43:12
Done.
|
| + callback(this); |
| + }, milliSeconds);) |
| + _canceler = () => window._clearInterval(id); |
| + } else { |
| + int id = window._setTimeout(() { |
| + _canceler = null; |
| + callback(this); |
| + }, milliSeconds); ) |
| + _canceler = window._clearTimeout(id); |
|
floitsch
2013/07/02 11:27:19
This must be a closure.
zarah
2013/07/02 11:43:12
Done.
|
| + } |
| + } |
| - _Timer(this.canceller); |
| + void cancel() { |
| + if (_canceler != null) { |
| + _canceler(); |
| + } |
| + _canceler = null; |
| + } |
| - void cancel() { canceller(); } |
| + bool get isActive => _canceler != null; |
| } |
| -get _timerFactoryClosure => (int milliSeconds, void callback(Timer timer), bool repeating) { |
| - var maker; |
| - var canceller; |
| - if (repeating) { |
| - maker = window._setInterval; |
| - canceller = window._clearInterval; |
| - } else { |
| - maker = window._setTimeout; |
| - canceller = window._clearTimeout; |
| - } |
| - Timer timer; |
| - final int id = maker(() { callback(timer); }, milliSeconds); |
| - timer = new _Timer(() { canceller(id); }); |
| - return timer; |
| +get _timerFactoryClosure => |
| + (int milliSeconds, void callback(Timer timer), bool repeating) { |
| + return new _Timer(milliseconds, callback, repeating); |
| }; |
| + |
| class _PureIsolateTimer implements Timer { |
| + bool _isDone = false; |
|
floitsch
2013/07/02 11:27:19
Rename _isDone to _isActive
zarah
2013/07/02 11:43:12
Done.
|
| final ReceivePort _port = new ReceivePort(); |
| SendPort _sendPort; // Effectively final. |
| @@ -232,6 +245,7 @@ class _PureIsolateTimer implements Timer { |
| _sendPort = _port.toSendPort(); |
| _port.receive((msg, replyTo) { |
| assert(msg == _TIMER_PING); |
| + _isDone = !repeating; |
| callback(this); |
| if (!repeating) _cancel(); |
| }); |
| @@ -245,12 +259,15 @@ class _PureIsolateTimer implements Timer { |
| } |
| void _cancel() { |
| + _isDone = true; |
| _port.close(); |
| } |
| _send(msg) { |
| _sendToHelperIsolate(msg, _sendPort); |
| } |
| + |
| + bool get isActive => !_isDone; |
| } |
| get _pureIsolateTimerFactoryClosure => |