| 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 R ZoneCallback<R>(); |
| 8 typedef dynamic ZoneUnaryCallback(arg); | 8 typedef R ZoneUnaryCallback<R, T>(T arg); |
| 9 typedef dynamic ZoneBinaryCallback(arg1, arg2); | 9 typedef R ZoneBinaryCallback<R, T1, T2>(T1 arg1, T2 arg2); |
| 10 | 10 |
| 11 typedef dynamic HandleUncaughtErrorHandler( | 11 // TODO(floitsch): we are abusing generic typedefs as typedefs for generic |
| 12 // functions. |
| 13 /*ABUSE*/ |
| 14 typedef R HandleUncaughtErrorHandler<R>( |
| 12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); | 15 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); |
| 13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); | 16 /*ABUSE*/ |
| 14 typedef dynamic RunUnaryHandler( | 17 typedef R RunHandler<R>(Zone self, ZoneDelegate parent, Zone zone, R f()); |
| 15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); | 18 /*ABUSE*/ |
| 16 typedef dynamic RunBinaryHandler( | 19 typedef R RunUnaryHandler<R, T>( |
| 17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); | 20 Zone self, ZoneDelegate parent, Zone zone, R f(T arg), T arg); |
| 18 typedef ZoneCallback RegisterCallbackHandler( | 21 /*ABUSE*/ |
| 19 Zone self, ZoneDelegate parent, Zone zone, f()); | 22 typedef R RunBinaryHandler<R, T1, T2>( |
| 20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( | 23 Zone self, ZoneDelegate parent, Zone zone, |
| 21 Zone self, ZoneDelegate parent, Zone zone, f(arg)); | 24 R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2); |
| 22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( | 25 /*ABUSE*/ |
| 23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); | 26 typedef ZoneCallback<R> RegisterCallbackHandler<R>( |
| 27 Zone self, ZoneDelegate parent, Zone zone, R f()); |
| 28 /*ABUSE*/ |
| 29 typedef ZoneUnaryCallback<R, T> RegisterUnaryCallbackHandler<R, T>( |
| 30 Zone self, ZoneDelegate parent, Zone zone, R f(T arg)); |
| 31 /*ABUSE*/ |
| 32 typedef ZoneBinaryCallback<R, T1, T2> RegisterBinaryCallbackHandler<R, T1, T2>( |
| 33 Zone self, ZoneDelegate parent, Zone zone, R f(T1 arg1, T2 arg2)); |
| 24 typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, | 34 typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, |
| 25 Zone zone, Object error, StackTrace stackTrace); | 35 Zone zone, Object error, StackTrace stackTrace); |
| 26 typedef void ScheduleMicrotaskHandler( | 36 typedef void ScheduleMicrotaskHandler( |
| 27 Zone self, ZoneDelegate parent, Zone zone, f()); | 37 Zone self, ZoneDelegate parent, Zone zone, void f()); |
| 28 typedef Timer CreateTimerHandler( | 38 typedef Timer CreateTimerHandler( |
| 29 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); | 39 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); |
| 30 typedef Timer CreatePeriodicTimerHandler( | 40 typedef Timer CreatePeriodicTimerHandler( |
| 31 Zone self, ZoneDelegate parent, Zone zone, | 41 Zone self, ZoneDelegate parent, Zone zone, |
| 32 Duration period, void f(Timer timer)); | 42 Duration period, void f(Timer timer)); |
| 33 typedef void PrintHandler( | 43 typedef void PrintHandler( |
| 34 Zone self, ZoneDelegate parent, Zone zone, String line); | 44 Zone self, ZoneDelegate parent, Zone zone, String line); |
| 35 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, | 45 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, |
| 36 ZoneSpecification specification, | 46 ZoneSpecification specification, |
| 37 Map zoneValues); | 47 Map zoneValues); |
| 38 | 48 |
| 39 /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ | 49 /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ |
| 40 class AsyncError implements Error { | 50 class AsyncError implements Error { |
| 41 final error; | 51 final Object error; |
| 42 final StackTrace stackTrace; | 52 final StackTrace stackTrace; |
| 43 | 53 |
| 44 AsyncError(this.error, this.stackTrace); | 54 AsyncError(this.error, this.stackTrace); |
| 45 | 55 |
| 46 String toString() => error.toString(); | 56 String toString() => '$error'; |
| 47 } | 57 } |
| 48 | 58 |
| 49 | 59 |
| 50 class _ZoneFunction { | 60 class _ZoneFunction<T extends Function> { |
| 51 final _Zone zone; | 61 final _Zone zone; |
| 52 final Function function; | 62 final T function; |
| 53 const _ZoneFunction(this.zone, this.function); | 63 const _ZoneFunction(this.zone, this.function); |
| 54 } | 64 } |
| 55 | 65 |
| 56 /** | 66 /** |
| 57 * This class provides the specification for a forked zone. | 67 * This class provides the specification for a forked zone. |
| 58 * | 68 * |
| 59 * When forking a new zone (see [Zone.fork]) one can override the default | 69 * 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 | 70 * behavior of the zone by providing callbacks. These callbacks must be |
| 61 * given in an instance of this class. | 71 * given in an instance of this class. |
| 62 * | 72 * |
| 63 * Handlers have the same signature as the same-named methods on [Zone] but | 73 * Handlers have the same signature as the same-named methods on [Zone] but |
| 64 * receive three additional arguments: | 74 * receive three additional arguments: |
| 65 * | 75 * |
| 66 * 1. the zone the handlers are attached to (the "self" zone). | 76 * 1. the zone the handlers are attached to (the "self" zone). |
| 67 * 2. a [ZoneDelegate] to the parent zone. | 77 * 2. a [ZoneDelegate] to the parent zone. |
| 68 * 3. the zone that first received the request (before the request was | 78 * 3. the zone that first received the request (before the request was |
| 69 * bubbled up). | 79 * bubbled up). |
| 70 * | 80 * |
| 71 * Handlers can either stop propagation the request (by simply not calling the | 81 * Handlers can either stop propagation the request (by simply not calling the |
| 72 * parent handler), or forward to the parent zone, potentially modifying the | 82 * parent handler), or forward to the parent zone, potentially modifying the |
| 73 * arguments on the way. | 83 * arguments on the way. |
| 74 */ | 84 */ |
| 75 abstract class ZoneSpecification { | 85 abstract class ZoneSpecification { |
| 76 /** | 86 /** |
| 77 * Creates a specification with the provided handlers. | 87 * Creates a specification with the provided handlers. |
| 78 */ | 88 */ |
| 79 const factory ZoneSpecification({ | 89 const factory ZoneSpecification({ |
| 80 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, | 90 HandleUncaughtErrorHandler handleUncaughtError, |
| 81 error, StackTrace stackTrace), | 91 RunHandler run, |
| 82 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()), | 92 RunUnaryHandler runUnary, |
| 83 dynamic runUnary( | 93 RunBinaryHandler runBinary, |
| 84 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg), | 94 RegisterCallbackHandler registerCallback, |
| 85 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, | 95 RegisterUnaryCallbackHandler registerUnaryCallback, |
| 86 f(arg1, arg2), arg1, arg2), | 96 RegisterBinaryCallbackHandler registerBinaryCallback, |
| 87 ZoneCallback registerCallback( | 97 ErrorCallbackHandler errorCallback, |
| 88 Zone self, ZoneDelegate parent, Zone zone, f()), | 98 ScheduleMicrotaskHandler scheduleMicrotask, |
| 89 ZoneUnaryCallback registerUnaryCallback( | 99 CreateTimerHandler createTimer, |
| 90 Zone self, ZoneDelegate parent, Zone zone, f(arg)), | 100 CreatePeriodicTimerHandler createPeriodicTimer, |
| 91 ZoneBinaryCallback registerBinaryCallback( | 101 PrintHandler print, |
| 92 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), | 102 ForkHandler fork |
| 93 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, | |
| 94 Object error, StackTrace stackTrace), | |
| 95 void scheduleMicrotask( | |
| 96 Zone self, ZoneDelegate parent, Zone zone, f()), | |
| 97 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | |
| 98 Duration duration, void f()), | |
| 99 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | |
| 100 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; | 103 }) = _ZoneSpecification; |
| 105 | 104 |
| 106 /** | 105 /** |
| 107 * Creates a specification from [other] with the provided handlers overriding | 106 * Creates a specification from [other] with the provided handlers overriding |
| 108 * the ones in [other]. | 107 * the ones in [other]. |
| 109 */ | 108 */ |
| 110 factory ZoneSpecification.from(ZoneSpecification other, { | 109 factory ZoneSpecification.from(ZoneSpecification other, { |
| 111 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, | 110 HandleUncaughtErrorHandler handleUncaughtError: null, |
| 112 error, StackTrace stackTrace): null, | 111 RunHandler run: null, |
| 113 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, | 112 RunUnaryHandler runUnary: null, |
| 114 dynamic runUnary( | 113 RunBinaryHandler runBinary: null, |
| 115 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, | 114 RegisterCallbackHandler registerCallback: null, |
| 116 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, | 115 RegisterUnaryCallbackHandler registerUnaryCallback: null, |
| 117 f(arg1, arg2), arg1, arg2): null, | 116 RegisterBinaryCallbackHandler registerBinaryCallback: null, |
| 118 ZoneCallback registerCallback( | 117 ErrorCallbackHandler errorCallback: null, |
| 119 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 118 ScheduleMicrotaskHandler scheduleMicrotask: null, |
| 120 ZoneUnaryCallback registerUnaryCallback( | 119 CreateTimerHandler createTimer: null, |
| 121 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, | 120 CreatePeriodicTimerHandler createPeriodicTimer: null, |
| 122 ZoneBinaryCallback registerBinaryCallback( | 121 PrintHandler print: null, |
| 123 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, | 122 ForkHandler fork: null |
| 124 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, | |
| 125 Object error, StackTrace stackTrace), | |
| 126 void scheduleMicrotask( | |
| 127 Zone self, ZoneDelegate parent, Zone zone, f()): null, | |
| 128 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | |
| 129 Duration duration, void f()): null, | |
| 130 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | |
| 131 Duration period, void f(Timer timer)): null, | |
| 132 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, | |
| 133 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | |
| 134 ZoneSpecification specification, | |
| 135 Map zoneValues): null | |
| 136 }) { | 123 }) { |
| 137 return new ZoneSpecification( | 124 return new ZoneSpecification( |
| 138 handleUncaughtError: handleUncaughtError != null | 125 handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError, |
| 139 ? handleUncaughtError | 126 run: run ?? other.run, |
| 140 : other.handleUncaughtError, | 127 runUnary: runUnary ?? other.runUnary, |
| 141 run: run != null ? run : other.run, | 128 runBinary: runBinary ?? other.runBinary, |
| 142 runUnary: runUnary != null ? runUnary : other.runUnary, | 129 registerCallback: registerCallback ?? other.registerCallback, |
| 143 runBinary: runBinary != null ? runBinary : other.runBinary, | 130 registerUnaryCallback: registerUnaryCallback ?? |
| 144 registerCallback: registerCallback != null | 131 other.registerUnaryCallback, |
| 145 ? registerCallback | 132 registerBinaryCallback: registerBinaryCallback ?? |
| 146 : other.registerCallback, | 133 other.registerBinaryCallback, |
| 147 registerUnaryCallback: registerUnaryCallback != null | 134 errorCallback: errorCallback ?? other.errorCallback, |
| 148 ? registerUnaryCallback | 135 scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask, |
| 149 : other.registerUnaryCallback, | 136 createTimer : createTimer ?? other.createTimer, |
| 150 registerBinaryCallback: registerBinaryCallback != null | 137 createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer, |
| 151 ? registerBinaryCallback | 138 print : print ?? other.print, |
| 152 : other.registerBinaryCallback, | 139 fork: fork ?? other.fork); |
| 153 errorCallback: errorCallback != null | |
| 154 ? errorCallback | |
| 155 : other.errorCallback, | |
| 156 scheduleMicrotask: scheduleMicrotask != null | |
| 157 ? scheduleMicrotask | |
| 158 : other.scheduleMicrotask, | |
| 159 createTimer : createTimer != null ? createTimer : other.createTimer, | |
| 160 createPeriodicTimer: createPeriodicTimer != null | |
| 161 ? createPeriodicTimer | |
| 162 : other.createPeriodicTimer, | |
| 163 print : print != null ? print : other.print, | |
| 164 fork: fork != null ? fork : other.fork); | |
| 165 } | 140 } |
| 166 | 141 |
| 167 HandleUncaughtErrorHandler get handleUncaughtError; | 142 HandleUncaughtErrorHandler get handleUncaughtError; |
| 168 RunHandler get run; | 143 RunHandler get run; |
| 169 RunUnaryHandler get runUnary; | 144 RunUnaryHandler get runUnary; |
| 170 RunBinaryHandler get runBinary; | 145 RunBinaryHandler get runBinary; |
| 171 RegisterCallbackHandler get registerCallback; | 146 RegisterCallbackHandler get registerCallback; |
| 172 RegisterUnaryCallbackHandler get registerUnaryCallback; | 147 RegisterUnaryCallbackHandler get registerUnaryCallback; |
| 173 RegisterBinaryCallbackHandler get registerBinaryCallback; | 148 RegisterBinaryCallbackHandler get registerBinaryCallback; |
| 174 ErrorCallbackHandler get errorCallback; | 149 ErrorCallbackHandler get errorCallback; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 196 this.registerUnaryCallback: null, | 171 this.registerUnaryCallback: null, |
| 197 this.registerBinaryCallback: null, | 172 this.registerBinaryCallback: null, |
| 198 this.errorCallback: null, | 173 this.errorCallback: null, |
| 199 this.scheduleMicrotask: null, | 174 this.scheduleMicrotask: null, |
| 200 this.createTimer: null, | 175 this.createTimer: null, |
| 201 this.createPeriodicTimer: null, | 176 this.createPeriodicTimer: null, |
| 202 this.print: null, | 177 this.print: null, |
| 203 this.fork: null | 178 this.fork: null |
| 204 }); | 179 }); |
| 205 | 180 |
| 206 // TODO(13406): Enable types when dart2js supports it. | 181 final HandleUncaughtErrorHandler handleUncaughtError; |
| 207 final /*HandleUncaughtErrorHandler*/ handleUncaughtError; | 182 final RunHandler run; |
| 208 final /*RunHandler*/ run; | 183 final RunUnaryHandler runUnary; |
| 209 final /*RunUnaryHandler*/ runUnary; | 184 final RunBinaryHandler runBinary; |
| 210 final /*RunBinaryHandler*/ runBinary; | 185 final RegisterCallbackHandler registerCallback; |
| 211 final /*RegisterCallbackHandler*/ registerCallback; | 186 final RegisterUnaryCallbackHandler registerUnaryCallback; |
| 212 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback; | 187 final RegisterBinaryCallbackHandler registerBinaryCallback; |
| 213 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback; | 188 final ErrorCallbackHandler errorCallback; |
| 214 final /*ErrorCallbackHandler*/ errorCallback; | 189 final ScheduleMicrotaskHandler scheduleMicrotask; |
| 215 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask; | 190 final CreateTimerHandler createTimer; |
| 216 final /*CreateTimerHandler*/ createTimer; | 191 final CreatePeriodicTimerHandler createPeriodicTimer; |
| 217 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer; | 192 final PrintHandler print; |
| 218 final /*PrintHandler*/ print; | 193 final ForkHandler fork; |
| 219 final /*ForkHandler*/ fork; | |
| 220 } | 194 } |
| 221 | 195 |
| 222 /** | 196 /** |
| 223 * This class wraps zones for delegation. | 197 * This class wraps zones for delegation. |
| 224 * | 198 * |
| 225 * When forwarding to parent zones one can't just invoke the parent zone's | 199 * When forwarding to parent zones one can't just invoke the parent zone's |
| 226 * exposed functions (like [Zone.run]), but one needs to provide more | 200 * exposed functions (like [Zone.run]), but one needs to provide more |
| 227 * information (like the zone the `run` was initiated). Zone callbacks thus | 201 * information (like the zone the `run` was initiated). Zone callbacks thus |
| 228 * receive more information including this [ZoneDelegate] class. When delegating | 202 * receive more information including this [ZoneDelegate] class. When delegating |
| 229 * to the parent zone one should go through the given instance instead of | 203 * to the parent zone one should go through the given instance instead of |
| 230 * directly invoking the parent zone. | 204 * directly invoking the parent zone. |
| 231 */ | 205 */ |
| 232 abstract class ZoneDelegate { | 206 abstract class ZoneDelegate { |
| 233 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); | 207 /*=R*/ handleUncaughtError/*<R>*/( |
| 234 dynamic run(Zone zone, f()); | 208 Zone zone, error, StackTrace stackTrace); |
| 235 dynamic runUnary(Zone zone, f(arg), arg); | 209 /*=R*/ run/*<R>*/(Zone zone, /*=R*/ f()); |
| 236 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); | 210 /*=R*/ runUnary/*<R, T>*/(Zone zone, /*=R*/ f(/*=T*/ arg), /*=T*/ arg); |
| 237 ZoneCallback registerCallback(Zone zone, f()); | 211 /*=R*/ runBinary/*<R, T1, T2>*/(Zone zone, |
| 238 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); | 212 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2); |
| 239 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); | 213 ZoneCallback/*<R>*/ registerCallback/*<R>*/(Zone zone, /*=R*/ f()); |
| 214 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
| 215 Zone zone, /*=R*/ f(/*=T*/ arg)); |
| 216 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
| 217 Zone zone, /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)); |
| 240 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); | 218 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); |
| 241 void scheduleMicrotask(Zone zone, f()); | 219 void scheduleMicrotask(Zone zone, void f()); |
| 242 Timer createTimer(Zone zone, Duration duration, void f()); | 220 Timer createTimer(Zone zone, Duration duration, void f()); |
| 243 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); | 221 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); |
| 244 void print(Zone zone, String line); | 222 void print(Zone zone, String line); |
| 245 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); | 223 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); |
| 246 } | 224 } |
| 247 | 225 |
| 248 /** | 226 /** |
| 249 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous | 227 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous |
| 250 * callbacks are executed in the zone they have been queued in. For example, | 228 * callbacks are executed in the zone they have been queued in. For example, |
| 251 * the callback of a `future.then` is executed in the same zone as the one where | 229 * the callback of a `future.then` is executed in the same zone as the one where |
| 252 * the `then` was invoked. | 230 * the `then` was invoked. |
| 253 */ | 231 */ |
| 254 abstract class Zone { | 232 abstract class Zone { |
| 255 // Private constructor so that it is not possible instantiate a Zone class. | 233 // Private constructor so that it is not possible instantiate a Zone class. |
| 256 Zone._(); | 234 Zone._(); |
| 257 | 235 |
| 258 /** The root zone that is implicitly created. */ | 236 /** The root zone that is implicitly created. */ |
| 259 static const Zone ROOT = _ROOT_ZONE; | 237 static const Zone ROOT = _ROOT_ZONE; |
| 260 | 238 |
| 261 /** The currently running zone. */ | 239 /** The currently running zone. */ |
| 262 static Zone _current = _ROOT_ZONE; | 240 static Zone _current = _ROOT_ZONE; |
| 263 | 241 |
| 264 static Zone get current => _current; | 242 static Zone get current => _current; |
| 265 | 243 |
| 266 dynamic handleUncaughtError(error, StackTrace stackTrace); | 244 /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace); |
| 267 | 245 |
| 268 /** | 246 /** |
| 269 * Returns the parent zone. | 247 * Returns the parent zone. |
| 270 * | 248 * |
| 271 * Returns `null` if `this` is the [ROOT] zone. | 249 * Returns `null` if `this` is the [ROOT] zone. |
| 272 */ | 250 */ |
| 273 Zone get parent; | 251 Zone get parent; |
| 274 | 252 |
| 275 /** | 253 /** |
| 276 * The error zone is the one that is responsible for dealing with uncaught | 254 * The error zone is the one that is responsible for dealing with uncaught |
| (...skipping 23 matching lines...) Expand all Loading... |
| 300 * `operator []`) as this zone, but updated with the keys and values | 278 * `operator []`) as this zone, but updated with the keys and values |
| 301 * in [zoneValues]. If a key is in both this zone's values and in | 279 * in [zoneValues]. If a key is in both this zone's values and in |
| 302 * `zoneValues`, the new zone will use the value from `zoneValues``. | 280 * `zoneValues`, the new zone will use the value from `zoneValues``. |
| 303 */ | 281 */ |
| 304 Zone fork({ ZoneSpecification specification, | 282 Zone fork({ ZoneSpecification specification, |
| 305 Map zoneValues }); | 283 Map zoneValues }); |
| 306 | 284 |
| 307 /** | 285 /** |
| 308 * Executes the given function [f] in this zone. | 286 * Executes the given function [f] in this zone. |
| 309 */ | 287 */ |
| 310 dynamic run(f()); | 288 /*=R*/ run/*<R>*/(/*=R*/ f()); |
| 311 | 289 |
| 312 /** | 290 /** |
| 313 * Executes the given callback [f] with argument [arg] in this zone. | 291 * Executes the given callback [f] with argument [arg] in this zone. |
| 314 */ | 292 */ |
| 315 dynamic runUnary(f(arg), var arg); | 293 /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg); |
| 316 | 294 |
| 317 /** | 295 /** |
| 318 * Executes the given callback [f] with argument [arg1] and [arg2] in this | 296 * Executes the given callback [f] with argument [arg1] and [arg2] in this |
| 319 * zone. | 297 * zone. |
| 320 */ | 298 */ |
| 321 dynamic runBinary(f(arg1, arg2), var arg1, var arg2); | 299 /*=R*/ runBinary/*<R, T1, T2>*/( |
| 300 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2); |
| 322 | 301 |
| 323 /** | 302 /** |
| 324 * Executes the given function [f] in this zone. | 303 * Executes the given function [f] in this zone. |
| 325 * | 304 * |
| 326 * Same as [run] but catches uncaught errors and gives them to | 305 * Same as [run] but catches uncaught errors and gives them to |
| 327 * [handleUncaughtError]. | 306 * [handleUncaughtError]. |
| 328 */ | 307 */ |
| 329 dynamic runGuarded(f()); | 308 /*=R*/ runGuarded/*<R>*/(/*=R*/ f()); |
| 330 | 309 |
| 331 /** | 310 /** |
| 332 * Executes the given callback [f] in this zone. | 311 * Executes the given callback [f] in this zone. |
| 333 * | 312 * |
| 334 * Same as [runUnary] but catches uncaught errors and gives them to | 313 * Same as [runUnary] but catches uncaught errors and gives them to |
| 335 * [handleUncaughtError]. | 314 * [handleUncaughtError]. |
| 336 */ | 315 */ |
| 337 dynamic runUnaryGuarded(f(arg), var arg); | 316 /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg); |
| 338 | 317 |
| 339 /** | 318 /** |
| 340 * Executes the given callback [f] in this zone. | 319 * Executes the given callback [f] in this zone. |
| 341 * | 320 * |
| 342 * Same as [runBinary] but catches uncaught errors and gives them to | 321 * Same as [runBinary] but catches uncaught errors and gives them to |
| 343 * [handleUncaughtError]. | 322 * [handleUncaughtError]. |
| 344 */ | 323 */ |
| 345 dynamic runBinaryGuarded(f(arg1, arg2), var arg1, var arg2); | 324 /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( |
| 325 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2); |
| 346 | 326 |
| 347 /** | 327 /** |
| 348 * Registers the given callback in this zone. | 328 * Registers the given callback in this zone. |
| 349 * | 329 * |
| 350 * It is good practice to register asynchronous or delayed callbacks before | 330 * It is good practice to register asynchronous or delayed callbacks before |
| 351 * invoking [run]. This gives the zone a chance to wrap the callback and | 331 * invoking [run]. This gives the zone a chance to wrap the callback and |
| 352 * to store information with the callback. For example, a zone may decide | 332 * to store information with the callback. For example, a zone may decide |
| 353 * to store the stack trace (at the time of the registration) with the | 333 * to store the stack trace (at the time of the registration) with the |
| 354 * callback. | 334 * callback. |
| 355 * | 335 * |
| 356 * Returns a potentially new callback that should be used in place of the | 336 * Returns a potentially new callback that should be used in place of the |
| 357 * given [callback]. | 337 * given [callback]. |
| 358 */ | 338 */ |
| 359 ZoneCallback registerCallback(callback()); | 339 ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ callback()); |
| 360 | 340 |
| 361 /** | 341 /** |
| 362 * Registers the given callback in this zone. | 342 * Registers the given callback in this zone. |
| 363 * | 343 * |
| 364 * Similar to [registerCallback] but with a unary callback. | 344 * Similar to [registerCallback] but with a unary callback. |
| 365 */ | 345 */ |
| 366 ZoneUnaryCallback registerUnaryCallback(callback(arg)); | 346 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
| 347 /*=R*/ callback(/*=T*/ arg)); |
| 367 | 348 |
| 368 /** | 349 /** |
| 369 * Registers the given callback in this zone. | 350 * Registers the given callback in this zone. |
| 370 * | 351 * |
| 371 * Similar to [registerCallback] but with a unary callback. | 352 * Similar to [registerCallback] but with a unary callback. |
| 372 */ | 353 */ |
| 373 ZoneBinaryCallback registerBinaryCallback(callback(arg1, arg2)); | 354 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
| 355 /*=R*/ callback(/*=T1*/ arg1, /*=T2*/ arg2)); |
| 374 | 356 |
| 375 /** | 357 /** |
| 376 * Equivalent to: | 358 * Equivalent to: |
| 377 * | 359 * |
| 378 * ZoneCallback registered = registerCallback(f); | 360 * ZoneCallback registered = registerCallback(f); |
| 379 * if (runGuarded) return () => this.runGuarded(registered); | 361 * if (runGuarded) return () => this.runGuarded(registered); |
| 380 * return () => this.run(registered); | 362 * return () => this.run(registered); |
| 381 * | 363 * |
| 382 */ | 364 */ |
| 383 ZoneCallback bindCallback(f(), { bool runGuarded: true }); | 365 ZoneCallback/*<R>*/ bindCallback/*<R>*/( |
| 366 /*=R*/ f(), { bool runGuarded: true }); |
| 384 | 367 |
| 385 /** | 368 /** |
| 386 * Equivalent to: | 369 * Equivalent to: |
| 387 * | 370 * |
| 388 * ZoneCallback registered = registerUnaryCallback(f); | 371 * ZoneCallback registered = registerUnaryCallback(f); |
| 389 * if (runGuarded) return (arg) => this.runUnaryGuarded(registered, arg); | 372 * if (runGuarded) return (arg) => this.runUnaryGuarded(registered, arg); |
| 390 * return (arg) => thin.runUnary(registered, arg); | 373 * return (arg) => thin.runUnary(registered, arg); |
| 391 */ | 374 */ |
| 392 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }); | 375 ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( |
| 376 /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }); |
| 393 | 377 |
| 394 /** | 378 /** |
| 395 * Equivalent to: | 379 * Equivalent to: |
| 396 * | 380 * |
| 397 * ZoneCallback registered = registerBinaryCallback(f); | 381 * ZoneCallback registered = registerBinaryCallback(f); |
| 398 * if (runGuarded) { | 382 * if (runGuarded) { |
| 399 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg); | 383 * return (arg1, arg2) => this.runBinaryGuarded(registered, arg); |
| 400 * } | 384 * } |
| 401 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); | 385 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); |
| 402 */ | 386 */ |
| 403 ZoneBinaryCallback bindBinaryCallback( | 387 ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( |
| 404 f(arg1, arg2), { bool runGuarded: true }); | 388 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }); |
| 405 | 389 |
| 406 /** | 390 /** |
| 407 * Intercepts errors when added programmtically to a `Future` or `Stream`. | 391 * Intercepts errors when added programmatically to a `Future` or `Stream`. |
| 408 * | 392 * |
| 409 * When caling [Completer.completeError], [Stream.addError], | 393 * When caling [Completer.completeError], [Stream.addError], |
| 410 * or [Future] constructors that take an error or a callback that may throw, | 394 * or [Future] constructors that take an error or a callback that may throw, |
| 411 * the current zone is allowed to intercept and replace the error. | 395 * the current zone is allowed to intercept and replace the error. |
| 412 * | 396 * |
| 413 * When other libraries use intermediate controllers or completers, such | 397 * When other libraries use intermediate controllers or completers, such |
| 414 * calls may contain errors that have already been processed. | 398 * calls may contain errors that have already been processed. |
| 415 * | 399 * |
| 416 * Return `null` if no replacement is desired. | 400 * Return `null` if no replacement is desired. |
| 417 * The original error is used unchanged in that case. | 401 * The original error is used unchanged in that case. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 ZoneDelegate _parentDelegate(_Zone zone) { | 465 ZoneDelegate _parentDelegate(_Zone zone) { |
| 482 if (zone.parent == null) return null; | 466 if (zone.parent == null) return null; |
| 483 return zone.parent._delegate; | 467 return zone.parent._delegate; |
| 484 } | 468 } |
| 485 | 469 |
| 486 class _ZoneDelegate implements ZoneDelegate { | 470 class _ZoneDelegate implements ZoneDelegate { |
| 487 final _Zone _delegationTarget; | 471 final _Zone _delegationTarget; |
| 488 | 472 |
| 489 _ZoneDelegate(this._delegationTarget); | 473 _ZoneDelegate(this._delegationTarget); |
| 490 | 474 |
| 491 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace) { | 475 /*=R*/ handleUncaughtError/*<R>*/( |
| 492 _ZoneFunction implementation = _delegationTarget._handleUncaughtError; | 476 Zone zone, error, StackTrace stackTrace) { |
| 477 var implementation = _delegationTarget._handleUncaughtError; |
| 493 _Zone implZone = implementation.zone; | 478 _Zone implZone = implementation.zone; |
| 494 return (implementation.function)( | 479 HandleUncaughtErrorHandler handler = implementation.function; |
| 495 implZone, _parentDelegate(implZone), zone, error, stackTrace); | 480 // TODO(floitsch): make this a generic method call on '<R>' once it's |
| 481 // supported. Remove the unnecessary cast. |
| 482 return handler( |
| 483 implZone, _parentDelegate(implZone), zone, error, stackTrace) |
| 484 as Object/*=R*/; |
| 496 } | 485 } |
| 497 | 486 |
| 498 dynamic run(Zone zone, f()) { | 487 /*=R*/ run/*<R>*/(Zone zone, /*=R*/ f()) { |
| 499 _ZoneFunction implementation = _delegationTarget._run; | 488 var implementation = _delegationTarget._run; |
| 500 _Zone implZone = implementation.zone; | 489 _Zone implZone = implementation.zone; |
| 501 return (implementation.function)( | 490 RunHandler handler = implementation.function; |
| 502 implZone, _parentDelegate(implZone), zone, f); | 491 // TODO(floitsch): make this a generic method call on '<R>' once it's |
| 492 // supported. Remove the unnecessary cast. |
| 493 return handler(implZone, _parentDelegate(implZone), zone, f) |
| 494 as Object/*=R*/; |
| 503 } | 495 } |
| 504 | 496 |
| 505 dynamic runUnary(Zone zone, f(arg), arg) { | 497 /*=R*/ runUnary/*<R, T>*/(Zone zone, /*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
| 506 _ZoneFunction implementation = _delegationTarget._runUnary; | 498 var implementation = _delegationTarget._runUnary; |
| 507 _Zone implZone = implementation.zone; | 499 _Zone implZone = implementation.zone; |
| 508 return (implementation.function)( | 500 RunUnaryHandler handler = implementation.function; |
| 509 implZone, _parentDelegate(implZone), zone, f, arg); | 501 // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
| 502 // supported. Remove the unnecessary cast. |
| 503 return handler( |
| 504 implZone, _parentDelegate(implZone), zone, f, arg) as Object/*=R*/; |
| 510 } | 505 } |
| 511 | 506 |
| 512 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2) { | 507 /*=R*/ runBinary/*<R, T1, T2>*/(Zone zone, |
| 513 _ZoneFunction implementation = _delegationTarget._runBinary; | 508 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
| 509 var implementation = _delegationTarget._runBinary; |
| 514 _Zone implZone = implementation.zone; | 510 _Zone implZone = implementation.zone; |
| 515 return (implementation.function)( | 511 RunBinaryHandler handler = implementation.function; |
| 516 implZone, _parentDelegate(implZone), zone, f, arg1, arg2); | 512 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
| 513 // it's supported. Remove the unnecessary cast. |
| 514 return handler( |
| 515 implZone, _parentDelegate(implZone), zone, f, arg1, arg2) |
| 516 as Object/*=R*/; |
| 517 } | 517 } |
| 518 | 518 |
| 519 ZoneCallback registerCallback(Zone zone, f()) { | 519 ZoneCallback/*<R>*/ registerCallback/*<R>*/(Zone zone, /*=R*/ f()) { |
| 520 _ZoneFunction implementation = _delegationTarget._registerCallback; | 520 var implementation = _delegationTarget._registerCallback; |
| 521 _Zone implZone = implementation.zone; | 521 _Zone implZone = implementation.zone; |
| 522 return (implementation.function)( | 522 RegisterCallbackHandler handler = implementation.function; |
| 523 implZone, _parentDelegate(implZone), zone, f); | 523 // TODO(floitsch): make this a generic method call on '<R>' once it's |
| 524 // supported. Remove the unnecessary cast. |
| 525 return handler(implZone, _parentDelegate(implZone), zone, f) |
| 526 as Object/*=ZoneCallback<R>*/; |
| 524 } | 527 } |
| 525 | 528 |
| 526 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)) { | 529 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
| 527 _ZoneFunction implementation = _delegationTarget._registerUnaryCallback; | 530 Zone zone, /*=R*/ f(/*=T*/ arg)) { |
| 531 var implementation = _delegationTarget._registerUnaryCallback; |
| 528 _Zone implZone = implementation.zone; | 532 _Zone implZone = implementation.zone; |
| 529 return (implementation.function)( | 533 RegisterUnaryCallbackHandler handler = implementation.function; |
| 530 implZone, _parentDelegate(implZone), zone, f); | 534 // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
| 535 // supported. Remove the unnecessary cast. |
| 536 return handler(implZone, _parentDelegate(implZone), zone, f) |
| 537 as Object/*=ZoneUnaryCallback<R, T>*/; |
| 531 } | 538 } |
| 532 | 539 |
| 533 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) { | 540 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
| 534 _ZoneFunction implementation = _delegationTarget._registerBinaryCallback; | 541 Zone zone, /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) { |
| 542 var implementation = _delegationTarget._registerBinaryCallback; |
| 535 _Zone implZone = implementation.zone; | 543 _Zone implZone = implementation.zone; |
| 536 return (implementation.function)( | 544 RegisterBinaryCallbackHandler handler = implementation.function; |
| 537 implZone, _parentDelegate(implZone), zone, f); | 545 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
| 546 // it's supported. Remove the unnecessary cast. |
| 547 return handler(implZone, _parentDelegate(implZone), zone, f) |
| 548 as Object/*=ZoneBinaryCallback<R, T1, T2>*/; |
| 538 } | 549 } |
| 539 | 550 |
| 540 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) { | 551 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) { |
| 541 _ZoneFunction implementation = _delegationTarget._errorCallback; | 552 var implementation = _delegationTarget._errorCallback; |
| 542 _Zone implZone = implementation.zone; | 553 _Zone implZone = implementation.zone; |
| 543 if (identical(implZone, _ROOT_ZONE)) return null; | 554 if (identical(implZone, _ROOT_ZONE)) return null; |
| 544 return (implementation.function)(implZone, _parentDelegate(implZone), zone, | 555 ErrorCallbackHandler handler = implementation.function; |
| 545 error, stackTrace); | 556 return handler(implZone, _parentDelegate(implZone), zone, |
| 557 error, stackTrace); |
| 546 } | 558 } |
| 547 | 559 |
| 548 void scheduleMicrotask(Zone zone, f()) { | 560 void scheduleMicrotask(Zone zone, f()) { |
| 549 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; | 561 var implementation = _delegationTarget._scheduleMicrotask; |
| 550 _Zone implZone = implementation.zone; | 562 _Zone implZone = implementation.zone; |
| 551 (implementation.function)( | 563 ScheduleMicrotaskHandler handler = implementation.function; |
| 552 implZone, _parentDelegate(implZone), zone, f); | 564 handler(implZone, _parentDelegate(implZone), zone, f); |
| 553 } | 565 } |
| 554 | 566 |
| 555 Timer createTimer(Zone zone, Duration duration, void f()) { | 567 Timer createTimer(Zone zone, Duration duration, void f()) { |
| 556 _ZoneFunction implementation = _delegationTarget._createTimer; | 568 var implementation = _delegationTarget._createTimer; |
| 557 _Zone implZone = implementation.zone; | 569 _Zone implZone = implementation.zone; |
| 558 return (implementation.function)( | 570 CreateTimerHandler handler = implementation.function; |
| 559 implZone, _parentDelegate(implZone), zone, duration, f); | 571 return handler(implZone, _parentDelegate(implZone), zone, duration, f); |
| 560 } | 572 } |
| 561 | 573 |
| 562 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { | 574 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { |
| 563 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; | 575 var implementation = _delegationTarget._createPeriodicTimer; |
| 564 _Zone implZone = implementation.zone; | 576 _Zone implZone = implementation.zone; |
| 565 return (implementation.function)( | 577 CreatePeriodicTimerHandler handler = implementation.function; |
| 566 implZone, _parentDelegate(implZone), zone, period, f); | 578 return handler(implZone, _parentDelegate(implZone), zone, period, f); |
| 567 } | 579 } |
| 568 | 580 |
| 569 void print(Zone zone, String line) { | 581 void print(Zone zone, String line) { |
| 570 _ZoneFunction implementation = _delegationTarget._print; | 582 var implementation = _delegationTarget._print; |
| 571 _Zone implZone = implementation.zone; | 583 _Zone implZone = implementation.zone; |
| 572 (implementation.function)( | 584 PrintHandler handler = implementation.function; |
| 573 implZone, _parentDelegate(implZone), zone, line); | 585 handler(implZone, _parentDelegate(implZone), zone, line); |
| 574 } | 586 } |
| 575 | 587 |
| 576 Zone fork(Zone zone, ZoneSpecification specification, | 588 Zone fork(Zone zone, ZoneSpecification specification, |
| 577 Map zoneValues) { | 589 Map zoneValues) { |
| 578 _ZoneFunction implementation = _delegationTarget._fork; | 590 var implementation = _delegationTarget._fork; |
| 579 _Zone implZone = implementation.zone; | 591 _Zone implZone = implementation.zone; |
| 580 return (implementation.function)( | 592 ForkHandler handler = implementation.function; |
| 593 return handler( |
| 581 implZone, _parentDelegate(implZone), zone, specification, zoneValues); | 594 implZone, _parentDelegate(implZone), zone, specification, zoneValues); |
| 582 } | 595 } |
| 583 } | 596 } |
| 584 | 597 |
| 585 | 598 |
| 586 /** | 599 /** |
| 587 * Base class for Zone implementations. | 600 * Base class for Zone implementations. |
| 588 */ | 601 */ |
| 589 abstract class _Zone implements Zone { | 602 abstract class _Zone implements Zone { |
| 590 const _Zone(); | 603 const _Zone(); |
| 591 | 604 |
| 592 _ZoneFunction get _runUnary; | 605 _ZoneFunction<RunHandler> get _run; |
| 593 _ZoneFunction get _run; | 606 _ZoneFunction<RunUnaryHandler> get _runUnary; |
| 594 _ZoneFunction get _runBinary; | 607 _ZoneFunction<RunBinaryHandler> get _runBinary; |
| 595 _ZoneFunction get _registerCallback; | 608 _ZoneFunction<RegisterCallbackHandler> get _registerCallback; |
| 596 _ZoneFunction get _registerUnaryCallback; | 609 _ZoneFunction<RegisterUnaryCallbackHandler> get _registerUnaryCallback; |
| 597 _ZoneFunction get _registerBinaryCallback; | 610 _ZoneFunction<RegisterBinaryCallbackHandler> get _registerBinaryCallback; |
| 598 _ZoneFunction get _errorCallback; | 611 _ZoneFunction<ErrorCallbackHandler> get _errorCallback; |
| 599 _ZoneFunction get _scheduleMicrotask; | 612 _ZoneFunction<ScheduleMicrotaskHandler> get _scheduleMicrotask; |
| 600 _ZoneFunction get _createTimer; | 613 _ZoneFunction<CreateTimerHandler> get _createTimer; |
| 601 _ZoneFunction get _createPeriodicTimer; | 614 _ZoneFunction<CreatePeriodicTimerHandler> get _createPeriodicTimer; |
| 602 _ZoneFunction get _print; | 615 _ZoneFunction<PrintHandler> get _print; |
| 603 _ZoneFunction get _fork; | 616 _ZoneFunction<ForkHandler> get _fork; |
| 604 _ZoneFunction get _handleUncaughtError; | 617 _ZoneFunction<HandleUncaughtErrorHandler> get _handleUncaughtError; |
| 605 _Zone get parent; | 618 _Zone get parent; |
| 606 ZoneDelegate get _delegate; | 619 ZoneDelegate get _delegate; |
| 607 Map get _map; | 620 Map get _map; |
| 608 | 621 |
| 609 bool inSameErrorZone(Zone otherZone) { | 622 bool inSameErrorZone(Zone otherZone) { |
| 610 return identical(this, otherZone) || | 623 return identical(this, otherZone) || |
| 611 identical(errorZone, otherZone.errorZone); | 624 identical(errorZone, otherZone.errorZone); |
| 612 } | 625 } |
| 613 } | 626 } |
| 614 | 627 |
| 615 class _CustomZone extends _Zone { | 628 class _CustomZone extends _Zone { |
| 616 // The actual zone and implementation of each of these | 629 // The actual zone and implementation of each of these |
| 617 // inheritable zone functions. | 630 // inheritable zone functions. |
| 618 _ZoneFunction _runUnary; | 631 _ZoneFunction<RunHandler> _run; |
| 619 _ZoneFunction _run; | 632 _ZoneFunction<RunUnaryHandler> _runUnary; |
| 620 _ZoneFunction _runBinary; | 633 _ZoneFunction<RunBinaryHandler> _runBinary; |
| 621 _ZoneFunction _registerCallback; | 634 _ZoneFunction<RegisterCallbackHandler> _registerCallback; |
| 622 _ZoneFunction _registerUnaryCallback; | 635 _ZoneFunction<RegisterUnaryCallbackHandler> _registerUnaryCallback; |
| 623 _ZoneFunction _registerBinaryCallback; | 636 _ZoneFunction<RegisterBinaryCallbackHandler> _registerBinaryCallback; |
| 624 _ZoneFunction _errorCallback; | 637 _ZoneFunction<ErrorCallbackHandler> _errorCallback; |
| 625 _ZoneFunction _scheduleMicrotask; | 638 _ZoneFunction<ScheduleMicrotaskHandler> _scheduleMicrotask; |
| 626 _ZoneFunction _createTimer; | 639 _ZoneFunction<CreateTimerHandler> _createTimer; |
| 627 _ZoneFunction _createPeriodicTimer; | 640 _ZoneFunction<CreatePeriodicTimerHandler> _createPeriodicTimer; |
| 628 _ZoneFunction _print; | 641 _ZoneFunction<PrintHandler> _print; |
| 629 _ZoneFunction _fork; | 642 _ZoneFunction<ForkHandler> _fork; |
| 630 _ZoneFunction _handleUncaughtError; | 643 _ZoneFunction<HandleUncaughtErrorHandler> _handleUncaughtError; |
| 631 | 644 |
| 632 // A cached delegate to this zone. | 645 // A cached delegate to this zone. |
| 633 ZoneDelegate _delegateCache; | 646 ZoneDelegate _delegateCache; |
| 634 | 647 |
| 635 /// The parent zone. | 648 /// The parent zone. |
| 636 final _Zone parent; | 649 final _Zone parent; |
| 637 | 650 |
| 638 /// The zone's scoped value declaration map. | 651 /// The zone's scoped value declaration map. |
| 639 /// | 652 /// |
| 640 /// This is always a [HashMap]. | 653 /// This is always a [HashMap]. |
| 641 final Map _map; | 654 final Map _map; |
| 642 | 655 |
| 643 ZoneDelegate get _delegate { | 656 ZoneDelegate get _delegate { |
| 644 if (_delegateCache != null) return _delegateCache; | 657 if (_delegateCache != null) return _delegateCache; |
| 645 _delegateCache = new _ZoneDelegate(this); | 658 _delegateCache = new _ZoneDelegate(this); |
| 646 return _delegateCache; | 659 return _delegateCache; |
| 647 } | 660 } |
| 648 | 661 |
| 649 _CustomZone(this.parent, ZoneSpecification specification, this._map) { | 662 _CustomZone(this.parent, ZoneSpecification specification, this._map) { |
| 650 // The root zone will have implementations of all parts of the | 663 // The root zone will have implementations of all parts of the |
| 651 // specification, so it will never try to access the (null) parent. | 664 // specification, so it will never try to access the (null) parent. |
| 652 // All other zones have a non-null parent. | 665 // All other zones have a non-null parent. |
| 653 _run = (specification.run != null) | 666 _run = (specification.run != null) |
| 654 ? new _ZoneFunction(this, specification.run) | 667 ? new _ZoneFunction<RunHandler>(this, specification.run) |
| 655 : parent._run; | 668 : parent._run; |
| 656 _runUnary = (specification.runUnary != null) | 669 _runUnary = (specification.runUnary != null) |
| 657 ? new _ZoneFunction(this, specification.runUnary) | 670 ? new _ZoneFunction<RunUnaryHandler>(this, specification.runUnary) |
| 658 : parent._runUnary; | 671 : parent._runUnary; |
| 659 _runBinary = (specification.runBinary != null) | 672 _runBinary = (specification.runBinary != null) |
| 660 ? new _ZoneFunction(this, specification.runBinary) | 673 ? new _ZoneFunction<RunBinaryHandler>(this, specification.runBinary) |
| 661 : parent._runBinary; | 674 : parent._runBinary; |
| 662 _registerCallback = (specification.registerCallback != null) | 675 _registerCallback = (specification.registerCallback != null) |
| 663 ? new _ZoneFunction(this, specification.registerCallback) | 676 ? new _ZoneFunction<RegisterCallbackHandler>( |
| 677 this, specification.registerCallback) |
| 664 : parent._registerCallback; | 678 : parent._registerCallback; |
| 665 _registerUnaryCallback = (specification.registerUnaryCallback != null) | 679 _registerUnaryCallback = (specification.registerUnaryCallback != null) |
| 666 ? new _ZoneFunction(this, specification.registerUnaryCallback) | 680 ? new _ZoneFunction<RegisterUnaryCallbackHandler>( |
| 681 this, specification.registerUnaryCallback) |
| 667 : parent._registerUnaryCallback; | 682 : parent._registerUnaryCallback; |
| 668 _registerBinaryCallback = (specification.registerBinaryCallback != null) | 683 _registerBinaryCallback = (specification.registerBinaryCallback != null) |
| 669 ? new _ZoneFunction(this, specification.registerBinaryCallback) | 684 ? new _ZoneFunction<RegisterBinaryCallbackHandler>( |
| 685 this, specification.registerBinaryCallback) |
| 670 : parent._registerBinaryCallback; | 686 : parent._registerBinaryCallback; |
| 671 _errorCallback = (specification.errorCallback != null) | 687 _errorCallback = (specification.errorCallback != null) |
| 672 ? new _ZoneFunction(this, specification.errorCallback) | 688 ? new _ZoneFunction<ErrorCallbackHandler>( |
| 689 this, specification.errorCallback) |
| 673 : parent._errorCallback; | 690 : parent._errorCallback; |
| 674 _scheduleMicrotask = (specification.scheduleMicrotask != null) | 691 _scheduleMicrotask = (specification.scheduleMicrotask != null) |
| 675 ? new _ZoneFunction(this, specification.scheduleMicrotask) | 692 ? new _ZoneFunction<ScheduleMicrotaskHandler>( |
| 693 this, specification.scheduleMicrotask) |
| 676 : parent._scheduleMicrotask; | 694 : parent._scheduleMicrotask; |
| 677 _createTimer = (specification.createTimer != null) | 695 _createTimer = (specification.createTimer != null) |
| 678 ? new _ZoneFunction(this, specification.createTimer) | 696 ? new _ZoneFunction<CreateTimerHandler>(this, specification.createTimer) |
| 679 : parent._createTimer; | 697 : parent._createTimer; |
| 680 _createPeriodicTimer = (specification.createPeriodicTimer != null) | 698 _createPeriodicTimer = (specification.createPeriodicTimer != null) |
| 681 ? new _ZoneFunction(this, specification.createPeriodicTimer) | 699 ? new _ZoneFunction<CreatePeriodicTimerHandler>( |
| 700 this, specification.createPeriodicTimer) |
| 682 : parent._createPeriodicTimer; | 701 : parent._createPeriodicTimer; |
| 683 _print = (specification.print != null) | 702 _print = (specification.print != null) |
| 684 ? new _ZoneFunction(this, specification.print) | 703 ? new _ZoneFunction<PrintHandler>(this, specification.print) |
| 685 : parent._print; | 704 : parent._print; |
| 686 _fork = (specification.fork != null) | 705 _fork = (specification.fork != null) |
| 687 ? new _ZoneFunction(this, specification.fork) | 706 ? new _ZoneFunction<ForkHandler>(this, specification.fork) |
| 688 : parent._fork; | 707 : parent._fork; |
| 689 _handleUncaughtError = (specification.handleUncaughtError != null) | 708 _handleUncaughtError = (specification.handleUncaughtError != null) |
| 690 ? new _ZoneFunction(this, specification.handleUncaughtError) | 709 ? new _ZoneFunction<HandleUncaughtErrorHandler>( |
| 710 this, specification.handleUncaughtError) |
| 691 : parent._handleUncaughtError; | 711 : parent._handleUncaughtError; |
| 692 } | 712 } |
| 693 | 713 |
| 694 /** | 714 /** |
| 695 * The closest error-handling zone. | 715 * The closest error-handling zone. |
| 696 * | 716 * |
| 697 * Returns `this` if `this` has an error-handler. Otherwise returns the | 717 * Returns `this` if `this` has an error-handler. Otherwise returns the |
| 698 * parent's error-zone. | 718 * parent's error-zone. |
| 699 */ | 719 */ |
| 700 Zone get errorZone => _handleUncaughtError.zone; | 720 Zone get errorZone => _handleUncaughtError.zone; |
| 701 | 721 |
| 702 dynamic runGuarded(f()) { | 722 /*=R*/ runGuarded/*<R>*/(/*=R*/ f()) { |
| 703 try { | 723 try { |
| 704 return run(f); | 724 return run(f); |
| 705 } catch (e, s) { | 725 } catch (e, s) { |
| 706 return handleUncaughtError(e, s); | 726 return handleUncaughtError(e, s); |
| 707 } | 727 } |
| 708 } | 728 } |
| 709 | 729 |
| 710 dynamic runUnaryGuarded(f(arg), arg) { | 730 /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
| 711 try { | 731 try { |
| 712 return runUnary(f, arg); | 732 return runUnary(f, arg); |
| 713 } catch (e, s) { | 733 } catch (e, s) { |
| 714 return handleUncaughtError(e, s); | 734 return handleUncaughtError(e, s); |
| 715 } | 735 } |
| 716 } | 736 } |
| 717 | 737 |
| 718 dynamic runBinaryGuarded(f(arg1, arg2), arg1, arg2) { | 738 /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( |
| 739 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
| 719 try { | 740 try { |
| 720 return runBinary(f, arg1, arg2); | 741 return runBinary(f, arg1, arg2); |
| 721 } catch (e, s) { | 742 } catch (e, s) { |
| 722 return handleUncaughtError(e, s); | 743 return handleUncaughtError(e, s); |
| 723 } | 744 } |
| 724 } | 745 } |
| 725 | 746 |
| 726 ZoneCallback bindCallback(f(), { bool runGuarded: true }) { | 747 ZoneCallback/*<R>*/ bindCallback/*<R>*/( |
| 727 ZoneCallback registered = registerCallback(f); | 748 /*=R*/ f(), { bool runGuarded: true }) { |
| 749 var registered = registerCallback(f); |
| 728 if (runGuarded) { | 750 if (runGuarded) { |
| 729 return () => this.runGuarded(registered); | 751 return () => this.runGuarded(registered); |
| 730 } else { | 752 } else { |
| 731 return () => this.run(registered); | 753 return () => this.run(registered); |
| 732 } | 754 } |
| 733 } | 755 } |
| 734 | 756 |
| 735 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }) { | 757 ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( |
| 736 ZoneUnaryCallback registered = registerUnaryCallback(f); | 758 /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }) { |
| 759 var registered = registerUnaryCallback(f); |
| 737 if (runGuarded) { | 760 if (runGuarded) { |
| 738 return (arg) => this.runUnaryGuarded(registered, arg); | 761 return (arg) => this.runUnaryGuarded(registered, arg); |
| 739 } else { | 762 } else { |
| 740 return (arg) => this.runUnary(registered, arg); | 763 return (arg) => this.runUnary(registered, arg); |
| 741 } | 764 } |
| 742 } | 765 } |
| 743 | 766 |
| 744 ZoneBinaryCallback bindBinaryCallback( | 767 ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( |
| 745 f(arg1, arg2), { bool runGuarded: true }) { | 768 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }) { |
| 746 ZoneBinaryCallback registered = registerBinaryCallback(f); | 769 var registered = registerBinaryCallback(f); |
| 747 if (runGuarded) { | 770 if (runGuarded) { |
| 748 return (arg1, arg2) => this.runBinaryGuarded(registered, arg1, arg2); | 771 return (arg1, arg2) => this.runBinaryGuarded(registered, arg1, arg2); |
| 749 } else { | 772 } else { |
| 750 return (arg1, arg2) => this.runBinary(registered, arg1, arg2); | 773 return (arg1, arg2) => this.runBinary(registered, arg1, arg2); |
| 751 } | 774 } |
| 752 } | 775 } |
| 753 | 776 |
| 754 operator [](Object key) { | 777 operator [](Object key) { |
| 755 var result = _map[key]; | 778 var result = _map[key]; |
| 756 if (result != null || _map.containsKey(key)) return result; | 779 if (result != null || _map.containsKey(key)) return result; |
| 757 // If we are not the root zone, look up in the parent zone. | 780 // If we are not the root zone, look up in the parent zone. |
| 758 if (parent != null) { | 781 if (parent != null) { |
| 759 // We do not optimize for repeatedly looking up a key which isn't | 782 // We do not optimize for repeatedly looking up a key which isn't |
| 760 // there. That would require storing the key and keeping it alive. | 783 // there. That would require storing the key and keeping it alive. |
| 761 // Copying the key/value from the parent does not keep any new values | 784 // Copying the key/value from the parent does not keep any new values |
| 762 // alive. | 785 // alive. |
| 763 var value = parent[key]; | 786 var value = parent[key]; |
| 764 if (value != null) { | 787 if (value != null) { |
| 765 _map[key] = value; | 788 _map[key] = value; |
| 766 } | 789 } |
| 767 return value; | 790 return value; |
| 768 } | 791 } |
| 769 assert(this == _ROOT_ZONE); | 792 assert(this == _ROOT_ZONE); |
| 770 return null; | 793 return null; |
| 771 } | 794 } |
| 772 | 795 |
| 773 // Methods that can be customized by the zone specification. | 796 // Methods that can be customized by the zone specification. |
| 774 | 797 |
| 775 dynamic handleUncaughtError(error, StackTrace stackTrace) { | 798 /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace) { |
| 776 _ZoneFunction implementation = this._handleUncaughtError; | 799 var implementation = this._handleUncaughtError; |
| 777 assert(implementation != null); | 800 assert(implementation != null); |
| 778 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 801 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 779 return (implementation.function)( | 802 HandleUncaughtErrorHandler handler = implementation.function; |
| 780 implementation.zone, parentDelegate, this, error, stackTrace); | 803 // TODO(floitsch): make this a generic method call on '<R>' once it's |
| 804 // supported. Remove the unnecessary cast. |
| 805 return handler( |
| 806 implementation.zone, parentDelegate, this, error, stackTrace) |
| 807 as Object/*=R*/; |
| 781 } | 808 } |
| 782 | 809 |
| 783 Zone fork({ZoneSpecification specification, Map zoneValues}) { | 810 Zone fork({ZoneSpecification specification, Map zoneValues}) { |
| 784 _ZoneFunction implementation = this._fork; | 811 var implementation = this._fork; |
| 785 assert(implementation != null); | 812 assert(implementation != null); |
| 786 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 813 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 787 return (implementation.function)( | 814 ForkHandler handler = implementation.function; |
| 788 implementation.zone, parentDelegate, this, | 815 return handler(implementation.zone, parentDelegate, this, |
| 789 specification, zoneValues); | 816 specification, zoneValues); |
| 790 } | 817 } |
| 791 | 818 |
| 792 dynamic run(f()) { | 819 /*=R*/ run/*<R>*/(/*=R*/ f()) { |
| 793 _ZoneFunction implementation = this._run; | 820 var implementation = this._run; |
| 794 assert(implementation != null); | 821 assert(implementation != null); |
| 795 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 822 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 796 return (implementation.function)( | 823 RunHandler handler = implementation.function; |
| 797 implementation.zone, parentDelegate, this, f); | 824 // TODO(floitsch): make this a generic method call on '<R>' once it's |
| 825 // supported. Remove the unnecessary cast. |
| 826 return handler(implementation.zone, parentDelegate, this, f) |
| 827 as Object/*=R*/; |
| 798 } | 828 } |
| 799 | 829 |
| 800 dynamic runUnary(f(arg), arg) { | 830 /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
| 801 _ZoneFunction implementation = this._runUnary; | 831 var implementation = this._runUnary; |
| 802 assert(implementation != null); | 832 assert(implementation != null); |
| 803 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 833 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 804 return (implementation.function)( | 834 RunUnaryHandler handler = implementation.function; |
| 805 implementation.zone, parentDelegate, this, f, arg); | 835 // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
| 836 // supported. Remove the unnecessary cast. |
| 837 return handler(implementation.zone, parentDelegate, this, f, arg) |
| 838 as Object/*=R*/; |
| 806 } | 839 } |
| 807 | 840 |
| 808 dynamic runBinary(f(arg1, arg2), arg1, arg2) { | 841 /*=R*/ runBinary/*<R, T1, T2>*/( |
| 809 _ZoneFunction implementation = this._runBinary; | 842 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
| 843 var implementation = this._runBinary; |
| 810 assert(implementation != null); | 844 assert(implementation != null); |
| 811 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 845 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 812 return (implementation.function)( | 846 RunBinaryHandler handler = implementation.function; |
| 813 implementation.zone, parentDelegate, this, f, arg1, arg2); | 847 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
| 848 // it's supported. Remove the unnecessary cast. |
| 849 return handler( |
| 850 implementation.zone, parentDelegate, this, f, arg1, arg2) |
| 851 as Object/*=R*/; |
| 814 } | 852 } |
| 815 | 853 |
| 816 ZoneCallback registerCallback(f()) { | 854 ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ callback()) { |
| 817 _ZoneFunction implementation = this._registerCallback; | 855 var implementation = this._registerCallback; |
| 818 assert(implementation != null); | 856 assert(implementation != null); |
| 819 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 857 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 820 return (implementation.function)( | 858 RegisterCallbackHandler handler = implementation.function; |
| 821 implementation.zone, parentDelegate, this, f); | 859 // TODO(floitsch): make this a generic method call on '<R>' once it's |
| 860 // supported. Remove the unnecessary cast. |
| 861 return handler(implementation.zone, parentDelegate, this, callback) |
| 862 as Object/*=ZoneCallback<R>*/; |
| 822 } | 863 } |
| 823 | 864 |
| 824 ZoneUnaryCallback registerUnaryCallback(f(arg)) { | 865 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
| 825 _ZoneFunction implementation = this._registerUnaryCallback; | 866 /*=R*/ callback(/*=T*/ arg)) { |
| 867 var implementation = this._registerUnaryCallback; |
| 826 assert(implementation != null); | 868 assert(implementation != null); |
| 827 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 869 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 828 return (implementation.function)( | 870 RegisterUnaryCallbackHandler handler = implementation.function; |
| 829 implementation.zone, parentDelegate, this, f); | 871 // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
| 872 // supported. Remove the unnecessary cast. |
| 873 return handler(implementation.zone, parentDelegate, this, callback) |
| 874 as Object/*=ZoneUnaryCallback<R, T>*/; |
| 830 } | 875 } |
| 831 | 876 |
| 832 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { | 877 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
| 833 _ZoneFunction implementation = this._registerBinaryCallback; | 878 /*=R*/ callback(/*=T1*/ arg1, /*=T2*/ arg2)) { |
| 879 var implementation = this._registerBinaryCallback; |
| 834 assert(implementation != null); | 880 assert(implementation != null); |
| 835 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 881 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 836 return (implementation.function)( | 882 RegisterBinaryCallbackHandler handler = implementation.function; |
| 837 implementation.zone, parentDelegate, this, f); | 883 // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
| 884 // it's supported. Remove the unnecessary cast. |
| 885 return handler(implementation.zone, parentDelegate, this, callback) |
| 886 as Object/*=ZoneBinaryCallback<R, T1, T2>*/; |
| 838 } | 887 } |
| 839 | 888 |
| 840 AsyncError errorCallback(Object error, StackTrace stackTrace) { | 889 AsyncError errorCallback(Object error, StackTrace stackTrace) { |
| 841 final _ZoneFunction implementation = this._errorCallback; | 890 var implementation = this._errorCallback; |
| 842 assert(implementation != null); | 891 assert(implementation != null); |
| 843 final Zone implementationZone = implementation.zone; | 892 final Zone implementationZone = implementation.zone; |
| 844 if (identical(implementationZone, _ROOT_ZONE)) return null; | 893 if (identical(implementationZone, _ROOT_ZONE)) return null; |
| 845 final ZoneDelegate parentDelegate = _parentDelegate(implementationZone); | 894 final ZoneDelegate parentDelegate = _parentDelegate(implementationZone); |
| 846 return (implementation.function)( | 895 ErrorCallbackHandler handler = implementation.function; |
| 896 return handler( |
| 847 implementationZone, parentDelegate, this, error, stackTrace); | 897 implementationZone, parentDelegate, this, error, stackTrace); |
| 848 } | 898 } |
| 849 | 899 |
| 850 void scheduleMicrotask(void f()) { | 900 void scheduleMicrotask(void f()) { |
| 851 _ZoneFunction implementation = this._scheduleMicrotask; | 901 var implementation = this._scheduleMicrotask; |
| 852 assert(implementation != null); | 902 assert(implementation != null); |
| 853 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 903 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 854 return (implementation.function)( | 904 ScheduleMicrotaskHandler handler = implementation.function; |
| 855 implementation.zone, parentDelegate, this, f); | 905 return handler(implementation.zone, parentDelegate, this, f); |
| 856 } | 906 } |
| 857 | 907 |
| 858 Timer createTimer(Duration duration, void f()) { | 908 Timer createTimer(Duration duration, void f()) { |
| 859 _ZoneFunction implementation = this._createTimer; | 909 var implementation = this._createTimer; |
| 860 assert(implementation != null); | 910 assert(implementation != null); |
| 861 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 911 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 862 return (implementation.function)( | 912 CreateTimerHandler handler = implementation.function; |
| 863 implementation.zone, parentDelegate, this, duration, f); | 913 return handler(implementation.zone, parentDelegate, this, duration, f); |
| 864 } | 914 } |
| 865 | 915 |
| 866 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { | 916 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
| 867 _ZoneFunction implementation = this._createPeriodicTimer; | 917 var implementation = this._createPeriodicTimer; |
| 868 assert(implementation != null); | 918 assert(implementation != null); |
| 869 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 919 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 870 return (implementation.function)( | 920 CreatePeriodicTimerHandler handler = implementation.function; |
| 921 return handler( |
| 871 implementation.zone, parentDelegate, this, duration, f); | 922 implementation.zone, parentDelegate, this, duration, f); |
| 872 } | 923 } |
| 873 | 924 |
| 874 void print(String line) { | 925 void print(String line) { |
| 875 _ZoneFunction implementation = this._print; | 926 var implementation = this._print; |
| 876 assert(implementation != null); | 927 assert(implementation != null); |
| 877 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 928 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
| 878 return (implementation.function)( | 929 PrintHandler handler = implementation.function; |
| 879 implementation.zone, parentDelegate, this, line); | 930 return handler(implementation.zone, parentDelegate, this, line); |
| 880 } | 931 } |
| 881 } | 932 } |
| 882 | 933 |
| 883 void _rootHandleUncaughtError( | 934 /*=R*/ _rootHandleUncaughtError/*<R>*/( |
| 884 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { | 935 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { |
| 885 _schedulePriorityAsyncCallback(() { | 936 _schedulePriorityAsyncCallback(() { |
| 886 throw new _UncaughtAsyncError(error, stackTrace); | 937 if (error == null) error = new NullThrownError(); |
| 938 if (stackTrace == null) throw error; |
| 939 _rethrow(error, stackTrace); |
| 887 }); | 940 }); |
| 888 } | 941 } |
| 889 | 942 |
| 890 dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { | 943 external void _rethrow(Object error, StackTrace stackTrace); |
| 944 |
| 945 /*=R*/ _rootRun/*<R>*/(Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f()) { |
| 891 if (Zone._current == zone) return f(); | 946 if (Zone._current == zone) return f(); |
| 892 | 947 |
| 893 Zone old = Zone._enter(zone); | 948 Zone old = Zone._enter(zone); |
| 894 try { | 949 try { |
| 895 return f(); | 950 return f(); |
| 896 } finally { | 951 } finally { |
| 897 Zone._leave(old); | 952 Zone._leave(old); |
| 898 } | 953 } |
| 899 } | 954 } |
| 900 | 955 |
| 901 dynamic _rootRunUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) { | 956 /*=R*/ _rootRunUnary/*<R, T>*/(Zone self, ZoneDelegate parent, Zone zone, |
| 957 /*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
| 902 if (Zone._current == zone) return f(arg); | 958 if (Zone._current == zone) return f(arg); |
| 903 | 959 |
| 904 Zone old = Zone._enter(zone); | 960 Zone old = Zone._enter(zone); |
| 905 try { | 961 try { |
| 906 return f(arg); | 962 return f(arg); |
| 907 } finally { | 963 } finally { |
| 908 Zone._leave(old); | 964 Zone._leave(old); |
| 909 } | 965 } |
| 910 } | 966 } |
| 911 | 967 |
| 912 dynamic _rootRunBinary(Zone self, ZoneDelegate parent, Zone zone, | 968 /*=R*/ _rootRunBinary/*<R, T1, T2>*/(Zone self, ZoneDelegate parent, Zone zone, |
| 913 f(arg1, arg2), arg1, arg2) { | 969 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
| 914 if (Zone._current == zone) return f(arg1, arg2); | 970 if (Zone._current == zone) return f(arg1, arg2); |
| 915 | 971 |
| 916 Zone old = Zone._enter(zone); | 972 Zone old = Zone._enter(zone); |
| 917 try { | 973 try { |
| 918 return f(arg1, arg2); | 974 return f(arg1, arg2); |
| 919 } finally { | 975 } finally { |
| 920 Zone._leave(old); | 976 Zone._leave(old); |
| 921 } | 977 } |
| 922 } | 978 } |
| 923 | 979 |
| 924 ZoneCallback _rootRegisterCallback( | 980 ZoneCallback/*<R>*/ _rootRegisterCallback/*<R>*/( |
| 925 Zone self, ZoneDelegate parent, Zone zone, f()) { | 981 Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f()) { |
| 926 return f; | 982 return f; |
| 927 } | 983 } |
| 928 | 984 |
| 929 ZoneUnaryCallback _rootRegisterUnaryCallback( | 985 ZoneUnaryCallback/*<R, T>*/ _rootRegisterUnaryCallback/*<R, T>*/( |
| 930 Zone self, ZoneDelegate parent, Zone zone, f(arg)) { | 986 Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f(/*=T*/ arg)) { |
| 931 return f; | 987 return f; |
| 932 } | 988 } |
| 933 | 989 |
| 934 ZoneBinaryCallback _rootRegisterBinaryCallback( | 990 ZoneBinaryCallback/*<R, T1, T2>*/ _rootRegisterBinaryCallback/*<R, T1, T2>*/( |
| 935 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) { | 991 Zone self, ZoneDelegate parent, Zone zone, |
| 992 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) { |
| 936 return f; | 993 return f; |
| 937 } | 994 } |
| 938 | 995 |
| 939 AsyncError _rootErrorCallback(Zone self, ZoneDelegate parent, Zone zone, | 996 AsyncError _rootErrorCallback(Zone self, ZoneDelegate parent, Zone zone, |
| 940 Object error, StackTrace stackTrace) => null; | 997 Object error, StackTrace stackTrace) => null; |
| 941 | 998 |
| 942 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { | 999 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { |
| 943 if (!identical(_ROOT_ZONE, zone)) { | 1000 if (!identical(_ROOT_ZONE, zone)) { |
| 944 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); | 1001 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); |
| 945 f = zone.bindCallback(f, runGuarded: hasErrorHandler); | 1002 f = zone.bindCallback(f, runGuarded: hasErrorHandler); |
| 1003 // Use root zone as event zone if the function is already bound. |
| 1004 zone = _ROOT_ZONE; |
| 946 } | 1005 } |
| 947 _scheduleAsyncCallback(f); | 1006 _scheduleAsyncCallback(f); |
| 948 } | 1007 } |
| 949 | 1008 |
| 950 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, | 1009 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, |
| 951 Duration duration, void callback()) { | 1010 Duration duration, void callback()) { |
| 952 if (!identical(_ROOT_ZONE, zone)) { | 1011 if (!identical(_ROOT_ZONE, zone)) { |
| 953 callback = zone.bindCallback(callback); | 1012 callback = zone.bindCallback(callback); |
| 954 } | 1013 } |
| 955 return Timer._createTimer(duration, callback); | 1014 return Timer._createTimer(duration, callback); |
| 956 } | 1015 } |
| 957 | 1016 |
| 958 Timer _rootCreatePeriodicTimer( | 1017 Timer _rootCreatePeriodicTimer( |
| 959 Zone self, ZoneDelegate parent, Zone zone, | 1018 Zone self, ZoneDelegate parent, Zone zone, |
| 960 Duration duration, void callback(Timer timer)) { | 1019 Duration duration, void callback(Timer timer)) { |
| 961 if (!identical(_ROOT_ZONE, zone)) { | 1020 if (!identical(_ROOT_ZONE, zone)) { |
| 962 callback = zone.bindUnaryCallback(callback); | 1021 // TODO(floitsch): the return type should be 'void'. |
| 1022 callback = zone.bindUnaryCallback/*<dynamic, Timer>*/(callback); |
| 963 } | 1023 } |
| 964 return Timer._createPeriodicTimer(duration, callback); | 1024 return Timer._createPeriodicTimer(duration, callback); |
| 965 } | 1025 } |
| 966 | 1026 |
| 967 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { | 1027 void _rootPrint(Zone self, ZoneDelegate parent, Zone zone, String line) { |
| 968 printToConsole(line); | 1028 printToConsole(line); |
| 969 } | 1029 } |
| 970 | 1030 |
| 971 void _printToZone(String line) { | 1031 void _printToZone(String line) { |
| 972 Zone.current.print(line); | 1032 Zone.current.print(line); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 992 valueMap = zone._map; | 1052 valueMap = zone._map; |
| 993 } else { | 1053 } else { |
| 994 valueMap = new HashMap(); | 1054 valueMap = new HashMap(); |
| 995 } | 1055 } |
| 996 } else { | 1056 } else { |
| 997 valueMap = new HashMap.from(zoneValues); | 1057 valueMap = new HashMap.from(zoneValues); |
| 998 } | 1058 } |
| 999 return new _CustomZone(zone, specification, valueMap); | 1059 return new _CustomZone(zone, specification, valueMap); |
| 1000 } | 1060 } |
| 1001 | 1061 |
| 1002 class _RootZoneSpecification implements ZoneSpecification { | |
| 1003 HandleUncaughtErrorHandler get handleUncaughtError => | |
| 1004 _rootHandleUncaughtError; | |
| 1005 RunHandler get run => _rootRun; | |
| 1006 RunUnaryHandler get runUnary => _rootRunUnary; | |
| 1007 RunBinaryHandler get runBinary => _rootRunBinary; | |
| 1008 RegisterCallbackHandler get registerCallback => _rootRegisterCallback; | |
| 1009 RegisterUnaryCallbackHandler get registerUnaryCallback => | |
| 1010 _rootRegisterUnaryCallback; | |
| 1011 RegisterBinaryCallbackHandler get registerBinaryCallback => | |
| 1012 _rootRegisterBinaryCallback; | |
| 1013 ErrorCallbackHandler get errorCallback => _rootErrorCallback; | |
| 1014 ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; | |
| 1015 CreateTimerHandler get createTimer => _rootCreateTimer; | |
| 1016 CreatePeriodicTimerHandler get createPeriodicTimer => | |
| 1017 _rootCreatePeriodicTimer; | |
| 1018 PrintHandler get print => _rootPrint; | |
| 1019 ForkHandler get fork => _rootFork; | |
| 1020 } | |
| 1021 | |
| 1022 class _RootZone extends _Zone { | 1062 class _RootZone extends _Zone { |
| 1023 const _RootZone(); | 1063 const _RootZone(); |
| 1024 | 1064 |
| 1025 _ZoneFunction get _run => | 1065 _ZoneFunction<RunHandler> get _run => |
| 1026 const _ZoneFunction(_ROOT_ZONE, _rootRun); | 1066 const _ZoneFunction<RunHandler>(_ROOT_ZONE, _rootRun); |
| 1027 _ZoneFunction get _runUnary => | 1067 _ZoneFunction<RunUnaryHandler> get _runUnary => |
| 1028 const _ZoneFunction(_ROOT_ZONE, _rootRunUnary); | 1068 const _ZoneFunction<RunUnaryHandler>(_ROOT_ZONE, _rootRunUnary); |
| 1029 _ZoneFunction get _runBinary => | 1069 _ZoneFunction<RunBinaryHandler> get _runBinary => |
| 1030 const _ZoneFunction(_ROOT_ZONE, _rootRunBinary); | 1070 const _ZoneFunction<RunBinaryHandler>(_ROOT_ZONE, _rootRunBinary); |
| 1031 _ZoneFunction get _registerCallback => | 1071 _ZoneFunction<RegisterCallbackHandler> get _registerCallback => |
| 1032 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback); | 1072 const _ZoneFunction<RegisterCallbackHandler>( |
| 1033 _ZoneFunction get _registerUnaryCallback => | 1073 _ROOT_ZONE, _rootRegisterCallback); |
| 1034 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback); | 1074 _ZoneFunction<RegisterUnaryCallbackHandler> get _registerUnaryCallback => |
| 1035 _ZoneFunction get _registerBinaryCallback => | 1075 const _ZoneFunction<RegisterUnaryCallbackHandler>( |
| 1036 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback); | 1076 _ROOT_ZONE, _rootRegisterUnaryCallback); |
| 1037 _ZoneFunction get _errorCallback => | 1077 _ZoneFunction<RegisterBinaryCallbackHandler> get _registerBinaryCallback => |
| 1038 const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback); | 1078 const _ZoneFunction<RegisterBinaryCallbackHandler>( |
| 1039 _ZoneFunction get _scheduleMicrotask => | 1079 _ROOT_ZONE, _rootRegisterBinaryCallback); |
| 1040 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); | 1080 _ZoneFunction<ErrorCallbackHandler> get _errorCallback => |
| 1041 _ZoneFunction get _createTimer => | 1081 const _ZoneFunction<ErrorCallbackHandler>(_ROOT_ZONE, _rootErrorCallback); |
| 1042 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); | 1082 _ZoneFunction<ScheduleMicrotaskHandler> get _scheduleMicrotask => |
| 1043 _ZoneFunction get _createPeriodicTimer => | 1083 const _ZoneFunction<ScheduleMicrotaskHandler>( |
| 1044 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); | 1084 _ROOT_ZONE, _rootScheduleMicrotask); |
| 1045 _ZoneFunction get _print => | 1085 _ZoneFunction<CreateTimerHandler> get _createTimer => |
| 1046 const _ZoneFunction(_ROOT_ZONE, _rootPrint); | 1086 const _ZoneFunction<CreateTimerHandler>(_ROOT_ZONE, _rootCreateTimer); |
| 1047 _ZoneFunction get _fork => | 1087 _ZoneFunction<CreatePeriodicTimerHandler> get _createPeriodicTimer => |
| 1048 const _ZoneFunction(_ROOT_ZONE, _rootFork); | 1088 const _ZoneFunction<CreatePeriodicTimerHandler>(_ROOT_ZONE, _rootCreatePer
iodicTimer); |
| 1049 _ZoneFunction get _handleUncaughtError => | 1089 _ZoneFunction<PrintHandler> get _print => |
| 1050 const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError); | 1090 const _ZoneFunction<PrintHandler>(_ROOT_ZONE, _rootPrint); |
| 1091 _ZoneFunction<ForkHandler> get _fork => |
| 1092 const _ZoneFunction<ForkHandler>(_ROOT_ZONE, _rootFork); |
| 1093 _ZoneFunction<HandleUncaughtErrorHandler> get _handleUncaughtError => |
| 1094 const _ZoneFunction<HandleUncaughtErrorHandler>( |
| 1095 _ROOT_ZONE, _rootHandleUncaughtError); |
| 1051 | 1096 |
| 1052 // The parent zone. | 1097 // The parent zone. |
| 1053 _Zone get parent => null; | 1098 _Zone get parent => null; |
| 1054 | 1099 |
| 1055 /// The zone's scoped value declaration map. | 1100 /// The zone's scoped value declaration map. |
| 1056 /// | 1101 /// |
| 1057 /// This is always a [HashMap]. | 1102 /// This is always a [HashMap]. |
| 1058 Map get _map => _rootMap; | 1103 Map get _map => _rootMap; |
| 1059 | 1104 |
| 1060 static Map _rootMap = new HashMap(); | 1105 static Map _rootMap = new HashMap(); |
| 1061 | 1106 |
| 1062 static ZoneDelegate _rootDelegate; | 1107 static ZoneDelegate _rootDelegate; |
| 1063 | 1108 |
| 1064 ZoneDelegate get _delegate { | 1109 ZoneDelegate get _delegate { |
| 1065 if (_rootDelegate != null) return _rootDelegate; | 1110 if (_rootDelegate != null) return _rootDelegate; |
| 1066 return _rootDelegate = new _ZoneDelegate(this); | 1111 return _rootDelegate = new _ZoneDelegate(this); |
| 1067 } | 1112 } |
| 1068 | 1113 |
| 1069 /** | 1114 /** |
| 1070 * The closest error-handling zone. | 1115 * The closest error-handling zone. |
| 1071 * | 1116 * |
| 1072 * Returns `this` if `this` has an error-handler. Otherwise returns the | 1117 * Returns `this` if `this` has an error-handler. Otherwise returns the |
| 1073 * parent's error-zone. | 1118 * parent's error-zone. |
| 1074 */ | 1119 */ |
| 1075 Zone get errorZone => this; | 1120 Zone get errorZone => this; |
| 1076 | 1121 |
| 1077 // Zone interface. | 1122 // Zone interface. |
| 1078 | 1123 |
| 1079 dynamic runGuarded(f()) { | 1124 /*=R*/ runGuarded/*<R>*/(/*=R*/ f()) { |
| 1080 try { | 1125 try { |
| 1081 if (identical(_ROOT_ZONE, Zone._current)) { | 1126 if (identical(_ROOT_ZONE, Zone._current)) { |
| 1082 return f(); | 1127 return f(); |
| 1083 } | 1128 } |
| 1084 return _rootRun(null, null, this, f); | 1129 return _rootRun/*<R>*/(null, null, this, f); |
| 1085 } catch (e, s) { | 1130 } catch (e, s) { |
| 1086 return handleUncaughtError(e, s); | 1131 return handleUncaughtError/*<R>*/(e, s); |
| 1087 } | 1132 } |
| 1088 } | 1133 } |
| 1089 | 1134 |
| 1090 dynamic runUnaryGuarded(f(arg), arg) { | 1135 /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
| 1091 try { | 1136 try { |
| 1092 if (identical(_ROOT_ZONE, Zone._current)) { | 1137 if (identical(_ROOT_ZONE, Zone._current)) { |
| 1093 return f(arg); | 1138 return f(arg); |
| 1094 } | 1139 } |
| 1095 return _rootRunUnary(null, null, this, f, arg); | 1140 return _rootRunUnary/*<R, T>*/(null, null, this, f, arg); |
| 1096 } catch (e, s) { | 1141 } catch (e, s) { |
| 1097 return handleUncaughtError(e, s); | 1142 return handleUncaughtError/*<R>*/(e, s); |
| 1098 } | 1143 } |
| 1099 } | 1144 } |
| 1100 | 1145 |
| 1101 dynamic runBinaryGuarded(f(arg1, arg2), arg1, arg2) { | 1146 /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( |
| 1147 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
| 1102 try { | 1148 try { |
| 1103 if (identical(_ROOT_ZONE, Zone._current)) { | 1149 if (identical(_ROOT_ZONE, Zone._current)) { |
| 1104 return f(arg1, arg2); | 1150 return f(arg1, arg2); |
| 1105 } | 1151 } |
| 1106 return _rootRunBinary(null, null, this, f, arg1, arg2); | 1152 return _rootRunBinary/*<R, T1, T2>*/(null, null, this, f, arg1, arg2); |
| 1107 } catch (e, s) { | 1153 } catch (e, s) { |
| 1108 return handleUncaughtError(e, s); | 1154 return handleUncaughtError/*<R>*/(e, s); |
| 1109 } | 1155 } |
| 1110 } | 1156 } |
| 1111 | 1157 |
| 1112 ZoneCallback bindCallback(f(), { bool runGuarded: true }) { | 1158 ZoneCallback/*<R>*/ bindCallback/*<R>*/( |
| 1159 /*=R*/ f(), { bool runGuarded: true }) { |
| 1113 if (runGuarded) { | 1160 if (runGuarded) { |
| 1114 return () => this.runGuarded(f); | 1161 return () => this.runGuarded/*<R>*/(f); |
| 1115 } else { | 1162 } else { |
| 1116 return () => this.run(f); | 1163 return () => this.run/*<R>*/(f); |
| 1117 } | 1164 } |
| 1118 } | 1165 } |
| 1119 | 1166 |
| 1120 ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }) { | 1167 ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( |
| 1168 /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }) { |
| 1121 if (runGuarded) { | 1169 if (runGuarded) { |
| 1122 return (arg) => this.runUnaryGuarded(f, arg); | 1170 return (arg) => this.runUnaryGuarded/*<R, T>*/(f, arg); |
| 1123 } else { | 1171 } else { |
| 1124 return (arg) => this.runUnary(f, arg); | 1172 return (arg) => this.runUnary/*<R, T>*/(f, arg); |
| 1125 } | 1173 } |
| 1126 } | 1174 } |
| 1127 | 1175 |
| 1128 ZoneBinaryCallback bindBinaryCallback( | 1176 ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( |
| 1129 f(arg1, arg2), { bool runGuarded: true }) { | 1177 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }) { |
| 1130 if (runGuarded) { | 1178 if (runGuarded) { |
| 1131 return (arg1, arg2) => this.runBinaryGuarded(f, arg1, arg2); | 1179 return (arg1, arg2) => |
| 1180 this.runBinaryGuarded/*<R, T1, T2>*/(f, arg1, arg2); |
| 1132 } else { | 1181 } else { |
| 1133 return (arg1, arg2) => this.runBinary(f, arg1, arg2); | 1182 return (arg1, arg2) => this.runBinary/*<R, T1, T2>*/(f, arg1, arg2); |
| 1134 } | 1183 } |
| 1135 } | 1184 } |
| 1136 | 1185 |
| 1137 operator [](Object key) => null; | 1186 operator [](Object key) => null; |
| 1138 | 1187 |
| 1139 // Methods that can be customized by the zone specification. | 1188 // Methods that can be customized by the zone specification. |
| 1140 | 1189 |
| 1141 dynamic handleUncaughtError(error, StackTrace stackTrace) { | 1190 /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace) { |
| 1142 return _rootHandleUncaughtError(null, null, this, error, stackTrace); | 1191 return _rootHandleUncaughtError(null, null, this, error, stackTrace); |
| 1143 } | 1192 } |
| 1144 | 1193 |
| 1145 Zone fork({ZoneSpecification specification, Map zoneValues}) { | 1194 Zone fork({ZoneSpecification specification, Map zoneValues}) { |
| 1146 return _rootFork(null, null, this, specification, zoneValues); | 1195 return _rootFork(null, null, this, specification, zoneValues); |
| 1147 } | 1196 } |
| 1148 | 1197 |
| 1149 dynamic run(f()) { | 1198 /*=R*/ run/*<R>*/(/*=R*/ f()) { |
| 1150 if (identical(Zone._current, _ROOT_ZONE)) return f(); | 1199 if (identical(Zone._current, _ROOT_ZONE)) return f(); |
| 1151 return _rootRun(null, null, this, f); | 1200 return _rootRun(null, null, this, f); |
| 1152 } | 1201 } |
| 1153 | 1202 |
| 1154 dynamic runUnary(f(arg), arg) { | 1203 /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
| 1155 if (identical(Zone._current, _ROOT_ZONE)) return f(arg); | 1204 if (identical(Zone._current, _ROOT_ZONE)) return f(arg); |
| 1156 return _rootRunUnary(null, null, this, f, arg); | 1205 return _rootRunUnary(null, null, this, f, arg); |
| 1157 } | 1206 } |
| 1158 | 1207 |
| 1159 dynamic runBinary(f(arg1, arg2), arg1, arg2) { | 1208 /*=R*/ runBinary/*<R, T1, T2>*/( |
| 1209 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
| 1160 if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2); | 1210 if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2); |
| 1161 return _rootRunBinary(null, null, this, f, arg1, arg2); | 1211 return _rootRunBinary(null, null, this, f, arg1, arg2); |
| 1162 } | 1212 } |
| 1163 | 1213 |
| 1164 ZoneCallback registerCallback(f()) => f; | 1214 ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ f()) => f; |
| 1165 | 1215 |
| 1166 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f; | 1216 ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
| 1217 /*=R*/ f(/*=T*/ arg)) => f; |
| 1167 | 1218 |
| 1168 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f; | 1219 ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
| 1220 /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) => f; |
| 1169 | 1221 |
| 1170 AsyncError errorCallback(Object error, StackTrace stackTrace) => null; | 1222 AsyncError errorCallback(Object error, StackTrace stackTrace) => null; |
| 1171 | 1223 |
| 1172 void scheduleMicrotask(void f()) { | 1224 void scheduleMicrotask(void f()) { |
| 1173 _rootScheduleMicrotask(null, null, this, f); | 1225 _rootScheduleMicrotask(null, null, this, f); |
| 1174 } | 1226 } |
| 1175 | 1227 |
| 1176 Timer createTimer(Duration duration, void f()) { | 1228 Timer createTimer(Duration duration, void f()) { |
| 1177 return Timer._createTimer(duration, f); | 1229 return Timer._createTimer(duration, f); |
| 1178 } | 1230 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1206 * future = future.catchError((e) { print("Never reached!"); }); | 1258 * future = future.catchError((e) { print("Never reached!"); }); |
| 1207 * }, onError: (e) { print("unused error handler"); }); | 1259 * }, onError: (e) { print("unused error handler"); }); |
| 1208 * }, onError: (e) { print("catches error of first error-zone."); }); | 1260 * }, onError: (e) { print("catches error of first error-zone."); }); |
| 1209 * | 1261 * |
| 1210 * Example: | 1262 * Example: |
| 1211 * | 1263 * |
| 1212 * runZoned(() { | 1264 * runZoned(() { |
| 1213 * new Future(() { throw "asynchronous error"; }); | 1265 * new Future(() { throw "asynchronous error"; }); |
| 1214 * }, onError: print); // Will print "asynchronous error". | 1266 * }, onError: print); // Will print "asynchronous error". |
| 1215 */ | 1267 */ |
| 1216 dynamic runZoned(body(), | 1268 /*=R*/ runZoned/*<R>*/(/*=R*/ body(), |
| 1217 { Map zoneValues, | 1269 { Map zoneValues, |
| 1218 ZoneSpecification zoneSpecification, | 1270 ZoneSpecification zoneSpecification, |
| 1219 Function onError }) { | 1271 Function onError }) { |
| 1220 HandleUncaughtErrorHandler errorHandler; | 1272 HandleUncaughtErrorHandler errorHandler; |
| 1221 if (onError != null) { | 1273 if (onError != null) { |
| 1222 errorHandler = (Zone self, ZoneDelegate parent, Zone zone, | 1274 errorHandler = (Zone self, ZoneDelegate parent, Zone zone, |
| 1223 error, StackTrace stackTrace) { | 1275 error, StackTrace stackTrace) { |
| 1224 try { | 1276 try { |
| 1225 if (onError is ZoneBinaryCallback) { | 1277 if (onError is ZoneBinaryCallback<dynamic/*=R*/, dynamic, StackTrace>) { |
| 1226 return self.parent.runBinary(onError, error, stackTrace); | 1278 return self.parent.runBinary(onError, error, stackTrace); |
| 1227 } | 1279 } |
| 1228 return self.parent.runUnary(onError, error); | 1280 return self.parent.runUnary(onError, error); |
| 1229 } catch(e, s) { | 1281 } catch(e, s) { |
| 1230 if (identical(e, error)) { | 1282 if (identical(e, error)) { |
| 1231 return parent.handleUncaughtError(zone, error, stackTrace); | 1283 return parent.handleUncaughtError(zone, error, stackTrace); |
| 1232 } else { | 1284 } else { |
| 1233 return parent.handleUncaughtError(zone, e, s); | 1285 return parent.handleUncaughtError(zone, e, s); |
| 1234 } | 1286 } |
| 1235 } | 1287 } |
| 1236 }; | 1288 }; |
| 1237 } | 1289 } |
| 1238 if (zoneSpecification == null) { | 1290 if (zoneSpecification == null) { |
| 1239 zoneSpecification = | 1291 zoneSpecification = |
| 1240 new ZoneSpecification(handleUncaughtError: errorHandler); | 1292 new ZoneSpecification(handleUncaughtError: errorHandler); |
| 1241 } else if (errorHandler != null) { | 1293 } else if (errorHandler != null) { |
| 1242 zoneSpecification = | 1294 zoneSpecification = |
| 1243 new ZoneSpecification.from(zoneSpecification, | 1295 new ZoneSpecification.from(zoneSpecification, |
| 1244 handleUncaughtError: errorHandler); | 1296 handleUncaughtError: errorHandler); |
| 1245 } | 1297 } |
| 1246 Zone zone = Zone.current.fork(specification: zoneSpecification, | 1298 Zone zone = Zone.current.fork(specification: zoneSpecification, |
| 1247 zoneValues: zoneValues); | 1299 zoneValues: zoneValues); |
| 1248 if (onError != null) { | 1300 if (onError != null) { |
| 1249 return zone.runGuarded(body); | 1301 return zone.runGuarded(body); |
| 1250 } else { | 1302 } else { |
| 1251 return zone.run(body); | 1303 return zone.run(body); |
| 1252 } | 1304 } |
| 1253 } | 1305 } |
| OLD | NEW |