| 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 import "dart:collection" show HashMap; | 5 import "dart:collection" show HashMap; |
| 6 | 6 |
| 7 patch class ReceivePort { | 7 patch class ReceivePort { |
| 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 8 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
| 9 | 9 |
| 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = | 10 /* patch */ factory ReceivePort.fromRawReceivePort(RawReceivePort rawPort) = |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // initial startup message has been received. | 193 // initial startup message has been received. |
| 194 } | 194 } |
| 195 | 195 |
| 196 isolateStartHandler(message) { | 196 isolateStartHandler(message) { |
| 197 // We received the initial startup message. Ignore all further messages and | 197 // We received the initial startup message. Ignore all further messages and |
| 198 // close the port which kept this isolate alive. | 198 // close the port which kept this isolate alive. |
| 199 Isolate._self.handler = ignoreHandler; | 199 Isolate._self.handler = ignoreHandler; |
| 200 keepAlivePort.close(); | 200 keepAlivePort.close(); |
| 201 | 201 |
| 202 SendPort replyTo = message[0]; | 202 SendPort replyTo = message[0]; |
| 203 if (replyTo != null) { | |
| 204 // TODO(floitsch): don't send ok-message if we can't find the entry point. | |
| 205 replyTo.send("started"); | |
| 206 } | |
| 207 if (isSpawnUri) { | 203 if (isSpawnUri) { |
| 208 assert(message.length == 3); | 204 assert(message.length == 3); |
| 209 List<String> args = message[1]; | 205 List<String> args = message[1]; |
| 210 var isolateMessage = message[2]; | 206 var isolateMessage = message[2]; |
| 211 if (entryPoint is _MainFunctionArgsMessage) { | 207 if (entryPoint == null) { |
| 208 // Set to null when lookup of "main" failed in C++ code. |
| 209 if (replyTo != null) { |
| 210 replyTo.send(["error", |
| 211 "No main method in isolate library"]); |
| 212 } |
| 213 } else if (entryPoint is _MainFunctionArgsMessage) { |
| 214 if (replyTo != null) replyTo.send("started"); |
| 212 entryPoint(args, isolateMessage); | 215 entryPoint(args, isolateMessage); |
| 213 } else if (entryPoint is _MainFunctionArgs) { | 216 } else if (entryPoint is _MainFunctionArgs) { |
| 217 if (replyTo != null) replyTo.send("started"); |
| 214 entryPoint(args); | 218 entryPoint(args); |
| 219 } else if (entryPoint is _MainFunction) { |
| 220 if (replyTo != null) replyTo.send("started"); |
| 221 entryPoint(); |
| 215 } else { | 222 } else { |
| 216 entryPoint(); | 223 // Report error back to spawner. |
| 224 if (replyTo != null) { |
| 225 replyTo.send(["error", |
| 226 "Incorrect parameter count on main: $entryPoint"]); |
| 227 } |
| 217 } | 228 } |
| 218 } else { | 229 } else { |
| 219 assert(message.length == 2); | 230 assert(message.length == 2); |
| 220 var entryMessage = message[1]; | 231 var entryMessage = message[1]; |
| 232 if (replyTo != null) replyTo.send("started"); |
| 221 entryPoint(entryMessage); | 233 entryPoint(entryMessage); |
| 222 } | 234 } |
| 223 } | 235 } |
| 224 | 236 |
| 225 Isolate._self.handler = isolateStartHandler; | 237 Isolate._self.handler = isolateStartHandler; |
| 226 } | 238 } |
| 227 | 239 |
| 228 patch class Isolate { | 240 patch class Isolate { |
| 229 /* patch */ static Future<Isolate> spawn( | 241 /* patch */ static Future<Isolate> spawn( |
| 230 void entryPoint(message), var message, { bool paused: false }) { | 242 void entryPoint(message), var message, { bool paused: false }) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 249 /* patch */ static Future<Isolate> spawnUri( | 261 /* patch */ static Future<Isolate> spawnUri( |
| 250 Uri uri, List<String> args, var message, { bool paused: false }) { | 262 Uri uri, List<String> args, var message, { bool paused: false }) { |
| 251 // `paused` isn't handled yet. | 263 // `paused` isn't handled yet. |
| 252 try { | 264 try { |
| 253 // The VM will invoke [_startIsolate] and not `main`. | 265 // The VM will invoke [_startIsolate] and not `main`. |
| 254 SendPort controlPort = _spawnUri(uri.toString()); | 266 SendPort controlPort = _spawnUri(uri.toString()); |
| 255 RawReceivePort readyPort = new RawReceivePort(); | 267 RawReceivePort readyPort = new RawReceivePort(); |
| 256 controlPort.send([readyPort.sendPort, args, message]); | 268 controlPort.send([readyPort.sendPort, args, message]); |
| 257 Completer completer = new Completer<Isolate>.sync(); | 269 Completer completer = new Completer<Isolate>.sync(); |
| 258 readyPort.handler = (readyMessage) { | 270 readyPort.handler = (readyMessage) { |
| 259 assert(readyMessage == 'started'); | |
| 260 readyPort.close(); | 271 readyPort.close(); |
| 261 completer.complete(new Isolate(controlPort)); | 272 if ('started' == readyMessage) { |
| 273 completer.complete(new Isolate(controlPort)); |
| 274 } else { |
| 275 assert(readyMessage is List && readyMessage[0] == "error"); |
| 276 String error = readyMessage[1]; |
| 277 var remoteError = new IsolateSpawnException(error); |
| 278 completer.completeError(remoteError); |
| 279 } |
| 262 }; | 280 }; |
| 263 return completer.future; | 281 return completer.future; |
| 264 } catch (e, st) { | 282 } catch (e, st) { |
| 265 return new Future<Isolate>.error(e, st); | 283 return new Future<Isolate>.error(e, st); |
| 266 }; | 284 }; |
| 267 return completer.future; | 285 return completer.future; |
| 268 } | 286 } |
| 269 | 287 |
| 270 static final RawReceivePort _self = _mainPort; | 288 static final RawReceivePort _self = _mainPort; |
| 271 static RawReceivePort get _mainPort native "Isolate_mainPort"; | 289 static RawReceivePort get _mainPort native "Isolate_mainPort"; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 322 } |
| 305 | 323 |
| 306 /* patch */ void addErrorListener(SendPort port) { | 324 /* patch */ void addErrorListener(SendPort port) { |
| 307 throw new UnsupportedError("addErrorListener"); | 325 throw new UnsupportedError("addErrorListener"); |
| 308 } | 326 } |
| 309 | 327 |
| 310 /* patch */ void removeErrorListener(SendPort port) { | 328 /* patch */ void removeErrorListener(SendPort port) { |
| 311 throw new UnsupportedError("removeErrorListener"); | 329 throw new UnsupportedError("removeErrorListener"); |
| 312 } | 330 } |
| 313 } | 331 } |
| OLD | NEW |