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

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

Issue 383993003: Implement scheduleImmediate on Chrome/Drt/Safari/Firefox. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revert changes to html.status. Created 6 years, 5 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 | tests/lib/lib.status » ('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 0203e4dabf2f50192698dbe11615de80fea08ef8..004f433b54f36d8ebc6bc1758b8b371c9583a3e6 100644
--- a/sdk/lib/_internal/lib/async_patch.dart
+++ b/sdk/lib/_internal/lib/async_patch.dart
@@ -8,7 +8,8 @@ import 'dart:_js_helper' show
patch,
Primitives,
convertDartClosureToJS,
- loadDeferredLibrary;
+ loadDeferredLibrary,
+ requiresPreamble;
import 'dart:_isolate_helper' show
IsolateNatives,
TimerImpl,
@@ -30,11 +31,44 @@ class _AsyncRun {
_initializeScheduleImmediate();
static Function _initializeScheduleImmediate() {
+ requiresPreamble();
if (JS('', 'self.scheduleImmediate') != null) {
return _scheduleImmediateJsOverride;
}
+ if (JS('', 'self.MutationObserver') != null &&
+ JS('', 'self.document') != null) {
+ // Use mutationObservers.
+ var div = JS('', 'self.document.createElement("div")');
+ var span = JS('', 'self.document.createElement("span")');
+ var storedCallback;
+
+ internalCallback(_) {
+ leaveJsAsync();
+ var f = storedCallback;
+ storedCallback = null;
+ f();
+ };
+
+ var observer = JS('', 'new self.MutationObserver(#)',
+ convertDartClosureToJS(internalCallback, 1));
+ JS('', '#.observe(#, { childList: true })',
+ observer, div);
+
+ return (void callback()) {
+ assert(storedCallback == null);
+ enterJsAsync();
+ storedCallback = callback;
+ // Because of a broken shadow-dom polyfill we have to change the
+ // children instead a cheap property.
+ // See https://github.com/Polymer/ShadowDOM/issues/468
+ JS('', '#.firstChild ? #.removeChild(#): #.appendChild(#)',
+ div, div, span, div, span);
+ };
+
+ }
// TODO(9002): don't use the Timer to enqueue the immediate callback.
- // Also check for other JS options like mutation observer or runImmediate.
+ // Also check for other JS options like setImmediate.
+ // TODO(20055): We should use DOM promises when available.
return _scheduleImmediateWithTimer;
}
« no previous file with comments | « no previous file | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698