Chromium Code Reviews| 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 part of html; | 5 part of html; |
| 6 | 6 |
| 7 class _ConsoleVariables { | 7 class _ConsoleVariables { |
| 8 Map<String, Object> _data = new Map<String, Object>(); | 8 Map<String, Object> _data = new Map<String, Object>(); |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 | 523 |
| 524 final _forwardingPrintClosure = _Utils.forwardingPrint; | 524 final _forwardingPrintClosure = _Utils.forwardingPrint; |
| 525 | 525 |
| 526 final _uriBaseClosure = () => Uri.parse(window.location.href); | 526 final _uriBaseClosure = () => Uri.parse(window.location.href); |
| 527 | 527 |
| 528 final _pureIsolateUriBaseClosure = () { | 528 final _pureIsolateUriBaseClosure = () { |
| 529 throw new UnimplementedError("Uri.base on a background isolate " | 529 throw new UnimplementedError("Uri.base on a background isolate " |
| 530 "is not supported in the browser"); | 530 "is not supported in the browser"); |
| 531 }; | 531 }; |
| 532 | 532 |
| 533 class _Timer implements Timer { | 533 class _Timer implements Timer { |
| 534 var _canceler; | 534 const int _STATE_TIMEOUT = 0; |
| 535 const int _STATE_INTERVAL = 1; | |
| 536 var _state; | |
|
floitsch
2013/12/06 14:11:23
type as "int", and explain how it is used.
| |
| 535 | 537 |
| 536 _Timer(int milliSeconds, void callback(Timer timer), bool repeating) { | 538 _Timer(int milliSeconds, void callback(Timer timer), bool repeating) { |
| 537 | |
| 538 if (repeating) { | 539 if (repeating) { |
| 539 int id = window._setInterval(() { | 540 _state = window._setInterval(() { |
| 540 callback(this); | 541 callback(this); |
| 541 }, milliSeconds); | 542 }), 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
| |
| 542 _canceler = () => window._clearInterval(id); | |
| 543 } else { | 543 } else { |
| 544 int id = window._setTimeout(() { | 544 _state = window._setTimeout(() { |
| 545 _canceler = null; | 545 _state = null; |
| 546 callback(this); | 546 callback(this); |
| 547 }, milliSeconds); | 547 }), milliSeconds) * 2 + _STATE_TIMEOUT; |
| 548 _canceler = () => window._clearTimeout(id); | |
| 549 } | 548 } |
| 550 } | 549 } |
| 551 | 550 |
| 552 void cancel() { | 551 void cancel() { |
| 553 if (_canceler != null) { | 552 if (_state == null) return; |
| 554 _canceler(); | 553 int id = state ~/ 2; |
|
floitsch
2013/12/06 14:11:23
ditto.
| |
| 554 if ((_state & 1) == _STATE_TIMEOUT) { | |
| 555 window._clearTimeout(id); | |
| 556 } else { | |
| 557 window._clearInterval(id); | |
| 555 } | 558 } |
| 556 _canceler = null; | 559 _state = null; |
| 557 } | 560 } |
| 558 | 561 |
| 559 bool get isActive => _canceler != null; | 562 bool get isActive => _state != null; |
| 560 } | 563 } |
| 561 | 564 |
| 562 get _timerFactoryClosure => | 565 get _timerFactoryClosure => |
| 563 (int milliSeconds, void callback(Timer timer), bool repeating) { | 566 (int milliSeconds, void callback(Timer timer), bool repeating) { |
| 564 return new _Timer(milliSeconds, callback, repeating); | 567 return new _Timer(milliSeconds, callback, repeating); |
| 565 }; | 568 }; |
| 566 | 569 |
| 567 get _pureIsolateTimerFactoryClosure => | 570 get _pureIsolateTimerFactoryClosure => |
| 568 ((int milliSeconds, void callback(Timer time), bool repeating) => | 571 ((int milliSeconds, void callback(Timer time), bool repeating) => |
| 569 throw new UnimplementedError("Timers on background isolates " | 572 throw new UnimplementedError("Timers on background isolates " |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 _scheduleImmediateHelper._schedule(callback); | 612 _scheduleImmediateHelper._schedule(callback); |
| 610 }; | 613 }; |
| 611 | 614 |
| 612 get _pureIsolateScheduleImmediateClosure => ((void callback()) => | 615 get _pureIsolateScheduleImmediateClosure => ((void callback()) => |
| 613 throw new UnimplementedError("scheduleMicrotask in background isolates " | 616 throw new UnimplementedError("scheduleMicrotask in background isolates " |
| 614 "are not supported in the browser")); | 617 "are not supported in the browser")); |
| 615 | 618 |
| 616 void _initializeCustomElement(Element e) { | 619 void _initializeCustomElement(Element e) { |
| 617 _Utils.initializeCustomElement(e); | 620 _Utils.initializeCustomElement(e); |
| 618 } | 621 } |
| OLD | NEW |