Chromium Code Reviews| Index: sdk/lib/_internal/lib/async_patch.dart |
| diff --git a/sdk/lib/_internal/lib/async_patch.dart b/sdk/lib/_internal/lib/async_patch.dart |
| index c26f29f9291e8c5926101078eefd5077c82b9295..456d3c0e5dde97fa655e7c16293fa807a442cd47 100644 |
| --- a/sdk/lib/_internal/lib/async_patch.dart |
| +++ b/sdk/lib/_internal/lib/async_patch.dart |
| @@ -10,13 +10,15 @@ import 'dart:_isolate_helper' show |
| TimerImpl, |
| leaveJsAsync, |
| enterJsAsync, |
| - isWorker; |
| + isWorker, |
| + globalThis; |
| import 'dart:_foreign_helper' show JS; |
| patch Timer _createTimer(Duration duration, void callback()) { |
| int milliseconds = duration.inMilliseconds; |
| if (milliseconds < 0) milliseconds = 0; |
| + if (milliseconds > 0) print("T: $milliseconds"); |
|
floitsch
2014/03/18 13:18:23
debug code. (just fyi).
Lasse Reichstein Nielsen
2014/03/19 10:24:41
Done.
|
| return new TimerImpl(milliseconds, callback); |
| } |
| @@ -29,7 +31,29 @@ patch Timer _createPeriodicTimer(Duration duration, |
| patch class _AsyncRun { |
| patch static void _scheduleImmediate(void callback()) { |
| + scheduleImmediateClosure(callback); |
| + } |
| + |
| + // Lazily initialized. |
| + static final Function scheduleImmediateClosure = |
| + _initializeScheduleImmediate(); |
| + |
| + static Function _initializeScheduleImmediate() { |
| + if (JS('', '#.scheduleImmediate', globalThis) != null) { |
| + return _scheduleImmediateJsOverride; |
| + } |
| // TODO(9002): don't use the Timer to enqueue the immediate callback. |
| + // Also check for other JS options like mutation observer or runImmediate. |
| + return _scheduleImmediateWithTimer; |
| + } |
| + |
| + static void _scheduleImmediateJsOverride(void callback()) { |
| + JS('void', '#.scheduleImmediate(#)', |
| + globalThis, |
| + convertDartClosureToJS(callback, 0)); |
| + } |
| + |
| + static void _scheduleImmediateWithTimer(void callback()) { |
| _createTimer(Duration.ZERO, callback); |
| } |
| } |