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

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: Fix bug. Update status. Created 6 years, 8 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') | no next file with comments »
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 aa1c34239cdc1f132d884f8474002edde3c3e956..c67b3ff7dbe4f31a9d7cb1a385dee1558323fd53 100644
--- a/sdk/lib/_internal/lib/async_patch.dart
+++ b/sdk/lib/_internal/lib/async_patch.dart
@@ -8,7 +8,13 @@ import 'dart:_js_helper' show
Primitives,
convertDartClosureToJS,
loadDeferredLibrary;
-import 'dart:_isolate_helper' show TimerImpl;
+import 'dart:_isolate_helper' show
+ IsolateNatives,
+ TimerImpl,
+ leaveJsAsync,
+ enterJsAsync,
+ isWorker,
+ globalThis;
import 'dart:_foreign_helper' show JS;
@@ -27,7 +33,34 @@ 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()) {
+ internalCallback() {
+ leaveJsAsync();
+ callback();
+ };
+ enterJsAsync();
+ JS('void', '#.scheduleImmediate(#)',
+ globalThis,
+ convertDartClosureToJS(internalCallback, 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698