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 0e62774be0ed0d408bb5ab3d7e8469e2598e44a8..aeb37756aeda201ee250c9a6f233856c739120c4 100644 |
| --- a/tools/dom/src/native_DOMImplementation.dart |
| +++ b/tools/dom/src/native_DOMImplementation.dart |
| @@ -188,3 +188,62 @@ final _pureIsolatePrintClosure = (s) { |
| }; |
| final _forwardingPrintClosure = _Utils.forwardingPrint; |
| + |
| +class _Timer implements Timer { |
| + final canceller; |
| + |
| + _Timer(this.canceller); |
| + |
| + void cancel() { canceller(); } |
| +} |
| + |
| +get _timerFactoryClosure => (int milliSeconds, void callback(Timer timer), bool repeating) { |
|
vsm
2013/04/04 13:41:49
nit length
|
| + 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; |
| +}; |
| + |
| +class _PureIsolateTimer implements Timer { |
| + final ReceivePort _port = new ReceivePort(); |
| + SendPort _sendPort; // Effectively final. |
| + |
| + static SendPort _SEND_PORT; |
| + |
| + _PureIsolateTimer(int milliSeconds, callback, repeating) { |
| + _sendPort = _port.toSendPort(); |
| + _port.receive((msg, replyTo) { |
| + assert(msg == _TIMER_PING); |
| + callback(this); |
| + if (!repeating) _cancel(); |
| + }); |
| + |
| + _send([_NEW_TIMER, milliSeconds, repeating]); |
| + } |
| + |
| + void cancel() { |
| + _cancel(); |
| + _send([_CANCEL_TIMER]); |
| + } |
| + |
| + void _cancel() { |
| + _port.close(); |
| + } |
| + |
| + _send(msg) { |
| + _sendToHelperIsolate(msg, _sendPort); |
| + } |
| +} |
| + |
| +get _pureIsolateTimerFactoryClosure => |
| + ((int milliSeconds, void callback(Timer time), bool repeating) => |
| + new _PureIsolateTimer(milliSeconds, callback, repeating)); |