| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 _invokeErrorHandler(Function errorHandler, | 7 _invokeErrorHandler(Function errorHandler, |
| 8 Object error, StackTrace stackTrace) { | 8 Object error, StackTrace stackTrace) { |
| 9 if (errorHandler is ZoneBinaryCallback) { | 9 if (errorHandler is ZoneBinaryCallback) { |
| 10 return errorHandler(error, stackTrace); | 10 return errorHandler(error, stackTrace); |
| 11 } else { | 11 } else { |
| 12 ZoneUnaryCallback unaryErrorHandler = errorHandler; | 12 ZoneUnaryCallback unaryErrorHandler = errorHandler; |
| 13 return unaryErrorHandler(error); | 13 return unaryErrorHandler(error); |
| 14 } | 14 } |
| 15 } | 15 } |
| 16 | 16 |
| 17 Function _registerErrorHandler<R>(Function errorHandler, Zone zone) { | 17 Function _registerErrorHandler(Function errorHandler, Zone zone) { |
| 18 // We are not allowed to use 'void' as type argument for the generic type, |
| 19 // so we use 'dynamic' instead. |
| 18 if (errorHandler is ZoneBinaryCallback) { | 20 if (errorHandler is ZoneBinaryCallback) { |
| 19 return zone.registerBinaryCallback<R, dynamic, StackTrace>( | 21 return zone.registerBinaryCallback<dynamic, dynamic, StackTrace>( |
| 20 errorHandler as dynamic/*=ZoneBinaryCallback<R, dynamic, StackTrace>*/); | 22 errorHandler as dynamic/*=ZoneBinaryCallback<dynamic, dynamic, StackTrac
e>*/); |
| 21 } else { | 23 } else { |
| 22 return zone.registerUnaryCallback<R, dynamic>( | 24 return zone.registerUnaryCallback<dynamic, dynamic>( |
| 23 errorHandler as dynamic/*=ZoneUnaryCallback<R, dynamic>*/); | 25 errorHandler as dynamic/*=ZoneUnaryCallback<dynamic, dynamic>*/); |
| 24 } | 26 } |
| 25 } | 27 } |
| 26 | 28 |
| 27 class _UncaughtAsyncError extends AsyncError { | 29 class _UncaughtAsyncError extends AsyncError { |
| 28 _UncaughtAsyncError(error, StackTrace stackTrace) | 30 _UncaughtAsyncError(error, StackTrace stackTrace) |
| 29 : super(error, _getBestStackTrace(error, stackTrace)); | 31 : super(error, _getBestStackTrace(error, stackTrace)); |
| 30 | 32 |
| 31 static StackTrace _getBestStackTrace(error, StackTrace stackTrace) { | 33 static StackTrace _getBestStackTrace(error, StackTrace stackTrace) { |
| 32 if (stackTrace != null) return stackTrace; | 34 if (stackTrace != null) return stackTrace; |
| 33 if (error is Error) { | 35 if (error is Error) { |
| 34 return error.stackTrace; | 36 return error.stackTrace; |
| 35 } | 37 } |
| 36 return null; | 38 return null; |
| 37 } | 39 } |
| 38 | 40 |
| 39 String toString() { | 41 String toString() { |
| 40 String result = "Uncaught Error: ${error}"; | 42 String result = "Uncaught Error: ${error}"; |
| 41 | 43 |
| 42 if (stackTrace != null) { | 44 if (stackTrace != null) { |
| 43 result += "\nStack Trace:\n$stackTrace"; | 45 result += "\nStack Trace:\n$stackTrace"; |
| 44 } | 46 } |
| 45 return result; | 47 return result; |
| 46 } | 48 } |
| 47 } | 49 } |
| OLD | NEW |