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

Unified Diff: tools/dom/src/native_DOMImplementation.dart

Issue 25722010: Add support for micro-tasks in Dartium. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reues both dummy-element and MutationObserver. Created 7 years, 2 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/src/native_DOMImplementation.dart
diff --git a/tools/dom/src/native_DOMImplementation.dart b/tools/dom/src/native_DOMImplementation.dart
index 38956acce395564bff0f575e0138a21a1a5544e5..2834bebf9363f416a0c08c1fe3ceefacd3722063 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -526,6 +526,46 @@ get _pureIsolateTimerFactoryClosure =>
throw new UnimplementedError("Timers on background isolates "
"are not supported in the browser"));
+class _EnqueueImmediateScheduler {
+ MutationObserver _observer;
+ final Element _dummy = new DivElement();
floitsch 2013/10/10 16:02:18 s/_dummy/_div
Anders Johnsen 2013/10/15 17:21:17 Done.
+ Function _callback;
+
+ _EnqueueImmediateScheduler() {
+ // Mutation events get fired as soon as the current event stack is unwound
+ // so we just make a dummy event and listen for that.
+ _observer = new MutationObserver(_handleMutation);
+ _observer.observe(_dummy, attributes: true);
+ }
+
+ void _schedule(callback) {
+ if (_callback != null) {
+ throw new StateError(
+ 'Only one immediate callback can be scheduled at once');
+ }
+ _callback = callback;
+ // Toggle it to trigger the mutation event.
+ _dummy.hidden = !_dummy.hidden;
+ }
+
+ _handleMutation(List<MutationRecord> mutations, MutationObserver observer) {
+ var tmp = _callback;
+ _callback = null;
+ tmp();
+ }
+}
+
+final _EnqueueImmediateScheduler _enqueueImmediateScheduler =
+ new _EnqueueImmediateScheduler();
+
+get _enqueueImmediateFactoryClosure => (void callback()) {
+ _enqueueImmediateScheduler._schedule(callback);
+};
+
+get _pureIsolateEnqueueImmediateFactoryClosure => ((void callback()) =>
+ throw new UnimplementedError("runAsync in background isolates "
+ "are not supported in the browser"));
+
void _initializeCustomElement(Element e) {
_Utils.initializeCustomElement(e);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698