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

Unified Diff: sdk/lib/_internal/lib/async_patch.dart

Issue 201873002: Trying to make preamble for d8. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Works, but unexpectedly fails on non-zero timers. Created 6 years, 9 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
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/preambles/d8.js » ('j') | sdk/lib/_internal/lib/preambles/d8.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/preambles/d8.js » ('j') | sdk/lib/_internal/lib/preambles/d8.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698