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

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

Issue 48483002: Remove deprecated parts of dart:async. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 7 years, 1 month 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
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 typedef dynamic ZoneCallback(); 7 typedef dynamic ZoneCallback();
8 typedef dynamic ZoneUnaryCallback(arg); 8 typedef dynamic ZoneUnaryCallback(arg);
9 typedef dynamic ZoneBinaryCallback(arg1, arg2); 9 typedef dynamic ZoneBinaryCallback(arg1, arg2);
10 10
11 typedef dynamic HandleUncaughtErrorHandler( 11 typedef dynamic HandleUncaughtErrorHandler(
12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); 12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace);
13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); 13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f());
14 typedef dynamic RunUnaryHandler( 14 typedef dynamic RunUnaryHandler(
15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); 15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg);
16 typedef dynamic RunBinaryHandler( 16 typedef dynamic RunBinaryHandler(
17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); 17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2);
18 typedef ZoneCallback RegisterCallbackHandler( 18 typedef ZoneCallback RegisterCallbackHandler(
19 Zone self, ZoneDelegate parent, Zone zone, f()); 19 Zone self, ZoneDelegate parent, Zone zone, f());
20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( 20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler(
21 Zone self, ZoneDelegate parent, Zone zone, f(arg)); 21 Zone self, ZoneDelegate parent, Zone zone, f(arg));
22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( 22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler(
23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); 23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2));
24 typedef void ScheduleMicrotaskHandler( 24 typedef void ScheduleMicrotaskHandler(
25 Zone self, ZoneDelegate parent, Zone zone, f()); 25 Zone self, ZoneDelegate parent, Zone zone, f());
26 @deprecated
27 typedef void RunAsyncHandler(
28 Zone self, ZoneDelegate parent, Zone zone, f());
29 typedef Timer CreateTimerHandler( 26 typedef Timer CreateTimerHandler(
30 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); 27 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f());
31 typedef Timer CreatePeriodicTimerHandler( 28 typedef Timer CreatePeriodicTimerHandler(
32 Zone self, ZoneDelegate parent, Zone zone, 29 Zone self, ZoneDelegate parent, Zone zone,
33 Duration period, void f(Timer timer)); 30 Duration period, void f(Timer timer));
34 typedef void PrintHandler( 31 typedef void PrintHandler(
35 Zone self, ZoneDelegate parent, Zone zone, String line); 32 Zone self, ZoneDelegate parent, Zone zone, String line);
36 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, 33 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone,
37 ZoneSpecification specification, 34 ZoneSpecification specification,
38 Map<Symbol, dynamic> zoneValues); 35 Map<Symbol, dynamic> zoneValues);
39 36
40 /** 37 /**
41 * This class provides the specification for a forked zone. 38 * This class provides the specification for a forked zone.
42 * 39 *
43 * When forking a new zone (see [Zone.fork]) one can override the default 40 * When forking a new zone (see [Zone.fork]) one can override the default
44 * behavior of the zone by providing callbacks. These callbacks must be 41 * behavior of the zone by providing callbacks. These callbacks must be
45 * given in an instance of this class. 42 * given in an instance of this class.
46 * 43 *
47 * Handlers have the same signature as the same-named methods on [Zone] but 44 * Handlers have the same signature as the same-named methods on [Zone] but
48 * receive three additional arguments: 45 * receive three additional arguments:
49 * 46 *
50 * 1. the zone the handlers are attached to (the "self" zone). 47 * 1. the zone the handlers are attached to (the "self" zone).
51 * 2. a [ZoneDelegate] to the parent zone. 48 * 2. a [ZoneDelegate] to the parent zone.
52 * 3. the zone that first received the request (before the request was 49 * 3. the zone that first received the request (before the request was
53 * bubbled up). 50 * bubbled up).
54 * 51 *
55 * Handlers can either stop propagation the request (by simply not calling the 52 * Handlers can either stop propagation the request (by simply not calling the
56 * parent handler), or forward to the parent zone, potentially modifying the 53 * parent handler), or forward to the parent zone, potentially modifying the
57 * arguments on the way. 54 * arguments on the way.
58 *
59 * *The `runAsync` handler is deprecated. Use `scheduleMicrotask` instead.*
60 */ 55 */
61 abstract class ZoneSpecification { 56 abstract class ZoneSpecification {
62 /** 57 /**
63 * Creates a specification with the provided handlers. 58 * Creates a specification with the provided handlers.
64 */ 59 */
65 const factory ZoneSpecification({ 60 const factory ZoneSpecification({
66 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, 61 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone,
67 error, StackTrace stackTrace), 62 error, StackTrace stackTrace),
68 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()), 63 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()),
69 dynamic runUnary( 64 dynamic runUnary(
70 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg), 65 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg),
71 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, 66 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone,
72 f(arg1, arg2), arg1, arg2), 67 f(arg1, arg2), arg1, arg2),
73 ZoneCallback registerCallback( 68 ZoneCallback registerCallback(
74 Zone self, ZoneDelegate parent, Zone zone, f()), 69 Zone self, ZoneDelegate parent, Zone zone, f()),
75 ZoneUnaryCallback registerUnaryCallback( 70 ZoneUnaryCallback registerUnaryCallback(
76 Zone self, ZoneDelegate parent, Zone zone, f(arg)), 71 Zone self, ZoneDelegate parent, Zone zone, f(arg)),
77 ZoneBinaryCallback registerBinaryCallback( 72 ZoneBinaryCallback registerBinaryCallback(
78 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), 73 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)),
79 void scheduleMicrotask( 74 void scheduleMicrotask(
80 Zone self, ZoneDelegate parent, Zone zone, f()), 75 Zone self, ZoneDelegate parent, Zone zone, f()),
81 void runAsync(
82 Zone self, ZoneDelegate parent, Zone zone, f()),
83 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, 76 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone,
84 Duration duration, void f()), 77 Duration duration, void f()),
85 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, 78 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone,
86 Duration period, void f(Timer timer)), 79 Duration period, void f(Timer timer)),
87 void print(Zone self, ZoneDelegate parent, Zone zone, String line), 80 void print(Zone self, ZoneDelegate parent, Zone zone, String line),
88 Zone fork(Zone self, ZoneDelegate parent, Zone zone, 81 Zone fork(Zone self, ZoneDelegate parent, Zone zone,
89 ZoneSpecification specification, Map zoneValues) 82 ZoneSpecification specification, Map zoneValues)
90 }) = _ZoneSpecification; 83 }) = _ZoneSpecification;
91 84
92 /** 85 /**
93 * Creates a specification from [other] with the provided handlers overriding 86 * Creates a specification from [other] with the provided handlers overriding
94 * the ones in [other]. 87 * the ones in [other].
95 */ 88 */
96 factory ZoneSpecification.from(ZoneSpecification other, { 89 factory ZoneSpecification.from(ZoneSpecification other, {
97 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, 90 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone,
98 error, StackTrace stackTrace): null, 91 error, StackTrace stackTrace): null,
99 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, 92 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null,
100 dynamic runUnary( 93 dynamic runUnary(
101 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, 94 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null,
102 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, 95 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone,
103 f(arg1, arg2), arg1, arg2): null, 96 f(arg1, arg2), arg1, arg2): null,
104 ZoneCallback registerCallback( 97 ZoneCallback registerCallback(
105 Zone self, ZoneDelegate parent, Zone zone, f()): null, 98 Zone self, ZoneDelegate parent, Zone zone, f()): null,
106 ZoneUnaryCallback registerUnaryCallback( 99 ZoneUnaryCallback registerUnaryCallback(
107 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, 100 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null,
108 ZoneBinaryCallback registerBinaryCallback( 101 ZoneBinaryCallback registerBinaryCallback(
109 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, 102 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null,
110 void scheduleMicrotask( 103 void scheduleMicrotask(
111 Zone self, ZoneDelegate parent, Zone zone, f()): null, 104 Zone self, ZoneDelegate parent, Zone zone, f()): null,
112 void runAsync(
113 Zone self, ZoneDelegate parent, Zone zone, f()): null,
114 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, 105 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone,
115 Duration duration, void f()): null, 106 Duration duration, void f()): null,
116 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, 107 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone,
117 Duration period, void f(Timer timer)): null, 108 Duration period, void f(Timer timer)): null,
118 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, 109 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null,
119 Zone fork(Zone self, ZoneDelegate parent, Zone zone, 110 Zone fork(Zone self, ZoneDelegate parent, Zone zone,
120 ZoneSpecification specification, 111 ZoneSpecification specification,
121 Map<Symbol, dynamic> zoneValues): null 112 Map<Symbol, dynamic> zoneValues): null
122 }) { 113 }) {
123 return new ZoneSpecification( 114 return new ZoneSpecification(
124 handleUncaughtError: handleUncaughtError != null 115 handleUncaughtError: handleUncaughtError != null
125 ? handleUncaughtError 116 ? handleUncaughtError
126 : other.handleUncaughtError, 117 : other.handleUncaughtError,
127 run: run != null ? run : other.run, 118 run: run != null ? run : other.run,
128 runUnary: runUnary != null ? runUnary : other.runUnary, 119 runUnary: runUnary != null ? runUnary : other.runUnary,
129 runBinary: runBinary != null ? runBinary : other.runBinary, 120 runBinary: runBinary != null ? runBinary : other.runBinary,
130 registerCallback: registerCallback != null 121 registerCallback: registerCallback != null
131 ? registerCallback 122 ? registerCallback
132 : other.registerCallback, 123 : other.registerCallback,
133 registerUnaryCallback: registerUnaryCallback != null 124 registerUnaryCallback: registerUnaryCallback != null
134 ? registerUnaryCallback 125 ? registerUnaryCallback
135 : other.registerUnaryCallback, 126 : other.registerUnaryCallback,
136 registerBinaryCallback: registerBinaryCallback != null 127 registerBinaryCallback: registerBinaryCallback != null
137 ? registerBinaryCallback 128 ? registerBinaryCallback
138 : other.registerBinaryCallback, 129 : other.registerBinaryCallback,
139 scheduleMicrotask: scheduleMicrotask != null 130 scheduleMicrotask: scheduleMicrotask != null
140 ? scheduleMicrotask 131 ? scheduleMicrotask
141 : (runAsync != null 132 : other.scheduleMicrotask,
142 ? runAsync
143 : other.scheduleMicrotask),
144 createTimer : createTimer != null ? createTimer : other.createTimer, 133 createTimer : createTimer != null ? createTimer : other.createTimer,
145 createPeriodicTimer: createPeriodicTimer != null 134 createPeriodicTimer: createPeriodicTimer != null
146 ? createPeriodicTimer 135 ? createPeriodicTimer
147 : other.createPeriodicTimer, 136 : other.createPeriodicTimer,
148 print : print != null ? print : other.print, 137 print : print != null ? print : other.print,
149 fork: fork != null ? fork : other.fork); 138 fork: fork != null ? fork : other.fork);
150 } 139 }
151 140
152 HandleUncaughtErrorHandler get handleUncaughtError; 141 HandleUncaughtErrorHandler get handleUncaughtError;
153 RunHandler get run; 142 RunHandler get run;
154 RunUnaryHandler get runUnary; 143 RunUnaryHandler get runUnary;
155 RunBinaryHandler get runBinary; 144 RunBinaryHandler get runBinary;
156 RegisterCallbackHandler get registerCallback; 145 RegisterCallbackHandler get registerCallback;
157 RegisterUnaryCallbackHandler get registerUnaryCallback; 146 RegisterUnaryCallbackHandler get registerUnaryCallback;
158 RegisterBinaryCallbackHandler get registerBinaryCallback; 147 RegisterBinaryCallbackHandler get registerBinaryCallback;
159 ScheduleMicrotaskHandler get scheduleMicrotask; 148 ScheduleMicrotaskHandler get scheduleMicrotask;
160 @deprecated
161 RunAsyncHandler get runAsync;
162 CreateTimerHandler get createTimer; 149 CreateTimerHandler get createTimer;
163 CreatePeriodicTimerHandler get createPeriodicTimer; 150 CreatePeriodicTimerHandler get createPeriodicTimer;
164 PrintHandler get print; 151 PrintHandler get print;
165 ForkHandler get fork; 152 ForkHandler get fork;
166 } 153 }
167 154
168 /** 155 /**
169 * Internal [ZoneSpecification] class. 156 * Internal [ZoneSpecification] class.
170 * 157 *
171 * The implementation wants to rely on the fact that the getters cannot change 158 * The implementation wants to rely on the fact that the getters cannot change
172 * dynamically. We thus require users to go through the redirecting 159 * dynamically. We thus require users to go through the redirecting
173 * [ZoneSpecification] constructor which instantiates this class. 160 * [ZoneSpecification] constructor which instantiates this class.
174 */ 161 */
175 class _ZoneSpecification implements ZoneSpecification { 162 class _ZoneSpecification implements ZoneSpecification {
176 const _ZoneSpecification({ 163 const _ZoneSpecification({
177 this.handleUncaughtError: null, 164 this.handleUncaughtError: null,
178 this.run: null, 165 this.run: null,
179 this.runUnary: null, 166 this.runUnary: null,
180 this.runBinary: null, 167 this.runBinary: null,
181 this.registerCallback: null, 168 this.registerCallback: null,
182 this.registerUnaryCallback: null, 169 this.registerUnaryCallback: null,
183 this.registerBinaryCallback: null, 170 this.registerBinaryCallback: null,
184 this.scheduleMicrotask: null, 171 this.scheduleMicrotask: null,
185 this.runAsync: null,
186 this.createTimer: null, 172 this.createTimer: null,
187 this.createPeriodicTimer: null, 173 this.createPeriodicTimer: null,
188 this.print: null, 174 this.print: null,
189 this.fork: null 175 this.fork: null
190 }); 176 });
191 177
192 // TODO(13406): Enable types when dart2js supports it. 178 // TODO(13406): Enable types when dart2js supports it.
193 final /*HandleUncaughtErrorHandler*/ handleUncaughtError; 179 final /*HandleUncaughtErrorHandler*/ handleUncaughtError;
194 final /*RunHandler*/ run; 180 final /*RunHandler*/ run;
195 final /*RunUnaryHandler*/ runUnary; 181 final /*RunUnaryHandler*/ runUnary;
196 final /*RunBinaryHandler*/ runBinary; 182 final /*RunBinaryHandler*/ runBinary;
197 final /*RegisterCallbackHandler*/ registerCallback; 183 final /*RegisterCallbackHandler*/ registerCallback;
198 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback; 184 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback;
199 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback; 185 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback;
200 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask; 186 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask;
201 @deprecated
202 final /*RunAsyncHandler*/ runAsync;
203 final /*CreateTimerHandler*/ createTimer; 187 final /*CreateTimerHandler*/ createTimer;
204 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer; 188 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer;
205 final /*PrintHandler*/ print; 189 final /*PrintHandler*/ print;
206 final /*ForkHandler*/ fork; 190 final /*ForkHandler*/ fork;
207 } 191 }
208 192
209 /** 193 /**
210 * This class wraps zones for delegation. 194 * This class wraps zones for delegation.
211 * 195 *
212 * When forwarding to parent zones one can't just invoke the parent zone's 196 * When forwarding to parent zones one can't just invoke the parent zone's
213 * exposed functions (like [Zone.run]), but one needs to provide more 197 * exposed functions (like [Zone.run]), but one needs to provide more
214 * information (like the zone the `run` was initiated). Zone callbacks thus 198 * information (like the zone the `run` was initiated). Zone callbacks thus
215 * receive more information including this [ZoneDelegate] class. When delegating 199 * receive more information including this [ZoneDelegate] class. When delegating
216 * to the parent zone one should go through the given instance instead of 200 * to the parent zone one should go through the given instance instead of
217 * directly invoking the parent zone. 201 * directly invoking the parent zone.
218 */ 202 */
219 abstract class ZoneDelegate { 203 abstract class ZoneDelegate {
220 /// The [Zone] this class wraps. 204 /// The [Zone] this class wraps.
221 Zone get _zone; 205 Zone get _zone;
222 206
223 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); 207 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace);
224 dynamic run(Zone zone, f()); 208 dynamic run(Zone zone, f());
225 dynamic runUnary(Zone zone, f(arg), arg); 209 dynamic runUnary(Zone zone, f(arg), arg);
226 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); 210 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2);
227 ZoneCallback registerCallback(Zone zone, f()); 211 ZoneCallback registerCallback(Zone zone, f());
228 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); 212 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg));
229 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); 213 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2));
230 @deprecated
231 void runAsync(Zone zone, f());
232 void scheduleMicrotask(Zone zone, f()); 214 void scheduleMicrotask(Zone zone, f());
233 Timer createTimer(Zone zone, Duration duration, void f()); 215 Timer createTimer(Zone zone, Duration duration, void f());
234 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); 216 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer));
235 void print(Zone zone, String line); 217 void print(Zone zone, String line);
236 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); 218 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues);
237 } 219 }
238 220
239 /** 221 /**
240 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous 222 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous
241 * callbacks are executed in the zone they have been queued in. For example, 223 * callbacks are executed in the zone they have been queued in. For example,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); 356 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2);
375 */ 357 */
376 ZoneBinaryCallback bindBinaryCallback( 358 ZoneBinaryCallback bindBinaryCallback(
377 f(arg1, arg2), { bool runGuarded: true }); 359 f(arg1, arg2), { bool runGuarded: true });
378 360
379 /** 361 /**
380 * Runs [f] asynchronously. 362 * Runs [f] asynchronously.
381 */ 363 */
382 void scheduleMicrotask(void f()); 364 void scheduleMicrotask(void f());
383 365
384 @deprecated
385 void runAsync(void f());
386
387 /** 366 /**
388 * Creates a Timer where the callback is executed in this zone. 367 * Creates a Timer where the callback is executed in this zone.
389 */ 368 */
390 Timer createTimer(Duration duration, void callback()); 369 Timer createTimer(Duration duration, void callback());
391 370
392 /** 371 /**
393 * Creates a periodic Timer where the callback is executed in this zone. 372 * Creates a periodic Timer where the callback is executed in this zone.
394 */ 373 */
395 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); 374 Timer createPeriodicTimer(Duration period, void callback(Timer timer));
396 375
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 _BaseZone parent = _degelationTarget; 458 _BaseZone parent = _degelationTarget;
480 while (parent._specification.registerBinaryCallback == null) { 459 while (parent._specification.registerBinaryCallback == null) {
481 parent = parent.parent; 460 parent = parent.parent;
482 } 461 }
483 return (parent._specification.registerBinaryCallback)( 462 return (parent._specification.registerBinaryCallback)(
484 parent, new _ZoneDelegate(parent.parent), zone, f); 463 parent, new _ZoneDelegate(parent.parent), zone, f);
485 } 464 }
486 465
487 void scheduleMicrotask(Zone zone, f()) { 466 void scheduleMicrotask(Zone zone, f()) {
488 _BaseZone parent = _degelationTarget; 467 _BaseZone parent = _degelationTarget;
489 while (parent._specification.scheduleMicrotask == null && 468 while (parent._specification.scheduleMicrotask == null) {
490 parent._specification.runAsync == null) {
491 parent = parent.parent; 469 parent = parent.parent;
492 } 470 }
493 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent); 471 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent);
494 Function scheduleMicrotask = parent._specification.scheduleMicrotask; 472 Function scheduleMicrotask = parent._specification.scheduleMicrotask;
495 if (scheduleMicrotask == null) {
496 scheduleMicrotask = parent._specification.runAsync;
497 }
498 scheduleMicrotask(parent, grandParent, zone, f); 473 scheduleMicrotask(parent, grandParent, zone, f);
499 } 474 }
500 475
501 @deprecated
502 void runAsync(Zone zone, f()) {
503 scheduleMicrotask(zone, f());
504 }
505
506 Timer createTimer(Zone zone, Duration duration, void f()) { 476 Timer createTimer(Zone zone, Duration duration, void f()) {
507 _BaseZone parent = _degelationTarget; 477 _BaseZone parent = _degelationTarget;
508 while (parent._specification.createTimer == null) { 478 while (parent._specification.createTimer == null) {
509 parent = parent.parent; 479 parent = parent.parent;
510 } 480 }
511 return (parent._specification.createTimer)( 481 return (parent._specification.createTimer)(
512 parent, new _ZoneDelegate(parent.parent), zone, duration, f); 482 parent, new _ZoneDelegate(parent.parent), zone, duration, f);
513 } 483 }
514 484
515 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { 485 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 } 644 }
675 645
676 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { 646 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) {
677 return new _ZoneDelegate(this).registerBinaryCallback(this, f); 647 return new _ZoneDelegate(this).registerBinaryCallback(this, f);
678 } 648 }
679 649
680 void scheduleMicrotask(void f()) { 650 void scheduleMicrotask(void f()) {
681 new _ZoneDelegate(this).scheduleMicrotask(this, f); 651 new _ZoneDelegate(this).scheduleMicrotask(this, f);
682 } 652 }
683 653
684 @deprecated
685 void runAsync(void f()) {
686 scheduleMicrotask(f);
687 }
688
689 Timer createTimer(Duration duration, void f()) { 654 Timer createTimer(Duration duration, void f()) {
690 return new _ZoneDelegate(this).createTimer(this, duration, f); 655 return new _ZoneDelegate(this).createTimer(this, duration, f);
691 } 656 }
692 657
693 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { 658 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) {
694 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f); 659 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f);
695 } 660 }
696 661
697 void print(String line) { 662 void print(String line) {
698 new _ZoneDelegate(this).print(this, line); 663 new _ZoneDelegate(this).print(this, line);
699 } 664 }
700 } 665 }
701 666
702 void _rootHandleUncaughtError( 667 void _rootHandleUncaughtError(
703 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { 668 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) {
704 self.run(() { 669 self.run(() {
705 _scheduleAsyncCallback(() { 670 _scheduleAsyncCallback(() {
706 print("Uncaught Error: ${error}"); 671 print("Uncaught Error: ${error}");
707 var trace = stackTrace; 672 var trace = stackTrace;
708 if (trace == null) trace = getAttachedStackTrace(error); 673 if (trace == null && error is Error) trace = error.stackTrace;
709 // Clear the attached stack trace (if any).
710 _attachStackTrace(error, null);
711 if (trace != null) { 674 if (trace != null) {
712 print("Stack Trace: \n$trace\n"); 675 print("Stack Trace: \n$trace\n");
713 } 676 }
714 throw error; 677 throw error;
715 }); 678 });
716 }); 679 });
717 } 680 }
718 681
719 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { 682 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) {
720 if (Zone._current == zone) return f(); 683 if (Zone._current == zone) return f();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 737
775 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, 738 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone,
776 Duration duration, void callback()) { 739 Duration duration, void callback()) {
777 return _createTimer(duration, callback); 740 return _createTimer(duration, callback);
778 } 741 }
779 742
780 Timer _rootCreatePeriodicTimer( 743 Timer _rootCreatePeriodicTimer(
781 Zone self, ZoneDelegate parent, Zone zone, 744 Zone self, ZoneDelegate parent, Zone zone,
782 Duration duration, void callback(Timer timer)) { 745 Duration duration, void callback(Timer timer)) {
783 return _createPeriodicTimer(duration, callback); 746 return _createPeriodicTimer(duration, callback);
747
784 } 748 }
785
786 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { 749 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) {
787 printToConsole(line); 750 printToConsole(line);
788 } 751 }
789 752
790 void _printToZone(String line) { 753 void _printToZone(String line) {
791 Zone.current.print(line); 754 Zone.current.print(line);
792 } 755 }
793 756
794 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, 757 Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone,
795 ZoneSpecification specification, 758 ZoneSpecification specification,
(...skipping 28 matching lines...) Expand all
824 _rootHandleUncaughtError; 787 _rootHandleUncaughtError;
825 RunHandler get run => _rootRun; 788 RunHandler get run => _rootRun;
826 RunUnaryHandler get runUnary => _rootRunUnary; 789 RunUnaryHandler get runUnary => _rootRunUnary;
827 RunBinaryHandler get runBinary => _rootRunBinary; 790 RunBinaryHandler get runBinary => _rootRunBinary;
828 RegisterCallbackHandler get registerCallback => _rootRegisterCallback; 791 RegisterCallbackHandler get registerCallback => _rootRegisterCallback;
829 RegisterUnaryCallbackHandler get registerUnaryCallback => 792 RegisterUnaryCallbackHandler get registerUnaryCallback =>
830 _rootRegisterUnaryCallback; 793 _rootRegisterUnaryCallback;
831 RegisterBinaryCallbackHandler get registerBinaryCallback => 794 RegisterBinaryCallbackHandler get registerBinaryCallback =>
832 _rootRegisterBinaryCallback; 795 _rootRegisterBinaryCallback;
833 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; 796 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask;
834 @deprecated
835 RunAsyncHandler get runAsync => null;
836 CreateTimerHandler get createTimer => _rootCreateTimer; 797 CreateTimerHandler get createTimer => _rootCreateTimer;
837 CreatePeriodicTimerHandler get createPeriodicTimer => 798 CreatePeriodicTimerHandler get createPeriodicTimer =>
838 _rootCreatePeriodicTimer; 799 _rootCreatePeriodicTimer;
839 PrintHandler get print => _rootPrint; 800 PrintHandler get print => _rootPrint;
840 ForkHandler get fork => _rootFork; 801 ForkHandler get fork => _rootFork;
841 } 802 }
842 803
843 class _RootZone extends _BaseZone { 804 class _RootZone extends _BaseZone {
844 const _RootZone(); 805 const _RootZone();
845 806
(...skipping 26 matching lines...) Expand all
872 ZoneUnaryCallback registerUnaryCallback(f(arg)) => 833 ZoneUnaryCallback registerUnaryCallback(f(arg)) =>
873 _rootRegisterUnaryCallback(this, null, this, f); 834 _rootRegisterUnaryCallback(this, null, this, f);
874 835
875 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => 836 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) =>
876 _rootRegisterBinaryCallback(this, null, this, f); 837 _rootRegisterBinaryCallback(this, null, this, f);
877 838
878 void scheduleMicrotask(void f()) { 839 void scheduleMicrotask(void f()) {
879 _rootScheduleMicrotask(this, null, this, f); 840 _rootScheduleMicrotask(this, null, this, f);
880 } 841 }
881 842
882 @deprecated
883 void runAsync(void f()) {
884 scheduleMicrotask(f);
885 }
886
887 Timer createTimer(Duration duration, void f()) => 843 Timer createTimer(Duration duration, void f()) =>
888 _rootCreateTimer(this, null, this, duration, f); 844 _rootCreateTimer(this, null, this, duration, f);
889 845
890 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) => 846 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) =>
891 _rootCreatePeriodicTimer(this, null, this, duration, f); 847 _rootCreatePeriodicTimer(this, null, this, duration, f);
892 848
893 void print(String line) => _rootPrint(this, null, this, line); 849 void print(String line) => _rootPrint(this, null, this, line);
894 } 850 }
895 851
896 const _ROOT_ZONE = const _RootZone(); 852 const _ROOT_ZONE = const _RootZone();
897 853
898 854
899 /** 855 /**
900 * Runs [body] in its own zone. 856 * Runs [body] in its own zone.
901 * 857 *
902 * If [onError] is non-null the zone is considered an error zone. All uncaught 858 * If [onError] is non-null the zone is considered an error zone. All uncaught
903 * errors, synchronous or asynchronous, in the zone are caught and handled 859 * errors, synchronous or asynchronous, in the zone are caught and handled
904 * by the callback. 860 * by the callback.
905 * 861 *
906 * Errors may never cross error-zone boundaries. This is intuitive for leaving 862 * Errors may never cross error-zone boundaries. This is intuitive for leaving
907 * a zone, but it also applies for errors that would enter an error-zone. 863 * a zone, but it also applies for errors that would enter an error-zone.
908 * Errors that try to cross error-zone boundaries are considered uncaught. 864 * Errors that try to cross error-zone boundaries are considered uncaught.
909 * 865 *
910 * var future = new Future.value(499); 866 * var future = new Future.value(499);
911 * runZonedExperimental(() { 867 * runZoned(() {
912 * future = future.then((_) { throw "error in first error-zone"; }); 868 * future = future.then((_) { throw "error in first error-zone"; });
913 * runZonedExperimental(() { 869 * runZoned(() {
914 * future = future.catchError((e) { print("Never reached!"); }); 870 * future = future.catchError((e) { print("Never reached!"); });
915 * }, onError: (e) { print("unused error handler"); }); 871 * }, onError: (e) { print("unused error handler"); });
916 * }, onError: (e) { print("catches error of first error-zone."); }); 872 * }, onError: (e) { print("catches error of first error-zone."); });
917 * 873 *
918 * Example: 874 * Example:
919 * 875 *
920 * runZonedExperimental(() { 876 * runZoned(() {
921 * new Future(() { throw "asynchronous error"; }); 877 * new Future(() { throw "asynchronous error"; });
922 * }, onError: print); // Will print "asynchronous error". 878 * }, onError: print); // Will print "asynchronous error".
923 */ 879 */
924 dynamic runZoned(body(), 880 dynamic runZoned(body(),
925 { Map<Symbol, dynamic> zoneValues, 881 { Map<Symbol, dynamic> zoneValues,
926 ZoneSpecification zoneSpecification, 882 ZoneSpecification zoneSpecification,
927 Function onError }) { 883 Function onError }) {
928 HandleUncaughtErrorHandler errorHandler; 884 HandleUncaughtErrorHandler errorHandler;
929 if (onError != null) { 885 if (onError != null) {
930 errorHandler = (Zone self, ZoneDelegate parent, Zone zone, 886 errorHandler = (Zone self, ZoneDelegate parent, Zone zone,
(...skipping 21 matching lines...) Expand all
952 handleUncaughtError: errorHandler); 908 handleUncaughtError: errorHandler);
953 } 909 }
954 Zone zone = Zone.current.fork(specification: zoneSpecification, 910 Zone zone = Zone.current.fork(specification: zoneSpecification,
955 zoneValues: zoneValues); 911 zoneValues: zoneValues);
956 if (onError != null) { 912 if (onError != null) {
957 return zone.runGuarded(body); 913 return zone.runGuarded(body);
958 } else { 914 } else {
959 return zone.run(body); 915 return zone.run(body);
960 } 916 }
961 } 917 }
962
963 /**
964 * Deprecated. Use `runZoned` instead or create your own [ZoneSpecification].
965 *
966 * The [onScheduleMicrotask] handler (if non-null) is invoked when the [body]
967 * executes [scheduleMicrotask]. The handler is invoked in the outer zone and
968 * can therefore execute [scheduleMicrotask] without recursing. The given
969 * callback must be executed eventually. Otherwise the nested zone will not
970 * complete. It must be executed only once.
971 *
972 * The following example prints the stack trace whenever a callback is
973 * registered using [scheduleMicrotask] (which is also used by [Completer]s and
974 * [StreamController]s.
975 *
976 * printStackTrace() { try { throw 0; } catch(e, s) { print(s); } }
977 * runZonedExperimental(body, onRunAsync: (callback) {
978 * printStackTrace();
979 * scheduleMicrotask(callback);
980 * });
981 *
982 * Note: the `onDone` handler is ignored.
983 */
984 @deprecated
985 runZonedExperimental(body(),
986 { void onRunAsync(void callback()),
987 void onError(error),
988 void onDone() }) {
989 if (onRunAsync == null) {
990 return runZoned(body, onError: onError);
991 }
992 HandleUncaughtErrorHandler errorHandler;
993 if (onError != null) {
994 errorHandler = (Zone self, ZoneDelegate parent, Zone zone,
995 error, StackTrace stackTrace) {
996 try {
997 return self.parent.runUnary(onError, error);
998 } catch(e, s) {
999 if (identical(e, error)) {
1000 return parent.handleUncaughtError(zone, error, stackTrace);
1001 } else {
1002 return parent.handleUncaughtError(zone, _asyncError(e, s), s);
1003 }
1004 }
1005 };
1006 }
1007 ScheduleMicrotaskHandler asyncHandler;
1008 if (onRunAsync != null) {
1009 asyncHandler = (Zone self, ZoneDelegate parent, Zone zone, f()) {
1010 self.parent.runUnary(onRunAsync, () => zone.runGuarded(f));
1011 };
1012 }
1013 ZoneSpecification specification =
1014 new ZoneSpecification(handleUncaughtError: errorHandler,
1015 scheduleMicrotask: asyncHandler);
1016 Zone zone = Zone.current.fork(specification: specification);
1017 if (onError != null) {
1018 return zone.runGuarded(body);
1019 } else {
1020 return zone.run(body);
1021 }
1022 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_transformers.dart ('k') | tests/lib/async/intercept_schedule_microtask6_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698