| 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 import "dart:_internal"; | 6 import "dart:_internal"; |
| 7 | 7 |
| 8 patch class ReceivePort { | 8 patch class ReceivePort { |
| 9 /* patch */ factory ReceivePort() = _ReceivePortImpl; | 9 /* patch */ factory ReceivePort() = _ReceivePortImpl; |
| 10 | 10 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Make sure the message handler is triggered. | 267 // Make sure the message handler is triggered. |
| 268 port.sendPort.send(null); | 268 port.sendPort.send(null); |
| 269 } | 269 } |
| 270 | 270 |
| 271 patch class Isolate { | 271 patch class Isolate { |
| 272 static final _currentIsolate = _getCurrentIsolate(); | 272 static final _currentIsolate = _getCurrentIsolate(); |
| 273 | 273 |
| 274 /* patch */ static Isolate get current => _currentIsolate; | 274 /* patch */ static Isolate get current => _currentIsolate; |
| 275 | 275 |
| 276 /* patch */ static Future<Isolate> spawn( | 276 /* patch */ static Future<Isolate> spawn( |
| 277 void entryPoint(message), var message, { bool paused: false }) { | 277 void entryPoint(message), var message, |
| 278 {bool paused: false, bool errorsAreFatal, |
| 279 SendPort onExit, SendPort onError}) { |
| 278 // `paused` isn't handled yet. | 280 // `paused` isn't handled yet. |
| 279 RawReceivePort readyPort; | 281 RawReceivePort readyPort; |
| 280 try { | 282 try { |
| 281 // The VM will invoke [_startIsolate] with entryPoint as argument. | 283 // The VM will invoke [_startIsolate] with entryPoint as argument. |
| 282 readyPort = new RawReceivePort(); | 284 readyPort = new RawReceivePort(); |
| 283 _spawnFunction(readyPort.sendPort, entryPoint, message, paused); | 285 _spawnFunction(readyPort.sendPort, entryPoint, message, paused); |
| 284 Completer completer = new Completer<Isolate>.sync(); | 286 Completer completer = new Completer<Isolate>.sync(); |
| 285 readyPort.handler = (readyMessage) { | 287 readyPort.handler = (readyMessage) { |
| 286 readyPort.close(); | 288 readyPort.close(); |
| 287 assert(readyMessage is List); | 289 assert(readyMessage is List); |
| 288 assert(readyMessage.length == 2); | 290 assert(readyMessage.length == 2); |
| 289 SendPort controlPort = readyMessage[0]; | 291 SendPort controlPort = readyMessage[0]; |
| 290 List capabilities = readyMessage[1]; | 292 List capabilities = readyMessage[1]; |
| 291 completer.complete(new Isolate(controlPort, | 293 completer.complete(new Isolate(controlPort, |
| 292 pauseCapability: capabilities[0], | 294 pauseCapability: capabilities[0], |
| 293 terminateCapability: capabilities[1])); | 295 terminateCapability: capabilities[1])); |
| 294 }; | 296 }; |
| 295 return completer.future; | 297 return completer.future; |
| 296 } catch (e, st) { | 298 } catch (e, st) { |
| 297 if (readyPort != null) { | 299 if (readyPort != null) { |
| 298 readyPort.close(); | 300 readyPort.close(); |
| 299 } | 301 } |
| 300 return new Future<Isolate>.error(e, st); | 302 return new Future<Isolate>.error(e, st); |
| 301 }; | 303 }; |
| 302 } | 304 } |
| 303 | 305 |
| 304 /* patch */ static Future<Isolate> spawnUri( | 306 /* patch */ static Future<Isolate> spawnUri( |
| 305 Uri uri, List<String> args, var message, | 307 Uri uri, List<String> args, var message, |
| 306 { bool paused: false, bool checked, Uri packageRoot }) { | 308 {bool paused: false, bool checked, Uri packageRoot, bool errorsAreFatal, |
| 309 SendPort onExit, SendPort onError}) { |
| 307 RawReceivePort readyPort; | 310 RawReceivePort readyPort; |
| 308 try { | 311 try { |
| 309 // The VM will invoke [_startIsolate] and not `main`. | 312 // The VM will invoke [_startIsolate] and not `main`. |
| 310 readyPort = new RawReceivePort(); | 313 readyPort = new RawReceivePort(); |
| 311 var packageRootString = | 314 var packageRootString = |
| 312 (packageRoot == null) ? null : packageRoot.toString(); | 315 (packageRoot == null) ? null : packageRoot.toString(); |
| 313 _spawnUri(readyPort.sendPort, uri.toString(), args, message, | 316 _spawnUri(readyPort.sendPort, uri.toString(), args, message, |
| 314 paused, checked, packageRootString); | 317 paused, checked, packageRootString); |
| 315 Completer completer = new Completer<Isolate>.sync(); | 318 Completer completer = new Completer<Isolate>.sync(); |
| 316 readyPort.handler = (readyMessage) { | 319 readyPort.handler = (readyMessage) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 static Isolate _getCurrentIsolate() { | 445 static Isolate _getCurrentIsolate() { |
| 443 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate(); | 446 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate(); |
| 444 return new Isolate(portAndCapabilities[0], | 447 return new Isolate(portAndCapabilities[0], |
| 445 pauseCapability: portAndCapabilities[1], | 448 pauseCapability: portAndCapabilities[1], |
| 446 terminateCapability: portAndCapabilities[2]); | 449 terminateCapability: portAndCapabilities[2]); |
| 447 } | 450 } |
| 448 | 451 |
| 449 static List _getPortAndCapabilitiesOfCurrentIsolate() | 452 static List _getPortAndCapabilitiesOfCurrentIsolate() |
| 450 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate"; | 453 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate"; |
| 451 } | 454 } |
| OLD | NEW |