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

Side by Side Diff: sdk/lib/async/zone.dart

Issue 23054006: for discussion: support for zones in DOM events (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.async; 5 part of dart.async;
6 6
7 /** 7 /**
8 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous 8 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous
9 * callbacks are executed in the zone they have been queued in. For example, 9 * callbacks are executed in the zone they have been queued in. For example,
10 * the callback of a `future.then` is executed in the same zone as the one where 10 * the callback of a `future.then` is executed in the same zone as the one where
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 * of `this`. 123 * of `this`.
124 */ 124 */
125 void _addChild(_Zone child); 125 void _addChild(_Zone child);
126 126
127 /** 127 /**
128 * Removes [child] from `this`' children. 128 * Removes [child] from `this`' children.
129 * 129 *
130 * This usually means that the [child] has finished executing and is done. 130 * This usually means that the [child] has finished executing and is done.
131 */ 131 */
132 void _removeChild(_Zone child); 132 void _removeChild(_Zone child);
133
134 /**
135 * True if this is the default zone, otherwise false.
136 */
137 bool get isDefault;
133 } 138 }
134 139
135 /** 140 /**
136 * Basic implementation of a [_Zone]. This class is intended for subclassing. 141 * Basic implementation of a [_Zone]. This class is intended for subclassing.
137 */ 142 */
138 class _ZoneBase implements _Zone { 143 class _ZoneBase implements _Zone {
139 /// The parent zone. [null] if `this` is the default zone. 144 /// The parent zone. [null] if `this` is the default zone.
140 final _Zone _parentZone; 145 final _Zone _parentZone;
141 146
142 /// The children of this zone. A child's [_parentZone] is `this`. 147 /// The children of this zone. A child's [_parentZone] is `this`.
143 // TODO(floitsch): this should be a double-linked list. 148 // TODO(floitsch): this should be a double-linked list.
144 final List<_Zone> _children = <_Zone>[]; 149 final List<_Zone> _children = <_Zone>[];
145 150
146 /// The number of outstanding (asynchronous) callbacks. As long as the 151 /// The number of outstanding (asynchronous) callbacks. As long as the
147 /// number is greater than 0 it means that the zone is not done yet. 152 /// number is greater than 0 it means that the zone is not done yet.
148 int _openCallbacks = 0; 153 int _openCallbacks = 0;
149 154
150 bool _isExecutingCallback = false; 155 bool _isExecutingCallback = false;
151 156
152 _ZoneBase(this._parentZone) { 157 _ZoneBase(this._parentZone) {
153 _parentZone._addChild(this); 158 _parentZone._addChild(this);
154 } 159 }
155 160
156 _ZoneBase._defaultZone() : _parentZone = null { 161 _ZoneBase._defaultZone() : _parentZone = null {
157 assert(this is _DefaultZone); 162 assert(this is _DefaultZone);
158 } 163 }
159 164
165 bool get isDefault => false;
166
160 _Zone get _errorZone => _parentZone._errorZone; 167 _Zone get _errorZone => _parentZone._errorZone;
161 168
162 void handleUncaughtError(error) { 169 void handleUncaughtError(error) {
163 _parentZone.handleUncaughtError(error); 170 _parentZone.handleUncaughtError(error);
164 } 171 }
165 172
166 bool inSameErrorZone(_Zone otherZone) => _errorZone == otherZone._errorZone; 173 bool inSameErrorZone(_Zone otherZone) => _errorZone == otherZone._errorZone;
167 174
168 _Zone fork() => this; 175 _Zone fork() => this;
169 176
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 throw new ArgumentError(child); 321 throw new ArgumentError(child);
315 } 322 }
316 } 323 }
317 324
318 /** 325 /**
319 * The default-zone that conceptually surrounds the `main` function. 326 * The default-zone that conceptually surrounds the `main` function.
320 */ 327 */
321 class _DefaultZone extends _ZoneBase { 328 class _DefaultZone extends _ZoneBase {
322 _DefaultZone() : super._defaultZone(); 329 _DefaultZone() : super._defaultZone();
323 330
331 bool get isDefault => true;
332
324 _Zone get _errorZone => this; 333 _Zone get _errorZone => this;
325 334
326 handleUncaughtError(error) { 335 handleUncaughtError(error) {
327 _scheduleAsyncCallback(() { 336 _scheduleAsyncCallback(() {
328 print("Uncaught Error: ${error}"); 337 print("Uncaught Error: ${error}");
329 var trace = getAttachedStackTrace(error); 338 var trace = getAttachedStackTrace(error);
330 _attachStackTrace(error, null); 339 _attachStackTrace(error, null);
331 if (trace != null) { 340 if (trace != null) {
332 print("Stack Trace:\n$trace\n"); 341 print("Stack Trace:\n$trace\n");
333 } 342 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 if (onError == null && onDone == null) return body(); 558 if (onError == null && onDone == null) return body();
550 if (onError == null) { 559 if (onError == null) {
551 _WaitForCompletionZone zone = 560 _WaitForCompletionZone zone =
552 new _WaitForCompletionZone(_Zone._current, onDone); 561 new _WaitForCompletionZone(_Zone._current, onDone);
553 return zone.runWaitForCompletion(body); 562 return zone.runWaitForCompletion(body);
554 } 563 }
555 if (onDone == null) onDone = _nullDoneHandler; 564 if (onDone == null) onDone = _nullDoneHandler;
556 _CatchErrorsZone zone = new _CatchErrorsZone(_Zone._current, onError, onDone); 565 _CatchErrorsZone zone = new _CatchErrorsZone(_Zone._current, onError, onDone);
557 return zone.runWaitForCompletion(body); 566 return zone.runWaitForCompletion(body);
558 } 567 }
568
569 /**
570 * Gets the current zone. See [runZonedExperimental].
571 *
572 * *Warning*: all Zone APIs are subject to change. Your code may break in the
573 * future with [NoSuchMethodError] or cause have other unexpected behavior.
574 */
575 // TODO(jmesserly): how do we expose only the features that dart:html needs?
576 // Crazy idea: move EventStreamSubscription to be an abstract base class in
577 // dart:async (possibly renaming it) and make the calls to add and remove the
578 // listener abstract. Then dart:html overrides it to use DOM addEventListener
579 // and removeEventListener.
580 get currentZoneExperimental => _Zone.current;
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698