Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Unified Diff: sdk/lib/_internal/js_runtime/lib/isolate_helper.dart

Issue 3003853002: Add ticks counter to Timer. (Closed)
Patch Set: Test that tick increments by more than one Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart b/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
index ebe79513d986733fccebc8d742528296905f7210..463858ab2faefed015975c8c52e1110d1f7668ba 100644
--- a/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
+++ b/sdk/lib/_internal/js_runtime/lib/isolate_helper.dart
@@ -1365,6 +1365,7 @@ class TimerImpl implements Timer {
final bool _once;
bool _inEventLoop = false;
int _handle;
+ int _tick = 0;
TimerImpl(int milliseconds, void callback()) : _once = true {
if (milliseconds == 0 && (!hasTimer() || _globalState.isWorker)) {
@@ -1390,6 +1391,7 @@ class TimerImpl implements Timer {
void internalCallback() {
_handle = null;
leaveJsAsync();
+ this._tick = 1;
callback();
}
@@ -1407,10 +1409,19 @@ class TimerImpl implements Timer {
: _once = false {
if (hasTimer()) {
enterJsAsync();
+ int start = JS('int', 'Date.now()');
_handle = JS(
'int',
'self.setInterval(#, #)',
convertDartClosureToJS(() {
+ int tick = this._tick + 1;
+ if (milliseconds > 0) {
+ int duration = JS('int', 'Date.now()') - start;
+ if (duration > (tick + 1) * milliseconds) {
+ tick = duration ~/ milliseconds;
+ }
+ }
+ this._tick = tick;
callback(this);
}, 0),
milliseconds);
@@ -1419,6 +1430,8 @@ class TimerImpl implements Timer {
}
}
+ int get tick => _tick;
+
void cancel() {
if (hasTimer()) {
if (_inEventLoop) {

Powered by Google App Engine
This is Rietveld 408576698