OLD | NEW |
---|---|
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 Object TaskCreate(TaskSpecification taskSpecification, Zone zone); | |
12 typedef void TaskCancel(Object task); | |
13 typedef void TaskRun(Object task, Object arg); | |
14 | |
11 typedef dynamic HandleUncaughtErrorHandler( | 15 typedef dynamic HandleUncaughtErrorHandler( |
12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); | 16 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); |
13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); | 17 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); |
14 typedef dynamic RunUnaryHandler( | 18 typedef dynamic RunUnaryHandler( |
15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); | 19 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); |
16 typedef dynamic RunBinaryHandler( | 20 typedef dynamic RunBinaryHandler( |
17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); | 21 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); |
18 typedef ZoneCallback RegisterCallbackHandler( | 22 typedef ZoneCallback RegisterCallbackHandler( |
19 Zone self, ZoneDelegate parent, Zone zone, f()); | 23 Zone self, ZoneDelegate parent, Zone zone, f()); |
20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( | 24 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( |
21 Zone self, ZoneDelegate parent, Zone zone, f(arg)); | 25 Zone self, ZoneDelegate parent, Zone zone, f(arg)); |
22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( | 26 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( |
23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); | 27 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); |
24 typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, | 28 typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, |
25 Zone zone, Object error, StackTrace stackTrace); | 29 Zone zone, Object error, StackTrace stackTrace); |
30 typedef Object CreateTaskHandler(Zone self, ZoneDelegate parent, Zone zone, | |
31 TaskSpecification taskSpecification, TaskCreate schedule); | |
Lasse Reichstein Nielsen
2016/05/18 11:40:55
schedule -> create.
| |
32 typedef void CancelTaskHandler(Zone self, ZoneDelegate parent, Zone zone, | |
33 Object task, TaskCancel cancel); | |
34 typedef void RunTaskHandler(Zone self, ZoneDelegate parent, Zone zone, | |
35 Object task, Object arg1, TaskRun run); | |
26 typedef void ScheduleMicrotaskHandler( | 36 typedef void ScheduleMicrotaskHandler( |
27 Zone self, ZoneDelegate parent, Zone zone, f()); | 37 Zone self, ZoneDelegate parent, Zone zone, f()); |
28 typedef Timer CreateTimerHandler( | |
29 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); | |
30 typedef Timer CreatePeriodicTimerHandler( | |
31 Zone self, ZoneDelegate parent, Zone zone, | |
32 Duration period, void f(Timer timer)); | |
33 typedef void PrintHandler( | 38 typedef void PrintHandler( |
34 Zone self, ZoneDelegate parent, Zone zone, String line); | 39 Zone self, ZoneDelegate parent, Zone zone, String line); |
35 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, | 40 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, |
36 ZoneSpecification specification, | 41 ZoneSpecification specification, |
37 Map zoneValues); | 42 Map zoneValues); |
38 | 43 |
44 // Typedefs for deprecated methods. | |
45 typedef Timer CreateTimerHandler( | |
46 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); | |
47 typedef Timer CreatePeriodicTimerHandler( | |
48 Zone self, ZoneDelegate parent, Zone zone, | |
49 Duration period, void f(Timer timer)); | |
50 | |
39 /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ | 51 /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ |
40 class AsyncError implements Error { | 52 class AsyncError implements Error { |
41 final error; | 53 final error; |
42 final StackTrace stackTrace; | 54 final StackTrace stackTrace; |
43 | 55 |
44 AsyncError(this.error, this.stackTrace); | 56 AsyncError(this.error, this.stackTrace); |
45 | 57 |
46 String toString() => '$error'; | 58 String toString() => '$error'; |
47 } | 59 } |
48 | 60 |
61 abstract class TaskSpecification { | |
62 /// Description of the task. | |
63 /// | |
64 /// This string is unused by the root-zone, but might be used for debugging, | |
65 /// and testing. As such, it should be relatively unique in its category. | |
66 String get name; | |
67 | |
68 /// Whether the scheduled task triggers at most once. | |
69 /// | |
70 /// If the task is not a one-shot task, it may need to be canceled to prevent | |
71 /// further iterations of the task. | |
72 bool get isOneShot; | |
73 } | |
74 | |
75 class _TimerTaskWrapper implements Timer { | |
76 final TimerTask _task; | |
77 | |
78 _TimerTaskWrapper(this._task); | |
79 | |
80 static _cancel(TimerTask task) { | |
81 task.timer.cancel(); | |
82 } | |
83 | |
84 void cancel() { | |
85 _task.zone.cancelTask(_task, _cancel); | |
86 } | |
87 | |
88 bool get isActive => _task.timer.isActive; | |
89 } | |
90 | |
91 abstract class TimerTask { | |
Lasse Reichstein Nielsen
2016/05/18 11:40:55
Maybe document the class - where is it used, what
| |
92 final Zone zone; | |
93 /// The native timer. | |
94 final Timer timer; | |
95 | |
96 TimerTask(this.timer, this.zone); | |
97 } | |
98 | |
99 class SingleShotTimerTask extends TimerTask { | |
Lasse Reichstein Nielsen
2016/05/18 11:40:55
Consider moving the timer-specific classes to the
| |
100 final ZoneCallback callback; | |
101 | |
102 SingleShotTimerTask(Timer timer, this.callback, Zone zone) | |
103 : super(timer, zone); | |
104 } | |
105 | |
106 class PeriodicTimerTask extends TimerTask { | |
107 final ZoneUnaryCallback callback; | |
108 | |
109 PeriodicTimerTask(Timer timer, this.callback, Zone zone) | |
110 : super(timer, zone); | |
111 } | |
112 | |
113 class SingleShotTimerTaskSpecification implements TaskSpecification { | |
114 final Duration duration; | |
115 final ZoneCallback callback; | |
116 | |
117 SingleShotTimerTaskSpecification(this.duration, void this.callback()); | |
118 | |
119 String get name => "Timer"; | |
120 bool get isOneShot => true; | |
121 bool get isEventTask => false; | |
122 bool get isMacroTask => true; | |
123 } | |
124 | |
125 class PeriodicTimerTaskSpecification implements TaskSpecification { | |
126 final Duration duration; | |
127 final ZoneUnaryCallback callback; | |
128 | |
129 PeriodicTimerTaskSpecification( | |
130 this.duration, void this.callback(Timer timer)); | |
131 | |
132 String get name => "Periodic Timer"; | |
133 bool get isOneShot => false; | |
134 bool get isEventTask => false; | |
135 bool get isMacroTask => true; | |
136 } | |
49 | 137 |
50 class _ZoneFunction { | 138 class _ZoneFunction { |
51 final _Zone zone; | 139 final _Zone zone; |
52 final Function function; | 140 final Function function; |
141 | |
53 const _ZoneFunction(this.zone, this.function); | 142 const _ZoneFunction(this.zone, this.function); |
54 } | 143 } |
55 | 144 |
56 /** | 145 /** |
57 * This class provides the specification for a forked zone. | 146 * This class provides the specification for a forked zone. |
58 * | 147 * |
59 * When forking a new zone (see [Zone.fork]) one can override the default | 148 * When forking a new zone (see [Zone.fork]) one can override the default |
60 * behavior of the zone by providing callbacks. These callbacks must be | 149 * behavior of the zone by providing callbacks. These callbacks must be |
61 * given in an instance of this class. | 150 * given in an instance of this class. |
62 * | 151 * |
(...skipping 24 matching lines...) Expand all Loading... | |
87 ZoneCallback registerCallback( | 176 ZoneCallback registerCallback( |
88 Zone self, ZoneDelegate parent, Zone zone, f()), | 177 Zone self, ZoneDelegate parent, Zone zone, f()), |
89 ZoneUnaryCallback registerUnaryCallback( | 178 ZoneUnaryCallback registerUnaryCallback( |
90 Zone self, ZoneDelegate parent, Zone zone, f(arg)), | 179 Zone self, ZoneDelegate parent, Zone zone, f(arg)), |
91 ZoneBinaryCallback registerBinaryCallback( | 180 ZoneBinaryCallback registerBinaryCallback( |
92 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), | 181 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), |
93 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, | 182 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, |
94 Object error, StackTrace stackTrace), | 183 Object error, StackTrace stackTrace), |
95 void scheduleMicrotask( | 184 void scheduleMicrotask( |
96 Zone self, ZoneDelegate parent, Zone zone, f()), | 185 Zone self, ZoneDelegate parent, Zone zone, f()), |
186 Object createTask(Zone self, ZoneDelegate parent, Zone zone, | |
187 TaskSpecification taskSpecification, TaskCreate create), | |
188 void runTask(Zone self, ZoneDelegate parent, Zone zone, Object task, | |
189 Object arg, TaskRun run), | |
190 void cancelTask(Zone self, ZoneDelegate parent, Zone zone, Object task, | |
191 TaskCancel cancel), | |
192 | |
193 void print(Zone self, ZoneDelegate parent, Zone zone, String line), | |
194 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | |
195 ZoneSpecification specification, Map zoneValues), | |
196 | |
197 @deprecated | |
97 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | 198 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
98 Duration duration, void f()), | 199 Duration duration, void f()), |
200 @deprecated | |
99 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | 201 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
100 Duration period, void f(Timer timer)), | 202 Duration period, void f(Timer timer)) |
101 void print(Zone self, ZoneDelegate parent, Zone zone, String line), | |
102 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | |
103 ZoneSpecification specification, Map zoneValues) | |
104 }) = _ZoneSpecification; | 203 }) = _ZoneSpecification; |
105 | 204 |
106 /** | 205 /** |
107 * Creates a specification from [other] with the provided handlers overriding | 206 * Creates a specification from [other] with the provided handlers overriding |
108 * the ones in [other]. | 207 * the ones in [other]. |
109 */ | 208 */ |
110 factory ZoneSpecification.from(ZoneSpecification other, { | 209 factory ZoneSpecification.from(ZoneSpecification other, { |
111 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, | 210 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, |
112 error, StackTrace stackTrace): null, | 211 error, StackTrace stackTrace): null, |
113 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, | 212 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, |
114 dynamic runUnary( | 213 dynamic runUnary( |
115 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, | 214 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, |
116 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, | 215 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, |
117 f(arg1, arg2), arg1, arg2): null, | 216 f(arg1, arg2), arg1, arg2): null, |
118 ZoneCallback registerCallback( | 217 ZoneCallback registerCallback( |
119 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 218 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
120 ZoneUnaryCallback registerUnaryCallback( | 219 ZoneUnaryCallback registerUnaryCallback( |
121 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, | 220 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, |
122 ZoneBinaryCallback registerBinaryCallback( | 221 ZoneBinaryCallback registerBinaryCallback( |
123 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, | 222 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, |
124 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, | 223 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, |
125 Object error, StackTrace stackTrace), | 224 Object error, StackTrace stackTrace), |
126 void scheduleMicrotask( | 225 void scheduleMicrotask( |
127 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 226 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
128 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | 227 |
129 Duration duration, void f()): null, | 228 Object createTask(Zone self, ZoneDelegate parent, Zone zone, |
130 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | 229 TaskSpecification taskSpecification, TaskCreate create): null, |
131 Duration period, void f(Timer timer)): null, | 230 void runTask(Zone self, ZoneDelegate parent, Zone zone, Object task, |
231 TaskRun run): null, | |
232 void cancelTask(Zone self, ZoneDelegate parent, Zone zone, Object task, | |
233 TaskCancel cancel): null, | |
234 | |
132 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, | 235 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, |
133 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | 236 Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
134 ZoneSpecification specification, | 237 ZoneSpecification specification, |
135 Map zoneValues): null | 238 Map zoneValues): null, |
239 | |
240 @deprecated | |
241 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | |
242 Duration duration, void f()): null, | |
243 @deprecated | |
244 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | |
245 Duration period, void f(Timer timer)): null | |
136 }) { | 246 }) { |
137 return new ZoneSpecification( | 247 return new ZoneSpecification( |
138 handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError, | 248 handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError, |
139 run: run ?? other.run, | 249 run: run ?? other.run, |
140 runUnary: runUnary ?? other.runUnary, | 250 runUnary: runUnary ?? other.runUnary, |
141 runBinary: runBinary ?? other.runBinary, | 251 runBinary: runBinary ?? other.runBinary, |
142 registerCallback: registerCallback ?? other.registerCallback, | 252 registerCallback: registerCallback ?? other.registerCallback, |
143 registerUnaryCallback: registerUnaryCallback ?? | 253 registerUnaryCallback: registerUnaryCallback ?? |
144 other.registerUnaryCallback, | 254 other.registerUnaryCallback, |
145 registerBinaryCallback: registerBinaryCallback ?? | 255 registerBinaryCallback: registerBinaryCallback ?? |
146 other.registerBinaryCallback, | 256 other.registerBinaryCallback, |
147 errorCallback: errorCallback ?? other.errorCallback, | 257 errorCallback: errorCallback ?? other.errorCallback, |
258 | |
259 createTask: createTask ?? other.createTask, | |
260 runTask: runTask ?? other.runTask, | |
261 cancelTask: cancelTask ?? other.cancelTask, | |
262 print : print ?? other.print, | |
263 fork: fork ?? other.fork, | |
148 scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask, | 264 scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask, |
149 createTimer : createTimer ?? other.createTimer, | 265 createTimer : createTimer ?? other.createTimer, |
150 createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer, | 266 createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer); |
151 print : print ?? other.print, | |
152 fork: fork ?? other.fork); | |
153 } | 267 } |
154 | 268 |
155 HandleUncaughtErrorHandler get handleUncaughtError; | 269 HandleUncaughtErrorHandler get handleUncaughtError; |
156 RunHandler get run; | 270 RunHandler get run; |
157 RunUnaryHandler get runUnary; | 271 RunUnaryHandler get runUnary; |
158 RunBinaryHandler get runBinary; | 272 RunBinaryHandler get runBinary; |
159 RegisterCallbackHandler get registerCallback; | 273 RegisterCallbackHandler get registerCallback; |
160 RegisterUnaryCallbackHandler get registerUnaryCallback; | 274 RegisterUnaryCallbackHandler get registerUnaryCallback; |
161 RegisterBinaryCallbackHandler get registerBinaryCallback; | 275 RegisterBinaryCallbackHandler get registerBinaryCallback; |
162 ErrorCallbackHandler get errorCallback; | 276 ErrorCallbackHandler get errorCallback; |
163 ScheduleMicrotaskHandler get scheduleMicrotask; | 277 ScheduleMicrotaskHandler get scheduleMicrotask; |
164 CreateTimerHandler get createTimer; | 278 CreateTaskHandler get createTask; |
165 CreatePeriodicTimerHandler get createPeriodicTimer; | 279 RunTaskHandler get runTask; |
280 CancelTaskHandler get cancelTask; | |
166 PrintHandler get print; | 281 PrintHandler get print; |
167 ForkHandler get fork; | 282 ForkHandler get fork; |
283 | |
284 @deprecated | |
285 CreateTimerHandler get createTimer; | |
286 @deprecated | |
287 CreatePeriodicTimerHandler get createPeriodicTimer; | |
168 } | 288 } |
169 | 289 |
170 /** | 290 /** |
171 * Internal [ZoneSpecification] class. | 291 * Internal [ZoneSpecification] class. |
172 * | 292 * |
173 * The implementation wants to rely on the fact that the getters cannot change | 293 * The implementation wants to rely on the fact that the getters cannot change |
174 * dynamically. We thus require users to go through the redirecting | 294 * dynamically. We thus require users to go through the redirecting |
175 * [ZoneSpecification] constructor which instantiates this class. | 295 * [ZoneSpecification] constructor which instantiates this class. |
176 */ | 296 */ |
177 class _ZoneSpecification implements ZoneSpecification { | 297 class _ZoneSpecification implements ZoneSpecification { |
178 const _ZoneSpecification({ | 298 const _ZoneSpecification({ |
179 this.handleUncaughtError: null, | 299 this.handleUncaughtError: null, |
180 this.run: null, | 300 this.run: null, |
181 this.runUnary: null, | 301 this.runUnary: null, |
182 this.runBinary: null, | 302 this.runBinary: null, |
183 this.registerCallback: null, | 303 this.registerCallback: null, |
184 this.registerUnaryCallback: null, | 304 this.registerUnaryCallback: null, |
185 this.registerBinaryCallback: null, | 305 this.registerBinaryCallback: null, |
186 this.errorCallback: null, | 306 this.errorCallback: null, |
187 this.scheduleMicrotask: null, | 307 this.scheduleMicrotask: null, |
308 this.createTask: null, | |
309 this.runTask: null, | |
310 this.cancelTask: null, | |
311 this.print: null, | |
312 this.fork: null, | |
313 @deprecated | |
188 this.createTimer: null, | 314 this.createTimer: null, |
189 this.createPeriodicTimer: null, | 315 @deprecated |
190 this.print: null, | 316 this.createPeriodicTimer: null |
191 this.fork: null | |
192 }); | 317 }); |
193 | 318 |
194 final HandleUncaughtErrorHandler handleUncaughtError; | 319 final HandleUncaughtErrorHandler handleUncaughtError; |
195 final RunHandler run; | 320 final RunHandler run; |
196 final RunUnaryHandler runUnary; | 321 final RunUnaryHandler runUnary; |
197 final RunBinaryHandler runBinary; | 322 final RunBinaryHandler runBinary; |
198 final RegisterCallbackHandler registerCallback; | 323 final RegisterCallbackHandler registerCallback; |
199 final RegisterUnaryCallbackHandler registerUnaryCallback; | 324 final RegisterUnaryCallbackHandler registerUnaryCallback; |
200 final RegisterBinaryCallbackHandler registerBinaryCallback; | 325 final RegisterBinaryCallbackHandler registerBinaryCallback; |
201 final ErrorCallbackHandler errorCallback; | 326 final ErrorCallbackHandler errorCallback; |
202 final ScheduleMicrotaskHandler scheduleMicrotask; | 327 final ScheduleMicrotaskHandler scheduleMicrotask; |
203 final CreateTimerHandler createTimer; | 328 final CreateTaskHandler createTask; |
204 final CreatePeriodicTimerHandler createPeriodicTimer; | 329 final RunTaskHandler runTask; |
330 final CancelTaskHandler cancelTask; | |
205 final PrintHandler print; | 331 final PrintHandler print; |
206 final ForkHandler fork; | 332 final ForkHandler fork; |
333 | |
334 @deprecated | |
335 final CreateTimerHandler createTimer; | |
336 @deprecated | |
337 final CreatePeriodicTimerHandler createPeriodicTimer; | |
207 } | 338 } |
208 | 339 |
209 /** | 340 /** |
210 * This class wraps zones for delegation. | 341 * This class wraps zones for delegation. |
211 * | 342 * |
212 * When forwarding to parent zones one can't just invoke the parent zone's | 343 * 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 | 344 * exposed functions (like [Zone.run]), but one needs to provide more |
214 * information (like the zone the `run` was initiated). Zone callbacks thus | 345 * information (like the zone the `run` was initiated). Zone callbacks thus |
215 * receive more information including this [ZoneDelegate] class. When delegating | 346 * receive more information including this [ZoneDelegate] class. When delegating |
216 * to the parent zone one should go through the given instance instead of | 347 * to the parent zone one should go through the given instance instead of |
217 * directly invoking the parent zone. | 348 * directly invoking the parent zone. |
218 */ | 349 */ |
219 abstract class ZoneDelegate { | 350 abstract class ZoneDelegate { |
220 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); | 351 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); |
221 dynamic run(Zone zone, f()); | 352 dynamic run(Zone zone, f()); |
222 dynamic runUnary(Zone zone, f(arg), arg); | 353 dynamic runUnary(Zone zone, f(arg), arg); |
223 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); | 354 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); |
224 ZoneCallback registerCallback(Zone zone, f()); | 355 ZoneCallback registerCallback(Zone zone, f()); |
225 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); | 356 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); |
226 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); | 357 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); |
227 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); | 358 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); |
228 void scheduleMicrotask(Zone zone, f()); | 359 void scheduleMicrotask(Zone zone, f()); |
229 Timer createTimer(Zone zone, Duration duration, void f()); | 360 Object createTask(Zone zone, TaskSpecification task, TaskCreate schedule); |
230 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); | 361 void runTask(Zone zone, Object task, Object arg, TaskRun run); |
362 void cancelTask(Zone zone, Object task, TaskCancel cancel); | |
231 void print(Zone zone, String line); | 363 void print(Zone zone, String line); |
232 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); | 364 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); |
365 | |
366 @deprecated | |
367 Timer createTimer(Zone zone, Duration duration, void f()); | |
368 @deprecated | |
369 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); | |
233 } | 370 } |
234 | 371 |
235 /** | 372 /** |
236 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous | 373 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous |
237 * callbacks are executed in the zone they have been queued in. For example, | 374 * callbacks are executed in the zone they have been queued in. For example, |
238 * the callback of a `future.then` is executed in the same zone as the one where | 375 * the callback of a `future.then` is executed in the same zone as the one where |
239 * the `then` was invoked. | 376 * the `then` was invoked. |
240 */ | 377 */ |
241 abstract class Zone { | 378 abstract class Zone { |
242 // Private constructor so that it is not possible instantiate a Zone class. | 379 // Private constructor so that it is not possible instantiate a Zone class. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 * the new pair of error and stack trace. | 543 * the new pair of error and stack trace. |
407 * If the [AsyncError.error] is `null`, it is replaced by a [NullThrownError]. | 544 * If the [AsyncError.error] is `null`, it is replaced by a [NullThrownError]. |
408 */ | 545 */ |
409 AsyncError errorCallback(Object error, StackTrace stackTrace); | 546 AsyncError errorCallback(Object error, StackTrace stackTrace); |
410 | 547 |
411 /** | 548 /** |
412 * Runs [f] asynchronously in this zone. | 549 * Runs [f] asynchronously in this zone. |
413 */ | 550 */ |
414 void scheduleMicrotask(void f()); | 551 void scheduleMicrotask(void f()); |
415 | 552 |
553 Object createTask(TaskSpecification task, TaskCreate create); | |
554 void runTask(Object task, Object arg1, TaskRun run); | |
555 void cancelTask(Object task, TaskCancel cancel); | |
556 | |
416 /** | 557 /** |
417 * Creates a Timer where the callback is executed in this zone. | 558 * Creates a Timer where the callback is executed in this zone. |
418 */ | 559 */ |
560 @deprecated | |
419 Timer createTimer(Duration duration, void callback()); | 561 Timer createTimer(Duration duration, void callback()); |
420 | 562 |
421 /** | 563 /** |
422 * Creates a periodic Timer where the callback is executed in this zone. | 564 * Creates a periodic Timer where the callback is executed in this zone. |
423 */ | 565 */ |
566 @deprecated | |
424 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); | 567 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); |
425 | 568 |
426 /** | 569 /** |
427 * Prints the given [line]. | 570 * Prints the given [line]. |
428 */ | 571 */ |
429 void print(String line); | 572 void print(String line); |
430 | 573 |
431 /** | 574 /** |
432 * Call to enter the Zone. | 575 * Call to enter the Zone. |
433 * | 576 * |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 error, stackTrace); | 679 error, stackTrace); |
537 } | 680 } |
538 | 681 |
539 void scheduleMicrotask(Zone zone, f()) { | 682 void scheduleMicrotask(Zone zone, f()) { |
540 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; | 683 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; |
541 _Zone implZone = implementation.zone; | 684 _Zone implZone = implementation.zone; |
542 ScheduleMicrotaskHandler handler = implementation.function; | 685 ScheduleMicrotaskHandler handler = implementation.function; |
543 handler(implZone, _parentDelegate(implZone), zone, f); | 686 handler(implZone, _parentDelegate(implZone), zone, f); |
544 } | 687 } |
545 | 688 |
546 Timer createTimer(Zone zone, Duration duration, void f()) { | 689 Object createTask(Zone zone, TaskSpecification task, TaskCreate create) { |
547 _ZoneFunction implementation = _delegationTarget._createTimer; | 690 _ZoneFunction implementation = _delegationTarget._createTask; |
548 _Zone implZone = implementation.zone; | 691 _Zone implZone = implementation.zone; |
549 CreateTimerHandler handler = implementation.function; | 692 CreateTaskHandler handler = implementation.function; |
550 return handler(implZone, _parentDelegate(implZone), zone, duration, f); | 693 return handler(implZone, _parentDelegate(implZone), zone, task, create); |
551 } | 694 } |
552 | 695 |
553 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { | 696 void runTask(Zone zone, Object task, Object arg, TaskRun run) { |
554 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; | 697 _ZoneFunction implementation = _delegationTarget._runTask; |
555 _Zone implZone = implementation.zone; | 698 _Zone implZone = implementation.zone; |
556 CreatePeriodicTimerHandler handler = implementation.function; | 699 RunTaskHandler handler = implementation.function; |
557 return handler(implZone, _parentDelegate(implZone), zone, period, f); | 700 handler(implZone, _parentDelegate(implZone), zone, task, arg, run); |
701 } | |
702 | |
703 void cancelTask(Zone zone, Object task, TaskCancel cancel) { | |
704 _ZoneFunction implementation = _delegationTarget._cancelTask; | |
705 _Zone implZone = implementation.zone; | |
706 CancelTaskHandler handler = implementation.function; | |
707 handler(implZone, _parentDelegate(implZone), zone, task, cancel); | |
558 } | 708 } |
559 | 709 |
560 void print(Zone zone, String line) { | 710 void print(Zone zone, String line) { |
561 _ZoneFunction implementation = _delegationTarget._print; | 711 _ZoneFunction implementation = _delegationTarget._print; |
562 _Zone implZone = implementation.zone; | 712 _Zone implZone = implementation.zone; |
563 PrintHandler handler = implementation.function; | 713 PrintHandler handler = implementation.function; |
564 handler(implZone, _parentDelegate(implZone), zone, line); | 714 handler(implZone, _parentDelegate(implZone), zone, line); |
565 } | 715 } |
566 | 716 |
567 Zone fork(Zone zone, ZoneSpecification specification, | 717 Zone fork(Zone zone, ZoneSpecification specification, |
568 Map zoneValues) { | 718 Map zoneValues) { |
569 _ZoneFunction implementation = _delegationTarget._fork; | 719 _ZoneFunction implementation = _delegationTarget._fork; |
570 _Zone implZone = implementation.zone; | 720 _Zone implZone = implementation.zone; |
571 ForkHandler handler = implementation.function; | 721 ForkHandler handler = implementation.function; |
572 return handler( | 722 return handler( |
573 implZone, _parentDelegate(implZone), zone, specification, zoneValues); | 723 implZone, _parentDelegate(implZone), zone, specification, zoneValues); |
574 } | 724 } |
725 | |
726 @deprecated | |
727 Timer createTimer(Zone zone, Duration duration, void f()) { | |
728 _ZoneFunction implementation = _delegationTarget._createTimer; | |
729 _Zone implZone = implementation.zone; | |
730 CreateTimerHandler handler = implementation.function; | |
731 return handler(implZone, _parentDelegate(implZone), zone, duration, f); | |
732 } | |
733 | |
734 @deprecated | |
735 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { | |
736 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; | |
737 _Zone implZone = implementation.zone; | |
738 CreatePeriodicTimerHandler handler = implementation.function; | |
739 return handler(implZone, _parentDelegate(implZone), zone, period, f); | |
740 } | |
575 } | 741 } |
576 | 742 |
577 | 743 |
578 /** | 744 /** |
579 * Base class for Zone implementations. | 745 * Base class for Zone implementations. |
580 */ | 746 */ |
581 abstract class _Zone implements Zone { | 747 abstract class _Zone implements Zone { |
582 const _Zone(); | 748 const _Zone(); |
583 | 749 |
584 _ZoneFunction get _runUnary; | 750 _ZoneFunction get _runUnary; |
585 _ZoneFunction get _run; | 751 _ZoneFunction get _run; |
586 _ZoneFunction get _runBinary; | 752 _ZoneFunction get _runBinary; |
587 _ZoneFunction get _registerCallback; | 753 _ZoneFunction get _registerCallback; |
588 _ZoneFunction get _registerUnaryCallback; | 754 _ZoneFunction get _registerUnaryCallback; |
589 _ZoneFunction get _registerBinaryCallback; | 755 _ZoneFunction get _registerBinaryCallback; |
590 _ZoneFunction get _errorCallback; | 756 _ZoneFunction get _errorCallback; |
591 _ZoneFunction get _scheduleMicrotask; | 757 _ZoneFunction get _scheduleMicrotask; |
592 _ZoneFunction get _createTimer; | 758 _ZoneFunction get _createTask; |
593 _ZoneFunction get _createPeriodicTimer; | 759 _ZoneFunction get _runTask; |
760 _ZoneFunction get _cancelTask; | |
594 _ZoneFunction get _print; | 761 _ZoneFunction get _print; |
595 _ZoneFunction get _fork; | 762 _ZoneFunction get _fork; |
596 _ZoneFunction get _handleUncaughtError; | 763 _ZoneFunction get _handleUncaughtError; |
764 | |
765 @deprecated | |
766 _ZoneFunction get _createTimer; | |
767 @deprecated | |
768 _ZoneFunction get _createPeriodicTimer; | |
769 | |
597 _Zone get parent; | 770 _Zone get parent; |
598 _ZoneDelegate get _delegate; | 771 _ZoneDelegate get _delegate; |
599 Map get _map; | 772 Map get _map; |
600 | 773 |
601 bool inSameErrorZone(Zone otherZone) { | 774 bool inSameErrorZone(Zone otherZone) { |
602 return identical(this, otherZone) || | 775 return identical(this, otherZone) || |
603 identical(errorZone, otherZone.errorZone); | 776 identical(errorZone, otherZone.errorZone); |
604 } | 777 } |
605 } | 778 } |
606 | 779 |
607 class _CustomZone extends _Zone { | 780 class _CustomZone extends _Zone { |
608 // The actual zone and implementation of each of these | 781 // The actual zone and implementation of each of these |
609 // inheritable zone functions. | 782 // inheritable zone functions. |
610 _ZoneFunction _runUnary; | 783 _ZoneFunction _runUnary; |
611 _ZoneFunction _run; | 784 _ZoneFunction _run; |
612 _ZoneFunction _runBinary; | 785 _ZoneFunction _runBinary; |
613 _ZoneFunction _registerCallback; | 786 _ZoneFunction _registerCallback; |
614 _ZoneFunction _registerUnaryCallback; | 787 _ZoneFunction _registerUnaryCallback; |
615 _ZoneFunction _registerBinaryCallback; | 788 _ZoneFunction _registerBinaryCallback; |
616 _ZoneFunction _errorCallback; | 789 _ZoneFunction _errorCallback; |
617 _ZoneFunction _scheduleMicrotask; | 790 _ZoneFunction _scheduleMicrotask; |
618 _ZoneFunction _createTimer; | 791 _ZoneFunction _createTask; |
619 _ZoneFunction _createPeriodicTimer; | 792 _ZoneFunction _runTask; |
793 _ZoneFunction _cancelTask; | |
620 _ZoneFunction _print; | 794 _ZoneFunction _print; |
621 _ZoneFunction _fork; | 795 _ZoneFunction _fork; |
622 _ZoneFunction _handleUncaughtError; | 796 _ZoneFunction _handleUncaughtError; |
623 | 797 |
798 @deprecated | |
799 _ZoneFunction _createTimer; | |
800 @deprecated | |
801 _ZoneFunction _createPeriodicTimer; | |
802 | |
624 // A cached delegate to this zone. | 803 // A cached delegate to this zone. |
625 ZoneDelegate _delegateCache; | 804 ZoneDelegate _delegateCache; |
626 | 805 |
627 /// The parent zone. | 806 /// The parent zone. |
628 final _Zone parent; | 807 final _Zone parent; |
629 | 808 |
630 /// The zone's scoped value declaration map. | 809 /// The zone's scoped value declaration map. |
631 /// | 810 /// |
632 /// This is always a [HashMap]. | 811 /// This is always a [HashMap]. |
633 final Map _map; | 812 final Map _map; |
(...skipping 25 matching lines...) Expand all Loading... | |
659 : parent._registerUnaryCallback; | 838 : parent._registerUnaryCallback; |
660 _registerBinaryCallback = (specification.registerBinaryCallback != null) | 839 _registerBinaryCallback = (specification.registerBinaryCallback != null) |
661 ? new _ZoneFunction(this, specification.registerBinaryCallback) | 840 ? new _ZoneFunction(this, specification.registerBinaryCallback) |
662 : parent._registerBinaryCallback; | 841 : parent._registerBinaryCallback; |
663 _errorCallback = (specification.errorCallback != null) | 842 _errorCallback = (specification.errorCallback != null) |
664 ? new _ZoneFunction(this, specification.errorCallback) | 843 ? new _ZoneFunction(this, specification.errorCallback) |
665 : parent._errorCallback; | 844 : parent._errorCallback; |
666 _scheduleMicrotask = (specification.scheduleMicrotask != null) | 845 _scheduleMicrotask = (specification.scheduleMicrotask != null) |
667 ? new _ZoneFunction(this, specification.scheduleMicrotask) | 846 ? new _ZoneFunction(this, specification.scheduleMicrotask) |
668 : parent._scheduleMicrotask; | 847 : parent._scheduleMicrotask; |
669 _createTimer = (specification.createTimer != null) | 848 _createTask = (specification.createTask != null) |
670 ? new _ZoneFunction(this, specification.createTimer) | 849 ? new _ZoneFunction(this, specification.createTask) |
671 : parent._createTimer; | 850 : parent._createTask; |
672 _createPeriodicTimer = (specification.createPeriodicTimer != null) | 851 _runTask = (specification.runTask != null) |
673 ? new _ZoneFunction(this, specification.createPeriodicTimer) | 852 ? new _ZoneFunction(this, specification.runTask) |
674 : parent._createPeriodicTimer; | 853 : parent._runTask; |
854 _cancelTask = (specification.cancelTask != null) | |
855 ? new _ZoneFunction(this, specification.runTask) | |
856 : parent._cancelTask; | |
675 _print = (specification.print != null) | 857 _print = (specification.print != null) |
676 ? new _ZoneFunction(this, specification.print) | 858 ? new _ZoneFunction(this, specification.print) |
677 : parent._print; | 859 : parent._print; |
678 _fork = (specification.fork != null) | 860 _fork = (specification.fork != null) |
679 ? new _ZoneFunction(this, specification.fork) | 861 ? new _ZoneFunction(this, specification.fork) |
680 : parent._fork; | 862 : parent._fork; |
681 _handleUncaughtError = (specification.handleUncaughtError != null) | 863 _handleUncaughtError = (specification.handleUncaughtError != null) |
682 ? new _ZoneFunction(this, specification.handleUncaughtError) | 864 ? new _ZoneFunction(this, specification.handleUncaughtError) |
683 : parent._handleUncaughtError; | 865 : parent._handleUncaughtError; |
866 | |
867 // Deprecated fields. | |
868 _createTimer = (specification.createTimer != null) | |
869 ? new _ZoneFunction(this, specification.createTimer) | |
870 : parent._createTimer; | |
871 _createPeriodicTimer = (specification.createPeriodicTimer != null) | |
872 ? new _ZoneFunction(this, specification.createPeriodicTimer) | |
873 : parent._createPeriodicTimer; | |
684 } | 874 } |
685 | 875 |
686 /** | 876 /** |
687 * The closest error-handling zone. | 877 * The closest error-handling zone. |
688 * | 878 * |
689 * Returns `this` if `this` has an error-handler. Otherwise returns the | 879 * Returns `this` if `this` has an error-handler. Otherwise returns the |
690 * parent's error-zone. | 880 * parent's error-zone. |
691 */ | 881 */ |
692 Zone get errorZone => _handleUncaughtError.zone; | 882 Zone get errorZone => _handleUncaughtError.zone; |
693 | 883 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 ErrorCallbackHandler handler = implementation.function; | 1030 ErrorCallbackHandler handler = implementation.function; |
841 return handler( | 1031 return handler( |
842 implementationZone, parentDelegate, this, error, stackTrace); | 1032 implementationZone, parentDelegate, this, error, stackTrace); |
843 } | 1033 } |
844 | 1034 |
845 void scheduleMicrotask(void f()) { | 1035 void scheduleMicrotask(void f()) { |
846 _ZoneFunction implementation = this._scheduleMicrotask; | 1036 _ZoneFunction implementation = this._scheduleMicrotask; |
847 assert(implementation != null); | 1037 assert(implementation != null); |
848 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 1038 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
849 ScheduleMicrotaskHandler handler = implementation.function; | 1039 ScheduleMicrotaskHandler handler = implementation.function; |
850 return handler(implementation.zone, parentDelegate, this, f); | 1040 handler(implementation.zone, parentDelegate, this, f); |
851 } | 1041 } |
852 | 1042 |
1043 Object createTask(TaskSpecification task, TaskCreate create) { | |
1044 _ZoneFunction implementation = this._createTask; | |
1045 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1046 CreateTaskHandler handler = implementation.function; | |
1047 return handler(implementation.zone, parentDelegate, this, task, create); | |
1048 } | |
1049 | |
1050 void runTask(Object task, Object arg1, TaskRun run) { | |
1051 _ZoneFunction implementation = this._runTask; | |
1052 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1053 RunTaskHandler handler = implementation.function; | |
1054 handler(implementation.zone, parentDelegate, this, task, arg1, run); | |
1055 } | |
1056 | |
1057 void cancelTask(Object task, TaskCancel cancel) { | |
1058 _ZoneFunction implementation = this._cancelTask; | |
1059 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1060 CancelTaskHandler handler = implementation.function; | |
1061 handler(implementation.zone, parentDelegate, this, task, cancel); | |
1062 } | |
1063 | |
1064 void print(String line) { | |
1065 _ZoneFunction implementation = this._print; | |
1066 assert(implementation != null); | |
1067 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1068 PrintHandler handler = implementation.function; | |
1069 return handler(implementation.zone, parentDelegate, this, line); | |
1070 } | |
1071 | |
1072 @deprecated | |
853 Timer createTimer(Duration duration, void f()) { | 1073 Timer createTimer(Duration duration, void f()) { |
854 _ZoneFunction implementation = this._createTimer; | 1074 _ZoneFunction implementation = this._createTimer; |
855 assert(implementation != null); | 1075 assert(implementation != null); |
856 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 1076 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
857 CreateTimerHandler handler = implementation.function; | 1077 CreateTimerHandler handler = implementation.function; |
858 return handler(implementation.zone, parentDelegate, this, duration, f); | 1078 return handler(implementation.zone, parentDelegate, this, duration, f); |
859 } | 1079 } |
860 | 1080 |
1081 @deprecated | |
861 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { | 1082 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
862 _ZoneFunction implementation = this._createPeriodicTimer; | 1083 _ZoneFunction implementation = this._createPeriodicTimer; |
863 assert(implementation != null); | 1084 assert(implementation != null); |
864 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 1085 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
865 CreatePeriodicTimerHandler handler = implementation.function; | 1086 CreatePeriodicTimerHandler handler = implementation.function; |
866 return handler( | 1087 return handler( |
867 implementation.zone, parentDelegate, this, duration, f); | 1088 implementation.zone, parentDelegate, this, duration, f); |
868 } | 1089 } |
869 | |
870 void print(String line) { | |
871 _ZoneFunction implementation = this._print; | |
872 assert(implementation != null); | |
873 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
874 PrintHandler handler = implementation.function; | |
875 return handler(implementation.zone, parentDelegate, this, line); | |
876 } | |
877 } | 1090 } |
878 | 1091 |
879 void _rootHandleUncaughtError( | 1092 void _rootHandleUncaughtError( |
880 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { | 1093 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { |
881 _schedulePriorityAsyncCallback(() { | 1094 _schedulePriorityAsyncCallback(() { |
882 if (error == null) error = new NullThrownError(); | 1095 if (error == null) error = new NullThrownError(); |
883 if (stackTrace == null) throw error; | 1096 if (stackTrace == null) throw error; |
884 _rethrow(error, stackTrace); | 1097 _rethrow(error, stackTrace); |
885 }); | 1098 }); |
886 } | 1099 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
942 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { | 1155 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { |
943 if (!identical(_ROOT_ZONE, zone)) { | 1156 if (!identical(_ROOT_ZONE, zone)) { |
944 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); | 1157 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); |
945 f = zone.bindCallback(f, runGuarded: hasErrorHandler); | 1158 f = zone.bindCallback(f, runGuarded: hasErrorHandler); |
946 // Use root zone as event zone if the function is already bound. | 1159 // Use root zone as event zone if the function is already bound. |
947 zone = _ROOT_ZONE; | 1160 zone = _ROOT_ZONE; |
948 } | 1161 } |
949 _scheduleAsyncCallback(f); | 1162 _scheduleAsyncCallback(f); |
950 } | 1163 } |
951 | 1164 |
1165 Object _rootcreateTask(Zone self, ZoneDelegate parent, Zone zone, | |
1166 TaskSpecification taskSpecification, TaskCreate create) { | |
1167 return create(taskSpecification, zone); | |
1168 } | |
1169 | |
1170 void _rootRunTask(Zone self, ZoneDelegate parent, Zone zone, Object task, | |
1171 Object arg, TaskRun run) { | |
1172 if (Zone._current == zone) run(task, arg); | |
1173 | |
1174 Zone old = Zone._enter(zone); | |
1175 try { | |
1176 run(task, arg); | |
1177 } finally { | |
1178 Zone._leave(old); | |
1179 } | |
1180 } | |
1181 | |
1182 void _rootCancelTask(Zone self, ZoneDelegate parent, Zone zone, Object task, | |
1183 TaskCancel cancel) { | |
1184 cancel(task); | |
1185 } | |
1186 | |
952 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, | 1187 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, |
953 Duration duration, void callback()) { | 1188 Duration duration, void callback()) { |
954 if (!identical(_ROOT_ZONE, zone)) { | 1189 return new Timer._task(zone, duration, callback); |
955 callback = zone.bindCallback(callback); | |
956 } | |
957 return Timer._createTimer(duration, callback); | |
958 } | 1190 } |
959 | 1191 |
960 Timer _rootCreatePeriodicTimer( | 1192 Timer _rootCreatePeriodicTimer( |
961 Zone self, ZoneDelegate parent, Zone zone, | 1193 Zone self, ZoneDelegate parent, Zone zone, |
962 Duration duration, void callback(Timer timer)) { | 1194 Duration duration, void callback(Timer timer)) { |
963 if (!identical(_ROOT_ZONE, zone)) { | 1195 return new Timer._periodicTask(zone, duration, callback); |
964 callback = zone.bindUnaryCallback(callback); | |
965 } | |
966 return Timer._createPeriodicTimer(duration, callback); | |
967 } | 1196 } |
968 | 1197 |
969 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { | 1198 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { |
970 printToConsole(line); | 1199 printToConsole(line); |
971 } | 1200 } |
972 | 1201 |
973 void _printToZone(String line) { | 1202 void _printToZone(String line) { |
974 Zone.current.print(line); | 1203 Zone.current.print(line); |
975 } | 1204 } |
976 | 1205 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 _ZoneFunction get _registerCallback => | 1242 _ZoneFunction get _registerCallback => |
1014 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback); | 1243 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback); |
1015 _ZoneFunction get _registerUnaryCallback => | 1244 _ZoneFunction get _registerUnaryCallback => |
1016 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback); | 1245 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback); |
1017 _ZoneFunction get _registerBinaryCallback => | 1246 _ZoneFunction get _registerBinaryCallback => |
1018 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback); | 1247 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback); |
1019 _ZoneFunction get _errorCallback => | 1248 _ZoneFunction get _errorCallback => |
1020 const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback); | 1249 const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback); |
1021 _ZoneFunction get _scheduleMicrotask => | 1250 _ZoneFunction get _scheduleMicrotask => |
1022 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); | 1251 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); |
1023 _ZoneFunction get _createTimer => | 1252 _ZoneFunction get _createTask => |
1024 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); | 1253 const _ZoneFunction(_ROOT_ZONE, _rootcreateTask); |
1025 _ZoneFunction get _createPeriodicTimer => | 1254 _ZoneFunction get _runTask => |
1026 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); | 1255 const _ZoneFunction(_ROOT_ZONE, _rootRunTask); |
1256 _ZoneFunction get _cancelTask => | |
1257 const _ZoneFunction(_ROOT_ZONE, _rootCancelTask); | |
1027 _ZoneFunction get _print => | 1258 _ZoneFunction get _print => |
1028 const _ZoneFunction(_ROOT_ZONE, _rootPrint); | 1259 const _ZoneFunction(_ROOT_ZONE, _rootPrint); |
1029 _ZoneFunction get _fork => | 1260 _ZoneFunction get _fork => |
1030 const _ZoneFunction(_ROOT_ZONE, _rootFork); | 1261 const _ZoneFunction(_ROOT_ZONE, _rootFork); |
1031 _ZoneFunction get _handleUncaughtError => | 1262 _ZoneFunction get _handleUncaughtError => |
1032 const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError); | 1263 const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError); |
1033 | 1264 |
1265 @deprecated | |
1266 _ZoneFunction get _createTimer => | |
1267 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); | |
1268 @deprecated | |
1269 _ZoneFunction get _createPeriodicTimer => | |
1270 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); | |
1271 | |
1034 // The parent zone. | 1272 // The parent zone. |
1035 _Zone get parent => null; | 1273 _Zone get parent => null; |
1036 | 1274 |
1037 /// The zone's scoped value declaration map. | 1275 /// The zone's scoped value declaration map. |
1038 /// | 1276 /// |
1039 /// This is always a [HashMap]. | 1277 /// This is always a [HashMap]. |
1040 Map get _map => _rootMap; | 1278 Map get _map => _rootMap; |
1041 | 1279 |
1042 static Map _rootMap = new HashMap(); | 1280 static Map _rootMap = new HashMap(); |
1043 | 1281 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f; | 1386 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f; |
1149 | 1387 |
1150 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f; | 1388 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f; |
1151 | 1389 |
1152 AsyncError errorCallback(Object error, StackTrace stackTrace) => null; | 1390 AsyncError errorCallback(Object error, StackTrace stackTrace) => null; |
1153 | 1391 |
1154 void scheduleMicrotask(void f()) { | 1392 void scheduleMicrotask(void f()) { |
1155 _rootScheduleMicrotask(null, null, this, f); | 1393 _rootScheduleMicrotask(null, null, this, f); |
1156 } | 1394 } |
1157 | 1395 |
1396 Object createTask(TaskSpecification task, TaskCreate create) { | |
1397 return _rootcreateTask(null, null, this, task, create); | |
1398 } | |
1399 | |
1400 void runTask(Object task, Object arg, TaskRun run) { | |
1401 _rootRunTask(null, null, this, task, arg, run); | |
1402 } | |
1403 | |
1404 void cancelTask(Object task, TaskCancel cancel) { | |
1405 _rootCancelTask(null, null, this, task, cancel); | |
1406 } | |
1407 | |
1158 Timer createTimer(Duration duration, void f()) { | 1408 Timer createTimer(Duration duration, void f()) { |
1159 return Timer._createTimer(duration, f); | 1409 return Timer._createTimer(duration, f); |
1160 } | 1410 } |
1161 | 1411 |
1162 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { | 1412 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
1163 return Timer._createPeriodicTimer(duration, f); | 1413 return Timer._createPeriodicTimer(duration, f); |
1164 } | 1414 } |
1165 | 1415 |
1166 void print(String line) { | 1416 void print(String line) { |
1167 printToConsole(line); | 1417 printToConsole(line); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 handleUncaughtError: errorHandler); | 1476 handleUncaughtError: errorHandler); |
1227 } | 1477 } |
1228 Zone zone = Zone.current.fork(specification: zoneSpecification, | 1478 Zone zone = Zone.current.fork(specification: zoneSpecification, |
1229 zoneValues: zoneValues); | 1479 zoneValues: zoneValues); |
1230 if (onError != null) { | 1480 if (onError != null) { |
1231 return zone.runGuarded(body); | 1481 return zone.runGuarded(body); |
1232 } else { | 1482 } else { |
1233 return zone.run(body); | 1483 return zone.run(body); |
1234 } | 1484 } |
1235 } | 1485 } |
OLD | NEW |