| 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.isolate; | 5 part of dart.isolate; |
| 6 | 6 |
| 7 class IsolateSpawnException implements Exception { | 7 class IsolateSpawnException implements Exception { |
| 8 const IsolateSpawnException(String this._s); | 8 const IsolateSpawnException(String this._s); |
| 9 String toString() => "IsolateSpawnException: '$_s'"; | 9 String toString() => "IsolateSpawnException: '$_s'"; |
| 10 final String _s; | 10 final String _s; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * argument must be a static top-level function or a static method that takes no | 24 * argument must be a static top-level function or a static method that takes no |
| 25 * arguments. It is illegal to pass a function closure. | 25 * arguments. It is illegal to pass a function closure. |
| 26 * | 26 * |
| 27 * When any isolate starts (even the main script of the application), a default | 27 * When any isolate starts (even the main script of the application), a default |
| 28 * [ReceivePort] is created for it. This port is available from the top-level | 28 * [ReceivePort] is created for it. This port is available from the top-level |
| 29 * getter [port] defined in this library. | 29 * getter [port] defined in this library. |
| 30 * | 30 * |
| 31 * [spawnFunction] returns a [SendPort] derived from the child isolate's default | 31 * [spawnFunction] returns a [SendPort] derived from the child isolate's default |
| 32 * port. | 32 * port. |
| 33 * | 33 * |
| 34 * The optional [unhandledExceptionCallback] argument is invoked whenever an |
| 35 * exception inside the isolate is unhandled. It can be seen as a big |
| 36 * `try/catch` around everything that is executed inside the isolate. The |
| 37 * callback should return `true` when it was able to handled the exception. |
| 38 * |
| 34 * See comments at the top of this library for more details. | 39 * See comments at the top of this library for more details. |
| 35 */ | 40 */ |
| 36 SendPort spawnFunction(void topLevelFunction(), | 41 SendPort spawnFunction(void topLevelFunction(), |
| 37 [bool UnhandledExceptionCallback(IsolateUnhandledException e)]) | 42 [bool unhandledExceptionCallback(IsolateUnhandledException e)]) |
| 38 => _Isolate.spawnFunction(topLevelFunction, UnhandledExceptionCallback); | 43 => _Isolate.spawnFunction(topLevelFunction, unhandledExceptionCallback); |
| 39 | 44 |
| 40 /** | 45 /** |
| 41 * Creates and spawns an isolate whose code is available at [uri]. Like with | 46 * Creates and spawns an isolate whose code is available at [uri]. Like with |
| 42 * [spawnFunction], the child isolate will have a default [ReceivePort], and a | 47 * [spawnFunction], the child isolate will have a default [ReceivePort], and a |
| 43 * this function returns a [SendPort] derived from it. | 48 * this function returns a [SendPort] derived from it. |
| 44 * | 49 * |
| 45 * See comments at the top of this library for more details. | 50 * See comments at the top of this library for more details. |
| 46 */ | 51 */ |
| 47 SendPort spawnUri(String uri) => _Isolate.spawnUri(uri); | 52 SendPort spawnUri(String uri) => _Isolate.spawnUri(uri); |
| 48 | 53 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 */ | 169 */ |
| 165 int get hashCode; | 170 int get hashCode; |
| 166 } | 171 } |
| 167 | 172 |
| 168 // The VM doesn't support accessing external globals in the same library. We | 173 // The VM doesn't support accessing external globals in the same library. We |
| 169 // therefore create this wrapper class. | 174 // therefore create this wrapper class. |
| 170 // TODO(6997): Don't go through static class for external variables. | 175 // TODO(6997): Don't go through static class for external variables. |
| 171 abstract class _Isolate { | 176 abstract class _Isolate { |
| 172 external static ReceivePort get port; | 177 external static ReceivePort get port; |
| 173 external static SendPort spawnFunction(void topLevelFunction(), | 178 external static SendPort spawnFunction(void topLevelFunction(), |
| 174 [bool UnhandledExceptionCallback(IsolateUnhandledException e)]); | 179 [bool unhandledExceptionCallback(IsolateUnhandledException e)]); |
| 175 external static SendPort spawnUri(String uri); | 180 external static SendPort spawnUri(String uri); |
| 176 } | 181 } |
| 177 | 182 |
| 178 /** | 183 /** |
| 179 * Wraps unhandled exceptions thrown during isolate execution. It is | 184 * Wraps unhandled exceptions thrown during isolate execution. It is |
| 180 * used to show both the error message and the stack trace for unhandled | 185 * used to show both the error message and the stack trace for unhandled |
| 181 * exceptions. | 186 * exceptions. |
| 182 */ | 187 */ |
| 183 class IsolateUnhandledException implements Exception { | 188 class IsolateUnhandledException implements Exception { |
| 184 /** Message being handled when exception occurred. */ | 189 /** Message being handled when exception occurred. */ |
| 185 final message; | 190 final message; |
| 186 | 191 |
| 187 /** Wrapped exception. */ | 192 /** Wrapped exception. */ |
| 188 final source; | 193 final source; |
| 189 | 194 |
| 190 /** Trace for the wrapped exception. */ | 195 /** Trace for the wrapped exception. */ |
| 191 final Object stackTrace; | 196 final Object stackTrace; |
| 192 | 197 |
| 193 const IsolateUnhandledException(this.message, this.source, this.stackTrace); | 198 const IsolateUnhandledException(this.message, this.source, this.stackTrace); |
| 194 | 199 |
| 195 String toString() { | 200 String toString() { |
| 196 return 'IsolateUnhandledException: exception while handling message: ' | 201 return 'IsolateUnhandledException: exception while handling message: ' |
| 197 '${message} \n ' | 202 '${message} \n ' |
| 198 '${source.toString().replaceAll("\n", "\n ")}\n' | 203 '${source.toString().replaceAll("\n", "\n ")}\n' |
| 199 'original stack trace:\n ' | 204 'original stack trace:\n ' |
| 200 '${stackTrace.toString().replaceAll("\n","\n ")}'; | 205 '${stackTrace.toString().replaceAll("\n","\n ")}'; |
| 201 } | 206 } |
| 202 } | 207 } |
| OLD | NEW |