Index: tool/input_sdk/lib/async/zone.dart |
diff --git a/tool/input_sdk/lib/async/zone.dart b/tool/input_sdk/lib/async/zone.dart |
index 43132d5d36c61428a63b69db04026371ff53d8f3..24f83f8bd8ba69a5ce7468aa031005d93a9d2266 100644 |
--- a/tool/input_sdk/lib/async/zone.dart |
+++ b/tool/input_sdk/lib/async/zone.dart |
@@ -4,27 +4,37 @@ |
part of dart.async; |
-typedef dynamic ZoneCallback(); |
-typedef dynamic ZoneUnaryCallback(arg); |
-typedef dynamic ZoneBinaryCallback(arg1, arg2); |
- |
-typedef dynamic HandleUncaughtErrorHandler( |
+typedef R ZoneCallback<R>(); |
+typedef R ZoneUnaryCallback<R, T>(T arg); |
+typedef R ZoneBinaryCallback<R, T1, T2>(T1 arg1, T2 arg2); |
+ |
+// TODO(floitsch): we are abusing generic typedefs as typedefs for generic |
+// functions. |
+/*ABUSE*/ |
+typedef R HandleUncaughtErrorHandler<R>( |
Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); |
-typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); |
-typedef dynamic RunUnaryHandler( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); |
-typedef dynamic RunBinaryHandler( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); |
-typedef ZoneCallback RegisterCallbackHandler( |
- Zone self, ZoneDelegate parent, Zone zone, f()); |
-typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg)); |
-typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); |
+/*ABUSE*/ |
+typedef R RunHandler<R>(Zone self, ZoneDelegate parent, Zone zone, R f()); |
+/*ABUSE*/ |
+typedef R RunUnaryHandler<R, T>( |
+ Zone self, ZoneDelegate parent, Zone zone, R f(T arg), T arg); |
+/*ABUSE*/ |
+typedef R RunBinaryHandler<R, T1, T2>( |
+ Zone self, ZoneDelegate parent, Zone zone, |
+ R f(T1 arg1, T2 arg2), T1 arg1, T2 arg2); |
+/*ABUSE*/ |
+typedef ZoneCallback<R> RegisterCallbackHandler<R>( |
+ Zone self, ZoneDelegate parent, Zone zone, R f()); |
+/*ABUSE*/ |
+typedef ZoneUnaryCallback<R, T> RegisterUnaryCallbackHandler<R, T>( |
+ Zone self, ZoneDelegate parent, Zone zone, R f(T arg)); |
+/*ABUSE*/ |
+typedef ZoneBinaryCallback<R, T1, T2> RegisterBinaryCallbackHandler<R, T1, T2>( |
+ Zone self, ZoneDelegate parent, Zone zone, R f(T1 arg1, T2 arg2)); |
typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, |
Zone zone, Object error, StackTrace stackTrace); |
typedef void ScheduleMicrotaskHandler( |
- Zone self, ZoneDelegate parent, Zone zone, f()); |
+ Zone self, ZoneDelegate parent, Zone zone, void f()); |
typedef Timer CreateTimerHandler( |
Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); |
typedef Timer CreatePeriodicTimerHandler( |
@@ -38,18 +48,18 @@ typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, |
/** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ |
class AsyncError implements Error { |
- final error; |
+ final Object error; |
final StackTrace stackTrace; |
AsyncError(this.error, this.stackTrace); |
- String toString() => error.toString(); |
+ String toString() => '$error'; |
} |
-class _ZoneFunction { |
+class _ZoneFunction<T extends Function> { |
final _Zone zone; |
- final Function function; |
+ final T function; |
const _ZoneFunction(this.zone, this.function); |
} |
@@ -77,30 +87,19 @@ abstract class ZoneSpecification { |
* Creates a specification with the provided handlers. |
*/ |
const factory ZoneSpecification({ |
- dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, |
- error, StackTrace stackTrace), |
- dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()), |
- dynamic runUnary( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg), arg), |
- dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, |
- f(arg1, arg2), arg1, arg2), |
- ZoneCallback registerCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f()), |
- ZoneUnaryCallback registerUnaryCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg)), |
- ZoneBinaryCallback registerBinaryCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), |
- AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, |
- Object error, StackTrace stackTrace), |
- void scheduleMicrotask( |
- Zone self, ZoneDelegate parent, Zone zone, f()), |
- Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
- Duration duration, void f()), |
- Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
- Duration period, void f(Timer timer)), |
- void print(Zone self, ZoneDelegate parent, Zone zone, String line), |
- Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
- ZoneSpecification specification, Map zoneValues) |
+ HandleUncaughtErrorHandler handleUncaughtError, |
+ RunHandler run, |
+ RunUnaryHandler runUnary, |
+ RunBinaryHandler runBinary, |
+ RegisterCallbackHandler registerCallback, |
+ RegisterUnaryCallbackHandler registerUnaryCallback, |
+ RegisterBinaryCallbackHandler registerBinaryCallback, |
+ ErrorCallbackHandler errorCallback, |
+ ScheduleMicrotaskHandler scheduleMicrotask, |
+ CreateTimerHandler createTimer, |
+ CreatePeriodicTimerHandler createPeriodicTimer, |
+ PrintHandler print, |
+ ForkHandler fork |
}) = _ZoneSpecification; |
/** |
@@ -108,60 +107,36 @@ abstract class ZoneSpecification { |
* the ones in [other]. |
*/ |
factory ZoneSpecification.from(ZoneSpecification other, { |
- dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, |
- error, StackTrace stackTrace): null, |
- dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, |
- dynamic runUnary( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, |
- dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, |
- f(arg1, arg2), arg1, arg2): null, |
- ZoneCallback registerCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f()): null, |
- ZoneUnaryCallback registerUnaryCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, |
- ZoneBinaryCallback registerBinaryCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, |
- AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, |
- Object error, StackTrace stackTrace), |
- void scheduleMicrotask( |
- Zone self, ZoneDelegate parent, Zone zone, f()): null, |
- Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
- Duration duration, void f()): null, |
- Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
- Duration period, void f(Timer timer)): null, |
- void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, |
- Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
- ZoneSpecification specification, |
- Map zoneValues): null |
+ HandleUncaughtErrorHandler handleUncaughtError: null, |
+ RunHandler run: null, |
+ RunUnaryHandler runUnary: null, |
+ RunBinaryHandler runBinary: null, |
+ RegisterCallbackHandler registerCallback: null, |
+ RegisterUnaryCallbackHandler registerUnaryCallback: null, |
+ RegisterBinaryCallbackHandler registerBinaryCallback: null, |
+ ErrorCallbackHandler errorCallback: null, |
+ ScheduleMicrotaskHandler scheduleMicrotask: null, |
+ CreateTimerHandler createTimer: null, |
+ CreatePeriodicTimerHandler createPeriodicTimer: null, |
+ PrintHandler print: null, |
+ ForkHandler fork: null |
}) { |
return new ZoneSpecification( |
- handleUncaughtError: handleUncaughtError != null |
- ? handleUncaughtError |
- : other.handleUncaughtError, |
- run: run != null ? run : other.run, |
- runUnary: runUnary != null ? runUnary : other.runUnary, |
- runBinary: runBinary != null ? runBinary : other.runBinary, |
- registerCallback: registerCallback != null |
- ? registerCallback |
- : other.registerCallback, |
- registerUnaryCallback: registerUnaryCallback != null |
- ? registerUnaryCallback |
- : other.registerUnaryCallback, |
- registerBinaryCallback: registerBinaryCallback != null |
- ? registerBinaryCallback |
- : other.registerBinaryCallback, |
- errorCallback: errorCallback != null |
- ? errorCallback |
- : other.errorCallback, |
- scheduleMicrotask: scheduleMicrotask != null |
- ? scheduleMicrotask |
- : other.scheduleMicrotask, |
- createTimer : createTimer != null ? createTimer : other.createTimer, |
- createPeriodicTimer: createPeriodicTimer != null |
- ? createPeriodicTimer |
- : other.createPeriodicTimer, |
- print : print != null ? print : other.print, |
- fork: fork != null ? fork : other.fork); |
+ handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError, |
+ run: run ?? other.run, |
+ runUnary: runUnary ?? other.runUnary, |
+ runBinary: runBinary ?? other.runBinary, |
+ registerCallback: registerCallback ?? other.registerCallback, |
+ registerUnaryCallback: registerUnaryCallback ?? |
+ other.registerUnaryCallback, |
+ registerBinaryCallback: registerBinaryCallback ?? |
+ other.registerBinaryCallback, |
+ errorCallback: errorCallback ?? other.errorCallback, |
+ scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask, |
+ createTimer : createTimer ?? other.createTimer, |
+ createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer, |
+ print : print ?? other.print, |
+ fork: fork ?? other.fork); |
} |
HandleUncaughtErrorHandler get handleUncaughtError; |
@@ -203,20 +178,19 @@ class _ZoneSpecification implements ZoneSpecification { |
this.fork: null |
}); |
- // TODO(13406): Enable types when dart2js supports it. |
- final /*HandleUncaughtErrorHandler*/ handleUncaughtError; |
- final /*RunHandler*/ run; |
- final /*RunUnaryHandler*/ runUnary; |
- final /*RunBinaryHandler*/ runBinary; |
- final /*RegisterCallbackHandler*/ registerCallback; |
- final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback; |
- final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback; |
- final /*ErrorCallbackHandler*/ errorCallback; |
- final /*ScheduleMicrotaskHandler*/ scheduleMicrotask; |
- final /*CreateTimerHandler*/ createTimer; |
- final /*CreatePeriodicTimerHandler*/ createPeriodicTimer; |
- final /*PrintHandler*/ print; |
- final /*ForkHandler*/ fork; |
+ final HandleUncaughtErrorHandler handleUncaughtError; |
+ final RunHandler run; |
+ final RunUnaryHandler runUnary; |
+ final RunBinaryHandler runBinary; |
+ final RegisterCallbackHandler registerCallback; |
+ final RegisterUnaryCallbackHandler registerUnaryCallback; |
+ final RegisterBinaryCallbackHandler registerBinaryCallback; |
+ final ErrorCallbackHandler errorCallback; |
+ final ScheduleMicrotaskHandler scheduleMicrotask; |
+ final CreateTimerHandler createTimer; |
+ final CreatePeriodicTimerHandler createPeriodicTimer; |
+ final PrintHandler print; |
+ final ForkHandler fork; |
} |
/** |
@@ -230,15 +204,19 @@ class _ZoneSpecification implements ZoneSpecification { |
* directly invoking the parent zone. |
*/ |
abstract class ZoneDelegate { |
- dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); |
- dynamic run(Zone zone, f()); |
- dynamic runUnary(Zone zone, f(arg), arg); |
- dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); |
- ZoneCallback registerCallback(Zone zone, f()); |
- ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); |
- ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); |
+ /*=R*/ handleUncaughtError/*<R>*/( |
+ Zone zone, error, StackTrace stackTrace); |
+ /*=R*/ run/*<R>*/(Zone zone, /*=R*/ f()); |
+ /*=R*/ runUnary/*<R, T>*/(Zone zone, /*=R*/ f(/*=T*/ arg), /*=T*/ arg); |
+ /*=R*/ runBinary/*<R, T1, T2>*/(Zone zone, |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2); |
+ ZoneCallback/*<R>*/ registerCallback/*<R>*/(Zone zone, /*=R*/ f()); |
+ ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
+ Zone zone, /*=R*/ f(/*=T*/ arg)); |
+ ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
+ Zone zone, /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)); |
AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); |
- void scheduleMicrotask(Zone zone, f()); |
+ void scheduleMicrotask(Zone zone, void f()); |
Timer createTimer(Zone zone, Duration duration, void f()); |
Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); |
void print(Zone zone, String line); |
@@ -263,7 +241,7 @@ abstract class Zone { |
static Zone get current => _current; |
- dynamic handleUncaughtError(error, StackTrace stackTrace); |
+ /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace); |
/** |
* Returns the parent zone. |
@@ -307,18 +285,19 @@ abstract class Zone { |
/** |
* Executes the given function [f] in this zone. |
*/ |
- dynamic run(f()); |
+ /*=R*/ run/*<R>*/(/*=R*/ f()); |
/** |
* Executes the given callback [f] with argument [arg] in this zone. |
*/ |
- dynamic runUnary(f(arg), var arg); |
+ /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg); |
/** |
* Executes the given callback [f] with argument [arg1] and [arg2] in this |
* zone. |
*/ |
- dynamic runBinary(f(arg1, arg2), var arg1, var arg2); |
+ /*=R*/ runBinary/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2); |
/** |
* Executes the given function [f] in this zone. |
@@ -326,7 +305,7 @@ abstract class Zone { |
* Same as [run] but catches uncaught errors and gives them to |
* [handleUncaughtError]. |
*/ |
- dynamic runGuarded(f()); |
+ /*=R*/ runGuarded/*<R>*/(/*=R*/ f()); |
/** |
* Executes the given callback [f] in this zone. |
@@ -334,7 +313,7 @@ abstract class Zone { |
* Same as [runUnary] but catches uncaught errors and gives them to |
* [handleUncaughtError]. |
*/ |
- dynamic runUnaryGuarded(f(arg), var arg); |
+ /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg); |
/** |
* Executes the given callback [f] in this zone. |
@@ -342,7 +321,8 @@ abstract class Zone { |
* Same as [runBinary] but catches uncaught errors and gives them to |
* [handleUncaughtError]. |
*/ |
- dynamic runBinaryGuarded(f(arg1, arg2), var arg1, var arg2); |
+ /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2); |
/** |
* Registers the given callback in this zone. |
@@ -356,21 +336,23 @@ abstract class Zone { |
* Returns a potentially new callback that should be used in place of the |
* given [callback]. |
*/ |
- ZoneCallback registerCallback(callback()); |
+ ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ callback()); |
/** |
* Registers the given callback in this zone. |
* |
* Similar to [registerCallback] but with a unary callback. |
*/ |
- ZoneUnaryCallback registerUnaryCallback(callback(arg)); |
+ ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
+ /*=R*/ callback(/*=T*/ arg)); |
/** |
* Registers the given callback in this zone. |
* |
* Similar to [registerCallback] but with a unary callback. |
*/ |
- ZoneBinaryCallback registerBinaryCallback(callback(arg1, arg2)); |
+ ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
+ /*=R*/ callback(/*=T1*/ arg1, /*=T2*/ arg2)); |
/** |
* Equivalent to: |
@@ -380,7 +362,8 @@ abstract class Zone { |
* return () => this.run(registered); |
* |
*/ |
- ZoneCallback bindCallback(f(), { bool runGuarded: true }); |
+ ZoneCallback/*<R>*/ bindCallback/*<R>*/( |
+ /*=R*/ f(), { bool runGuarded: true }); |
/** |
* Equivalent to: |
@@ -389,7 +372,8 @@ abstract class Zone { |
* if (runGuarded) return (arg) => this.runUnaryGuarded(registered, arg); |
* return (arg) => thin.runUnary(registered, arg); |
*/ |
- ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }); |
+ ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( |
+ /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }); |
/** |
* Equivalent to: |
@@ -400,11 +384,11 @@ abstract class Zone { |
* } |
* return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); |
*/ |
- ZoneBinaryCallback bindBinaryCallback( |
- f(arg1, arg2), { bool runGuarded: true }); |
+ ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }); |
/** |
- * Intercepts errors when added programmtically to a `Future` or `Stream`. |
+ * Intercepts errors when added programmatically to a `Future` or `Stream`. |
* |
* When caling [Completer.completeError], [Stream.addError], |
* or [Future] constructors that take an error or a callback that may throw, |
@@ -488,96 +472,125 @@ class _ZoneDelegate implements ZoneDelegate { |
_ZoneDelegate(this._delegationTarget); |
- dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace) { |
- _ZoneFunction implementation = _delegationTarget._handleUncaughtError; |
+ /*=R*/ handleUncaughtError/*<R>*/( |
+ Zone zone, error, StackTrace stackTrace) { |
+ var implementation = _delegationTarget._handleUncaughtError; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, error, stackTrace); |
+ HandleUncaughtErrorHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler( |
+ implZone, _parentDelegate(implZone), zone, error, stackTrace) |
+ as Object/*=R*/; |
} |
- dynamic run(Zone zone, f()) { |
- _ZoneFunction implementation = _delegationTarget._run; |
+ /*=R*/ run/*<R>*/(Zone zone, /*=R*/ f()) { |
+ var implementation = _delegationTarget._run; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, f); |
+ RunHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler(implZone, _parentDelegate(implZone), zone, f) |
+ as Object/*=R*/; |
} |
- dynamic runUnary(Zone zone, f(arg), arg) { |
- _ZoneFunction implementation = _delegationTarget._runUnary; |
+ /*=R*/ runUnary/*<R, T>*/(Zone zone, /*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
+ var implementation = _delegationTarget._runUnary; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, f, arg); |
+ RunUnaryHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler( |
+ implZone, _parentDelegate(implZone), zone, f, arg) as Object/*=R*/; |
} |
- dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2) { |
- _ZoneFunction implementation = _delegationTarget._runBinary; |
+ /*=R*/ runBinary/*<R, T1, T2>*/(Zone zone, |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
+ var implementation = _delegationTarget._runBinary; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, f, arg1, arg2); |
+ RunBinaryHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
+ // it's supported. Remove the unnecessary cast. |
+ return handler( |
+ implZone, _parentDelegate(implZone), zone, f, arg1, arg2) |
+ as Object/*=R*/; |
} |
- ZoneCallback registerCallback(Zone zone, f()) { |
- _ZoneFunction implementation = _delegationTarget._registerCallback; |
+ ZoneCallback/*<R>*/ registerCallback/*<R>*/(Zone zone, /*=R*/ f()) { |
+ var implementation = _delegationTarget._registerCallback; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, f); |
+ RegisterCallbackHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler(implZone, _parentDelegate(implZone), zone, f) |
+ as Object/*=ZoneCallback<R>*/; |
} |
- ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)) { |
- _ZoneFunction implementation = _delegationTarget._registerUnaryCallback; |
+ ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
+ Zone zone, /*=R*/ f(/*=T*/ arg)) { |
+ var implementation = _delegationTarget._registerUnaryCallback; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, f); |
+ RegisterUnaryCallbackHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler(implZone, _parentDelegate(implZone), zone, f) |
+ as Object/*=ZoneUnaryCallback<R, T>*/; |
} |
- ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)) { |
- _ZoneFunction implementation = _delegationTarget._registerBinaryCallback; |
+ ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
+ Zone zone, /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) { |
+ var implementation = _delegationTarget._registerBinaryCallback; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, f); |
+ RegisterBinaryCallbackHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
+ // it's supported. Remove the unnecessary cast. |
+ return handler(implZone, _parentDelegate(implZone), zone, f) |
+ as Object/*=ZoneBinaryCallback<R, T1, T2>*/; |
} |
AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) { |
- _ZoneFunction implementation = _delegationTarget._errorCallback; |
+ var implementation = _delegationTarget._errorCallback; |
_Zone implZone = implementation.zone; |
if (identical(implZone, _ROOT_ZONE)) return null; |
- return (implementation.function)(implZone, _parentDelegate(implZone), zone, |
- error, stackTrace); |
+ ErrorCallbackHandler handler = implementation.function; |
+ return handler(implZone, _parentDelegate(implZone), zone, |
+ error, stackTrace); |
} |
void scheduleMicrotask(Zone zone, f()) { |
- _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; |
+ var implementation = _delegationTarget._scheduleMicrotask; |
_Zone implZone = implementation.zone; |
- (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, f); |
+ ScheduleMicrotaskHandler handler = implementation.function; |
+ handler(implZone, _parentDelegate(implZone), zone, f); |
} |
Timer createTimer(Zone zone, Duration duration, void f()) { |
- _ZoneFunction implementation = _delegationTarget._createTimer; |
+ var implementation = _delegationTarget._createTimer; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, duration, f); |
+ CreateTimerHandler handler = implementation.function; |
+ return handler(implZone, _parentDelegate(implZone), zone, duration, f); |
} |
Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { |
- _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; |
+ var implementation = _delegationTarget._createPeriodicTimer; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, period, f); |
+ CreatePeriodicTimerHandler handler = implementation.function; |
+ return handler(implZone, _parentDelegate(implZone), zone, period, f); |
} |
void print(Zone zone, String line) { |
- _ZoneFunction implementation = _delegationTarget._print; |
+ var implementation = _delegationTarget._print; |
_Zone implZone = implementation.zone; |
- (implementation.function)( |
- implZone, _parentDelegate(implZone), zone, line); |
+ PrintHandler handler = implementation.function; |
+ handler(implZone, _parentDelegate(implZone), zone, line); |
} |
Zone fork(Zone zone, ZoneSpecification specification, |
Map zoneValues) { |
- _ZoneFunction implementation = _delegationTarget._fork; |
+ var implementation = _delegationTarget._fork; |
_Zone implZone = implementation.zone; |
- return (implementation.function)( |
+ ForkHandler handler = implementation.function; |
+ return handler( |
implZone, _parentDelegate(implZone), zone, specification, zoneValues); |
} |
} |
@@ -589,19 +602,19 @@ class _ZoneDelegate implements ZoneDelegate { |
abstract class _Zone implements Zone { |
const _Zone(); |
- _ZoneFunction get _runUnary; |
- _ZoneFunction get _run; |
- _ZoneFunction get _runBinary; |
- _ZoneFunction get _registerCallback; |
- _ZoneFunction get _registerUnaryCallback; |
- _ZoneFunction get _registerBinaryCallback; |
- _ZoneFunction get _errorCallback; |
- _ZoneFunction get _scheduleMicrotask; |
- _ZoneFunction get _createTimer; |
- _ZoneFunction get _createPeriodicTimer; |
- _ZoneFunction get _print; |
- _ZoneFunction get _fork; |
- _ZoneFunction get _handleUncaughtError; |
+ _ZoneFunction<RunHandler> get _run; |
+ _ZoneFunction<RunUnaryHandler> get _runUnary; |
+ _ZoneFunction<RunBinaryHandler> get _runBinary; |
+ _ZoneFunction<RegisterCallbackHandler> get _registerCallback; |
+ _ZoneFunction<RegisterUnaryCallbackHandler> get _registerUnaryCallback; |
+ _ZoneFunction<RegisterBinaryCallbackHandler> get _registerBinaryCallback; |
+ _ZoneFunction<ErrorCallbackHandler> get _errorCallback; |
+ _ZoneFunction<ScheduleMicrotaskHandler> get _scheduleMicrotask; |
+ _ZoneFunction<CreateTimerHandler> get _createTimer; |
+ _ZoneFunction<CreatePeriodicTimerHandler> get _createPeriodicTimer; |
+ _ZoneFunction<PrintHandler> get _print; |
+ _ZoneFunction<ForkHandler> get _fork; |
+ _ZoneFunction<HandleUncaughtErrorHandler> get _handleUncaughtError; |
_Zone get parent; |
ZoneDelegate get _delegate; |
Map get _map; |
@@ -615,19 +628,19 @@ abstract class _Zone implements Zone { |
class _CustomZone extends _Zone { |
// The actual zone and implementation of each of these |
// inheritable zone functions. |
- _ZoneFunction _runUnary; |
- _ZoneFunction _run; |
- _ZoneFunction _runBinary; |
- _ZoneFunction _registerCallback; |
- _ZoneFunction _registerUnaryCallback; |
- _ZoneFunction _registerBinaryCallback; |
- _ZoneFunction _errorCallback; |
- _ZoneFunction _scheduleMicrotask; |
- _ZoneFunction _createTimer; |
- _ZoneFunction _createPeriodicTimer; |
- _ZoneFunction _print; |
- _ZoneFunction _fork; |
- _ZoneFunction _handleUncaughtError; |
+ _ZoneFunction<RunHandler> _run; |
+ _ZoneFunction<RunUnaryHandler> _runUnary; |
+ _ZoneFunction<RunBinaryHandler> _runBinary; |
+ _ZoneFunction<RegisterCallbackHandler> _registerCallback; |
+ _ZoneFunction<RegisterUnaryCallbackHandler> _registerUnaryCallback; |
+ _ZoneFunction<RegisterBinaryCallbackHandler> _registerBinaryCallback; |
+ _ZoneFunction<ErrorCallbackHandler> _errorCallback; |
+ _ZoneFunction<ScheduleMicrotaskHandler> _scheduleMicrotask; |
+ _ZoneFunction<CreateTimerHandler> _createTimer; |
+ _ZoneFunction<CreatePeriodicTimerHandler> _createPeriodicTimer; |
+ _ZoneFunction<PrintHandler> _print; |
+ _ZoneFunction<ForkHandler> _fork; |
+ _ZoneFunction<HandleUncaughtErrorHandler> _handleUncaughtError; |
// A cached delegate to this zone. |
ZoneDelegate _delegateCache; |
@@ -651,43 +664,50 @@ class _CustomZone extends _Zone { |
// specification, so it will never try to access the (null) parent. |
// All other zones have a non-null parent. |
_run = (specification.run != null) |
- ? new _ZoneFunction(this, specification.run) |
+ ? new _ZoneFunction<RunHandler>(this, specification.run) |
: parent._run; |
_runUnary = (specification.runUnary != null) |
- ? new _ZoneFunction(this, specification.runUnary) |
+ ? new _ZoneFunction<RunUnaryHandler>(this, specification.runUnary) |
: parent._runUnary; |
_runBinary = (specification.runBinary != null) |
- ? new _ZoneFunction(this, specification.runBinary) |
+ ? new _ZoneFunction<RunBinaryHandler>(this, specification.runBinary) |
: parent._runBinary; |
_registerCallback = (specification.registerCallback != null) |
- ? new _ZoneFunction(this, specification.registerCallback) |
+ ? new _ZoneFunction<RegisterCallbackHandler>( |
+ this, specification.registerCallback) |
: parent._registerCallback; |
_registerUnaryCallback = (specification.registerUnaryCallback != null) |
- ? new _ZoneFunction(this, specification.registerUnaryCallback) |
+ ? new _ZoneFunction<RegisterUnaryCallbackHandler>( |
+ this, specification.registerUnaryCallback) |
: parent._registerUnaryCallback; |
_registerBinaryCallback = (specification.registerBinaryCallback != null) |
- ? new _ZoneFunction(this, specification.registerBinaryCallback) |
+ ? new _ZoneFunction<RegisterBinaryCallbackHandler>( |
+ this, specification.registerBinaryCallback) |
: parent._registerBinaryCallback; |
_errorCallback = (specification.errorCallback != null) |
- ? new _ZoneFunction(this, specification.errorCallback) |
+ ? new _ZoneFunction<ErrorCallbackHandler>( |
+ this, specification.errorCallback) |
: parent._errorCallback; |
_scheduleMicrotask = (specification.scheduleMicrotask != null) |
- ? new _ZoneFunction(this, specification.scheduleMicrotask) |
+ ? new _ZoneFunction<ScheduleMicrotaskHandler>( |
+ this, specification.scheduleMicrotask) |
: parent._scheduleMicrotask; |
_createTimer = (specification.createTimer != null) |
- ? new _ZoneFunction(this, specification.createTimer) |
+ ? new _ZoneFunction<CreateTimerHandler>(this, specification.createTimer) |
: parent._createTimer; |
_createPeriodicTimer = (specification.createPeriodicTimer != null) |
- ? new _ZoneFunction(this, specification.createPeriodicTimer) |
+ ? new _ZoneFunction<CreatePeriodicTimerHandler>( |
+ this, specification.createPeriodicTimer) |
: parent._createPeriodicTimer; |
_print = (specification.print != null) |
- ? new _ZoneFunction(this, specification.print) |
+ ? new _ZoneFunction<PrintHandler>(this, specification.print) |
: parent._print; |
_fork = (specification.fork != null) |
- ? new _ZoneFunction(this, specification.fork) |
+ ? new _ZoneFunction<ForkHandler>(this, specification.fork) |
: parent._fork; |
_handleUncaughtError = (specification.handleUncaughtError != null) |
- ? new _ZoneFunction(this, specification.handleUncaughtError) |
+ ? new _ZoneFunction<HandleUncaughtErrorHandler>( |
+ this, specification.handleUncaughtError) |
: parent._handleUncaughtError; |
} |
@@ -699,7 +719,7 @@ class _CustomZone extends _Zone { |
*/ |
Zone get errorZone => _handleUncaughtError.zone; |
- dynamic runGuarded(f()) { |
+ /*=R*/ runGuarded/*<R>*/(/*=R*/ f()) { |
try { |
return run(f); |
} catch (e, s) { |
@@ -707,7 +727,7 @@ class _CustomZone extends _Zone { |
} |
} |
- dynamic runUnaryGuarded(f(arg), arg) { |
+ /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
try { |
return runUnary(f, arg); |
} catch (e, s) { |
@@ -715,7 +735,8 @@ class _CustomZone extends _Zone { |
} |
} |
- dynamic runBinaryGuarded(f(arg1, arg2), arg1, arg2) { |
+ /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
try { |
return runBinary(f, arg1, arg2); |
} catch (e, s) { |
@@ -723,8 +744,9 @@ class _CustomZone extends _Zone { |
} |
} |
- ZoneCallback bindCallback(f(), { bool runGuarded: true }) { |
- ZoneCallback registered = registerCallback(f); |
+ ZoneCallback/*<R>*/ bindCallback/*<R>*/( |
+ /*=R*/ f(), { bool runGuarded: true }) { |
+ var registered = registerCallback(f); |
if (runGuarded) { |
return () => this.runGuarded(registered); |
} else { |
@@ -732,8 +754,9 @@ class _CustomZone extends _Zone { |
} |
} |
- ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }) { |
- ZoneUnaryCallback registered = registerUnaryCallback(f); |
+ ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( |
+ /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }) { |
+ var registered = registerUnaryCallback(f); |
if (runGuarded) { |
return (arg) => this.runUnaryGuarded(registered, arg); |
} else { |
@@ -741,9 +764,9 @@ class _CustomZone extends _Zone { |
} |
} |
- ZoneBinaryCallback bindBinaryCallback( |
- f(arg1, arg2), { bool runGuarded: true }) { |
- ZoneBinaryCallback registered = registerBinaryCallback(f); |
+ ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }) { |
+ var registered = registerBinaryCallback(f); |
if (runGuarded) { |
return (arg1, arg2) => this.runBinaryGuarded(registered, arg1, arg2); |
} else { |
@@ -772,122 +795,154 @@ class _CustomZone extends _Zone { |
// Methods that can be customized by the zone specification. |
- dynamic handleUncaughtError(error, StackTrace stackTrace) { |
- _ZoneFunction implementation = this._handleUncaughtError; |
+ /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace) { |
+ var implementation = this._handleUncaughtError; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, error, stackTrace); |
+ HandleUncaughtErrorHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler( |
+ implementation.zone, parentDelegate, this, error, stackTrace) |
+ as Object/*=R*/; |
} |
Zone fork({ZoneSpecification specification, Map zoneValues}) { |
- _ZoneFunction implementation = this._fork; |
+ var implementation = this._fork; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, |
- specification, zoneValues); |
+ ForkHandler handler = implementation.function; |
+ return handler(implementation.zone, parentDelegate, this, |
+ specification, zoneValues); |
} |
- dynamic run(f()) { |
- _ZoneFunction implementation = this._run; |
+ /*=R*/ run/*<R>*/(/*=R*/ f()) { |
+ var implementation = this._run; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, f); |
+ RunHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler(implementation.zone, parentDelegate, this, f) |
+ as Object/*=R*/; |
} |
- dynamic runUnary(f(arg), arg) { |
- _ZoneFunction implementation = this._runUnary; |
+ /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
+ var implementation = this._runUnary; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, f, arg); |
+ RunUnaryHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler(implementation.zone, parentDelegate, this, f, arg) |
+ as Object/*=R*/; |
} |
- dynamic runBinary(f(arg1, arg2), arg1, arg2) { |
- _ZoneFunction implementation = this._runBinary; |
+ /*=R*/ runBinary/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
+ var implementation = this._runBinary; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, f, arg1, arg2); |
+ RunBinaryHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
+ // it's supported. Remove the unnecessary cast. |
+ return handler( |
+ implementation.zone, parentDelegate, this, f, arg1, arg2) |
+ as Object/*=R*/; |
} |
- ZoneCallback registerCallback(f()) { |
- _ZoneFunction implementation = this._registerCallback; |
+ ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ callback()) { |
+ var implementation = this._registerCallback; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, f); |
+ RegisterCallbackHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler(implementation.zone, parentDelegate, this, callback) |
+ as Object/*=ZoneCallback<R>*/; |
} |
- ZoneUnaryCallback registerUnaryCallback(f(arg)) { |
- _ZoneFunction implementation = this._registerUnaryCallback; |
+ ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
+ /*=R*/ callback(/*=T*/ arg)) { |
+ var implementation = this._registerUnaryCallback; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, f); |
+ RegisterUnaryCallbackHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T>' once it's |
+ // supported. Remove the unnecessary cast. |
+ return handler(implementation.zone, parentDelegate, this, callback) |
+ as Object/*=ZoneUnaryCallback<R, T>*/; |
} |
- ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { |
- _ZoneFunction implementation = this._registerBinaryCallback; |
+ ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
+ /*=R*/ callback(/*=T1*/ arg1, /*=T2*/ arg2)) { |
+ var implementation = this._registerBinaryCallback; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, f); |
+ RegisterBinaryCallbackHandler handler = implementation.function; |
+ // TODO(floitsch): make this a generic method call on '<R, T1, T2>' once |
+ // it's supported. Remove the unnecessary cast. |
+ return handler(implementation.zone, parentDelegate, this, callback) |
+ as Object/*=ZoneBinaryCallback<R, T1, T2>*/; |
} |
AsyncError errorCallback(Object error, StackTrace stackTrace) { |
- final _ZoneFunction implementation = this._errorCallback; |
+ var implementation = this._errorCallback; |
assert(implementation != null); |
final Zone implementationZone = implementation.zone; |
if (identical(implementationZone, _ROOT_ZONE)) return null; |
final ZoneDelegate parentDelegate = _parentDelegate(implementationZone); |
- return (implementation.function)( |
+ ErrorCallbackHandler handler = implementation.function; |
+ return handler( |
implementationZone, parentDelegate, this, error, stackTrace); |
} |
void scheduleMicrotask(void f()) { |
- _ZoneFunction implementation = this._scheduleMicrotask; |
+ var implementation = this._scheduleMicrotask; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, f); |
+ ScheduleMicrotaskHandler handler = implementation.function; |
+ return handler(implementation.zone, parentDelegate, this, f); |
} |
Timer createTimer(Duration duration, void f()) { |
- _ZoneFunction implementation = this._createTimer; |
+ var implementation = this._createTimer; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, duration, f); |
+ CreateTimerHandler handler = implementation.function; |
+ return handler(implementation.zone, parentDelegate, this, duration, f); |
} |
Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
- _ZoneFunction implementation = this._createPeriodicTimer; |
+ var implementation = this._createPeriodicTimer; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
+ CreatePeriodicTimerHandler handler = implementation.function; |
+ return handler( |
implementation.zone, parentDelegate, this, duration, f); |
} |
void print(String line) { |
- _ZoneFunction implementation = this._print; |
+ var implementation = this._print; |
assert(implementation != null); |
ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
- return (implementation.function)( |
- implementation.zone, parentDelegate, this, line); |
+ PrintHandler handler = implementation.function; |
+ return handler(implementation.zone, parentDelegate, this, line); |
} |
} |
-void _rootHandleUncaughtError( |
+/*=R*/ _rootHandleUncaughtError/*<R>*/( |
Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { |
_schedulePriorityAsyncCallback(() { |
- throw new _UncaughtAsyncError(error, stackTrace); |
+ if (error == null) error = new NullThrownError(); |
+ if (stackTrace == null) throw error; |
+ _rethrow(error, stackTrace); |
}); |
} |
-dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { |
+external void _rethrow(Object error, StackTrace stackTrace); |
+ |
+/*=R*/ _rootRun/*<R>*/(Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f()) { |
if (Zone._current == zone) return f(); |
Zone old = Zone._enter(zone); |
@@ -898,7 +953,8 @@ dynamic _rootRun(Zone self, ZoneDelegate parent, Zone zone, f()) { |
} |
} |
-dynamic _rootRunUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) { |
+/*=R*/ _rootRunUnary/*<R, T>*/(Zone self, ZoneDelegate parent, Zone zone, |
+ /*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
if (Zone._current == zone) return f(arg); |
Zone old = Zone._enter(zone); |
@@ -909,8 +965,8 @@ dynamic _rootRunUnary(Zone self, ZoneDelegate parent, Zone zone, f(arg), arg) { |
} |
} |
-dynamic _rootRunBinary(Zone self, ZoneDelegate parent, Zone zone, |
- f(arg1, arg2), arg1, arg2) { |
+/*=R*/ _rootRunBinary/*<R, T1, T2>*/(Zone self, ZoneDelegate parent, Zone zone, |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
if (Zone._current == zone) return f(arg1, arg2); |
Zone old = Zone._enter(zone); |
@@ -921,18 +977,19 @@ dynamic _rootRunBinary(Zone self, ZoneDelegate parent, Zone zone, |
} |
} |
-ZoneCallback _rootRegisterCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f()) { |
+ZoneCallback/*<R>*/ _rootRegisterCallback/*<R>*/( |
+ Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f()) { |
return f; |
} |
-ZoneUnaryCallback _rootRegisterUnaryCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg)) { |
+ZoneUnaryCallback/*<R, T>*/ _rootRegisterUnaryCallback/*<R, T>*/( |
+ Zone self, ZoneDelegate parent, Zone zone, /*=R*/ f(/*=T*/ arg)) { |
return f; |
} |
-ZoneBinaryCallback _rootRegisterBinaryCallback( |
- Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)) { |
+ZoneBinaryCallback/*<R, T1, T2>*/ _rootRegisterBinaryCallback/*<R, T1, T2>*/( |
+ Zone self, ZoneDelegate parent, Zone zone, |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) { |
return f; |
} |
@@ -943,6 +1000,8 @@ void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { |
if (!identical(_ROOT_ZONE, zone)) { |
bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); |
f = zone.bindCallback(f, runGuarded: hasErrorHandler); |
+ // Use root zone as event zone if the function is already bound. |
+ zone = _ROOT_ZONE; |
} |
_scheduleAsyncCallback(f); |
} |
@@ -959,7 +1018,8 @@ Timer _rootCreatePeriodicTimer( |
Zone self, ZoneDelegate parent, Zone zone, |
Duration duration, void callback(Timer timer)) { |
if (!identical(_ROOT_ZONE, zone)) { |
- callback = zone.bindUnaryCallback(callback); |
+ // TODO(floitsch): the return type should be 'void'. |
+ callback = zone.bindUnaryCallback/*<dynamic, Timer>*/(callback); |
} |
return Timer._createPeriodicTimer(duration, callback); |
} |
@@ -999,55 +1059,40 @@ Zone _rootFork(Zone self, ZoneDelegate parent, Zone zone, |
return new _CustomZone(zone, specification, valueMap); |
} |
-class _RootZoneSpecification implements ZoneSpecification { |
- HandleUncaughtErrorHandler get handleUncaughtError => |
- _rootHandleUncaughtError; |
- RunHandler get run => _rootRun; |
- RunUnaryHandler get runUnary => _rootRunUnary; |
- RunBinaryHandler get runBinary => _rootRunBinary; |
- RegisterCallbackHandler get registerCallback => _rootRegisterCallback; |
- RegisterUnaryCallbackHandler get registerUnaryCallback => |
- _rootRegisterUnaryCallback; |
- RegisterBinaryCallbackHandler get registerBinaryCallback => |
- _rootRegisterBinaryCallback; |
- ErrorCallbackHandler get errorCallback => _rootErrorCallback; |
- ScheduleMicrotaskHandler get scheduleMicrotask => _rootScheduleMicrotask; |
- CreateTimerHandler get createTimer => _rootCreateTimer; |
- CreatePeriodicTimerHandler get createPeriodicTimer => |
- _rootCreatePeriodicTimer; |
- PrintHandler get print => _rootPrint; |
- ForkHandler get fork => _rootFork; |
-} |
- |
class _RootZone extends _Zone { |
const _RootZone(); |
- _ZoneFunction get _run => |
- const _ZoneFunction(_ROOT_ZONE, _rootRun); |
- _ZoneFunction get _runUnary => |
- const _ZoneFunction(_ROOT_ZONE, _rootRunUnary); |
- _ZoneFunction get _runBinary => |
- const _ZoneFunction(_ROOT_ZONE, _rootRunBinary); |
- _ZoneFunction get _registerCallback => |
- const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback); |
- _ZoneFunction get _registerUnaryCallback => |
- const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback); |
- _ZoneFunction get _registerBinaryCallback => |
- const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback); |
- _ZoneFunction get _errorCallback => |
- const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback); |
- _ZoneFunction get _scheduleMicrotask => |
- const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); |
- _ZoneFunction get _createTimer => |
- const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); |
- _ZoneFunction get _createPeriodicTimer => |
- const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); |
- _ZoneFunction get _print => |
- const _ZoneFunction(_ROOT_ZONE, _rootPrint); |
- _ZoneFunction get _fork => |
- const _ZoneFunction(_ROOT_ZONE, _rootFork); |
- _ZoneFunction get _handleUncaughtError => |
- const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError); |
+ _ZoneFunction<RunHandler> get _run => |
+ const _ZoneFunction<RunHandler>(_ROOT_ZONE, _rootRun); |
+ _ZoneFunction<RunUnaryHandler> get _runUnary => |
+ const _ZoneFunction<RunUnaryHandler>(_ROOT_ZONE, _rootRunUnary); |
+ _ZoneFunction<RunBinaryHandler> get _runBinary => |
+ const _ZoneFunction<RunBinaryHandler>(_ROOT_ZONE, _rootRunBinary); |
+ _ZoneFunction<RegisterCallbackHandler> get _registerCallback => |
+ const _ZoneFunction<RegisterCallbackHandler>( |
+ _ROOT_ZONE, _rootRegisterCallback); |
+ _ZoneFunction<RegisterUnaryCallbackHandler> get _registerUnaryCallback => |
+ const _ZoneFunction<RegisterUnaryCallbackHandler>( |
+ _ROOT_ZONE, _rootRegisterUnaryCallback); |
+ _ZoneFunction<RegisterBinaryCallbackHandler> get _registerBinaryCallback => |
+ const _ZoneFunction<RegisterBinaryCallbackHandler>( |
+ _ROOT_ZONE, _rootRegisterBinaryCallback); |
+ _ZoneFunction<ErrorCallbackHandler> get _errorCallback => |
+ const _ZoneFunction<ErrorCallbackHandler>(_ROOT_ZONE, _rootErrorCallback); |
+ _ZoneFunction<ScheduleMicrotaskHandler> get _scheduleMicrotask => |
+ const _ZoneFunction<ScheduleMicrotaskHandler>( |
+ _ROOT_ZONE, _rootScheduleMicrotask); |
+ _ZoneFunction<CreateTimerHandler> get _createTimer => |
+ const _ZoneFunction<CreateTimerHandler>(_ROOT_ZONE, _rootCreateTimer); |
+ _ZoneFunction<CreatePeriodicTimerHandler> get _createPeriodicTimer => |
+ const _ZoneFunction<CreatePeriodicTimerHandler>(_ROOT_ZONE, _rootCreatePeriodicTimer); |
+ _ZoneFunction<PrintHandler> get _print => |
+ const _ZoneFunction<PrintHandler>(_ROOT_ZONE, _rootPrint); |
+ _ZoneFunction<ForkHandler> get _fork => |
+ const _ZoneFunction<ForkHandler>(_ROOT_ZONE, _rootFork); |
+ _ZoneFunction<HandleUncaughtErrorHandler> get _handleUncaughtError => |
+ const _ZoneFunction<HandleUncaughtErrorHandler>( |
+ _ROOT_ZONE, _rootHandleUncaughtError); |
// The parent zone. |
_Zone get parent => null; |
@@ -1076,61 +1121,65 @@ class _RootZone extends _Zone { |
// Zone interface. |
- dynamic runGuarded(f()) { |
+ /*=R*/ runGuarded/*<R>*/(/*=R*/ f()) { |
try { |
if (identical(_ROOT_ZONE, Zone._current)) { |
return f(); |
} |
- return _rootRun(null, null, this, f); |
+ return _rootRun/*<R>*/(null, null, this, f); |
} catch (e, s) { |
- return handleUncaughtError(e, s); |
+ return handleUncaughtError/*<R>*/(e, s); |
} |
} |
- dynamic runUnaryGuarded(f(arg), arg) { |
+ /*=R*/ runUnaryGuarded/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
try { |
if (identical(_ROOT_ZONE, Zone._current)) { |
return f(arg); |
} |
- return _rootRunUnary(null, null, this, f, arg); |
+ return _rootRunUnary/*<R, T>*/(null, null, this, f, arg); |
} catch (e, s) { |
- return handleUncaughtError(e, s); |
+ return handleUncaughtError/*<R>*/(e, s); |
} |
} |
- dynamic runBinaryGuarded(f(arg1, arg2), arg1, arg2) { |
+ /*=R*/ runBinaryGuarded/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
try { |
if (identical(_ROOT_ZONE, Zone._current)) { |
return f(arg1, arg2); |
} |
- return _rootRunBinary(null, null, this, f, arg1, arg2); |
+ return _rootRunBinary/*<R, T1, T2>*/(null, null, this, f, arg1, arg2); |
} catch (e, s) { |
- return handleUncaughtError(e, s); |
+ return handleUncaughtError/*<R>*/(e, s); |
} |
} |
- ZoneCallback bindCallback(f(), { bool runGuarded: true }) { |
+ ZoneCallback/*<R>*/ bindCallback/*<R>*/( |
+ /*=R*/ f(), { bool runGuarded: true }) { |
if (runGuarded) { |
- return () => this.runGuarded(f); |
+ return () => this.runGuarded/*<R>*/(f); |
} else { |
- return () => this.run(f); |
+ return () => this.run/*<R>*/(f); |
} |
} |
- ZoneUnaryCallback bindUnaryCallback(f(arg), { bool runGuarded: true }) { |
+ ZoneUnaryCallback/*<R, T>*/ bindUnaryCallback/*<R, T>*/( |
+ /*=R*/ f(/*=T*/ arg), { bool runGuarded: true }) { |
if (runGuarded) { |
- return (arg) => this.runUnaryGuarded(f, arg); |
+ return (arg) => this.runUnaryGuarded/*<R, T>*/(f, arg); |
} else { |
- return (arg) => this.runUnary(f, arg); |
+ return (arg) => this.runUnary/*<R, T>*/(f, arg); |
} |
} |
- ZoneBinaryCallback bindBinaryCallback( |
- f(arg1, arg2), { bool runGuarded: true }) { |
+ ZoneBinaryCallback/*<R, T1, T2>*/ bindBinaryCallback/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), { bool runGuarded: true }) { |
if (runGuarded) { |
- return (arg1, arg2) => this.runBinaryGuarded(f, arg1, arg2); |
+ return (arg1, arg2) => |
+ this.runBinaryGuarded/*<R, T1, T2>*/(f, arg1, arg2); |
} else { |
- return (arg1, arg2) => this.runBinary(f, arg1, arg2); |
+ return (arg1, arg2) => this.runBinary/*<R, T1, T2>*/(f, arg1, arg2); |
} |
} |
@@ -1138,7 +1187,7 @@ class _RootZone extends _Zone { |
// Methods that can be customized by the zone specification. |
- dynamic handleUncaughtError(error, StackTrace stackTrace) { |
+ /*=R*/ handleUncaughtError/*<R>*/(error, StackTrace stackTrace) { |
return _rootHandleUncaughtError(null, null, this, error, stackTrace); |
} |
@@ -1146,26 +1195,29 @@ class _RootZone extends _Zone { |
return _rootFork(null, null, this, specification, zoneValues); |
} |
- dynamic run(f()) { |
+ /*=R*/ run/*<R>*/(/*=R*/ f()) { |
if (identical(Zone._current, _ROOT_ZONE)) return f(); |
return _rootRun(null, null, this, f); |
} |
- dynamic runUnary(f(arg), arg) { |
+ /*=R*/ runUnary/*<R, T>*/(/*=R*/ f(/*=T*/ arg), /*=T*/ arg) { |
if (identical(Zone._current, _ROOT_ZONE)) return f(arg); |
return _rootRunUnary(null, null, this, f, arg); |
} |
- dynamic runBinary(f(arg1, arg2), arg1, arg2) { |
+ /*=R*/ runBinary/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2), /*=T1*/ arg1, /*=T2*/ arg2) { |
if (identical(Zone._current, _ROOT_ZONE)) return f(arg1, arg2); |
return _rootRunBinary(null, null, this, f, arg1, arg2); |
} |
- ZoneCallback registerCallback(f()) => f; |
+ ZoneCallback/*<R>*/ registerCallback/*<R>*/(/*=R*/ f()) => f; |
- ZoneUnaryCallback registerUnaryCallback(f(arg)) => f; |
+ ZoneUnaryCallback/*<R, T>*/ registerUnaryCallback/*<R, T>*/( |
+ /*=R*/ f(/*=T*/ arg)) => f; |
- ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f; |
+ ZoneBinaryCallback/*<R, T1, T2>*/ registerBinaryCallback/*<R, T1, T2>*/( |
+ /*=R*/ f(/*=T1*/ arg1, /*=T2*/ arg2)) => f; |
AsyncError errorCallback(Object error, StackTrace stackTrace) => null; |
@@ -1213,7 +1265,7 @@ const _ROOT_ZONE = const _RootZone(); |
* new Future(() { throw "asynchronous error"; }); |
* }, onError: print); // Will print "asynchronous error". |
*/ |
-dynamic runZoned(body(), |
+/*=R*/ runZoned/*<R>*/(/*=R*/ body(), |
{ Map zoneValues, |
ZoneSpecification zoneSpecification, |
Function onError }) { |
@@ -1222,7 +1274,7 @@ dynamic runZoned(body(), |
errorHandler = (Zone self, ZoneDelegate parent, Zone zone, |
error, StackTrace stackTrace) { |
try { |
- if (onError is ZoneBinaryCallback) { |
+ if (onError is ZoneBinaryCallback<dynamic/*=R*/, dynamic, StackTrace>) { |
return self.parent.runBinary(onError, error, stackTrace); |
} |
return self.parent.runUnary(onError, error); |