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

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: Rename stuff. 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 | « tests/lib/lib.status ('k') | 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 2b760a209a8c4ad6216292c059628ad0f63078b3..7b123486440d280197e60513d6faaf667e81d774 100644
--- a/tools/dom/src/native_DOMImplementation.dart
+++ b/tools/dom/src/native_DOMImplementation.dart
@@ -531,6 +531,46 @@ get _pureIsolateTimerFactoryClosure =>
throw new UnimplementedError("Timers on background isolates "
"are not supported in the browser"));
+class _ScheduleImmediateHelper {
+ MutationObserver _observer;
+ final DivElement _div = new DivElement();
+ Function _callback;
+
+ _ScheduleImmediateHelper() {
+ // 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(_div, 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.
+ _div.hidden = !_div.hidden;
+ }
+
+ _handleMutation(List<MutationRecord> mutations, MutationObserver observer) {
+ var tmp = _callback;
+ _callback = null;
+ tmp();
+ }
+}
+
+final _ScheduleImmediateHelper _scheduleImmediateHelper =
+ new _ScheduleImmediateHelper();
+
+get _scheduleImmediateClosure => (void callback()) {
+ _scheduleImmediateHelper._schedule(callback);
+};
+
+get _pureIsolateScheduleImmediateClosure => ((void callback()) =>
+ throw new UnimplementedError("scheduleMicrotask in background isolates "
+ "are not supported in the browser"));
+
void _initializeCustomElement(Element e) {
_Utils.initializeCustomElement(e);
}
« no previous file with comments | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698