| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 }; | 268 }; |
| 269 // Make sure the message handler is triggered. | 269 // Make sure the message handler is triggered. |
| 270 port.sendPort.send(null); | 270 port.sendPort.send(null); |
| 271 } | 271 } |
| 272 | 272 |
| 273 patch class Isolate { | 273 patch class Isolate { |
| 274 static final _currentIsolate = _getCurrentIsolate(); | 274 static final _currentIsolate = _getCurrentIsolate(); |
| 275 | 275 |
| 276 /* patch */ static Isolate get current => _currentIsolate; | 276 /* patch */ static Isolate get current => _currentIsolate; |
| 277 | 277 |
| 278 /* patch */ static Future<Uri> get packageRoot { | |
| 279 var hook = VMLibraryHooks.getPackageRoot; | |
| 280 if (hook == null) { | |
| 281 throw new UnimplementedError("Isolate.packageRoot"); | |
| 282 } | |
| 283 return hook(); | |
| 284 } | |
| 285 | |
| 286 /* patch */ static Future<Map<String, Uri>> get packageMap { | |
| 287 var hook = VMLibraryHooks.getPackageMap; | |
| 288 if (hook == null) { | |
| 289 throw new UnimplementedError("Isolate.packageMap"); | |
| 290 } | |
| 291 return hook(); | |
| 292 } | |
| 293 | |
| 294 /* patch */ static Future<Isolate> spawn( | 278 /* patch */ static Future<Isolate> spawn( |
| 295 void entryPoint(message), var message, | 279 void entryPoint(message), var message, |
| 296 {bool paused: false, bool errorsAreFatal, | 280 {bool paused: false, bool errorsAreFatal, |
| 297 SendPort onExit, SendPort onError}) { | 281 SendPort onExit, SendPort onError}) { |
| 298 // `paused` isn't handled yet. | 282 // `paused` isn't handled yet. |
| 299 RawReceivePort readyPort; | 283 RawReceivePort readyPort; |
| 300 try { | 284 try { |
| 301 // The VM will invoke [_startIsolate] with entryPoint as argument. | 285 // The VM will invoke [_startIsolate] with entryPoint as argument. |
| 302 readyPort = new RawReceivePort(); | 286 readyPort = new RawReceivePort(); |
| 303 _spawnFunction(readyPort.sendPort, entryPoint, message, | 287 _spawnFunction(readyPort.sendPort, entryPoint, message, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 323 } | 307 } |
| 324 | 308 |
| 325 /* patch */ static Future<Isolate> spawnUri( | 309 /* patch */ static Future<Isolate> spawnUri( |
| 326 Uri uri, List<String> args, var message, | 310 Uri uri, List<String> args, var message, |
| 327 {bool paused: false, | 311 {bool paused: false, |
| 328 SendPort onExit, | 312 SendPort onExit, |
| 329 SendPort onError, | 313 SendPort onError, |
| 330 bool errorsAreFatal, | 314 bool errorsAreFatal, |
| 331 bool checked, | 315 bool checked, |
| 332 Map<String, String> environment, | 316 Map<String, String> environment, |
| 333 Uri packageRoot, | 317 Uri packageRoot}) { |
| 334 Map<String, Uri> packageMap}) { | |
| 335 RawReceivePort readyPort; | 318 RawReceivePort readyPort; |
| 336 if (environment != null) throw new UnimplementedError("environment"); | 319 if (environment != null) throw new UnimplementedError("environment"); |
| 337 try { | 320 try { |
| 338 // The VM will invoke [_startIsolate] and not `main`. | 321 // The VM will invoke [_startIsolate] and not `main`. |
| 339 readyPort = new RawReceivePort(); | 322 readyPort = new RawReceivePort(); |
| 340 var packageRootString = | 323 var packageRootString = |
| 341 (packageRoot == null) ? null : packageRoot.toString(); | 324 (packageRoot == null) ? null : packageRoot.toString(); |
| 342 var packagesList = null; | 325 var packagesList = null; |
| 343 if (packageMap != null) { | |
| 344 packagesList = new List(2 * packageMap.length); | |
| 345 var i = 0; | |
| 346 packageMap.forEach((key, value) { | |
| 347 packagesList[i++] = key; | |
| 348 packagesList[i++] = Uri.base.resolveUri(value).toString(); | |
| 349 }); | |
| 350 } | |
| 351 | 326 |
| 352 _spawnUri(readyPort.sendPort, uri.toString(), | 327 _spawnUri(readyPort.sendPort, uri.toString(), |
| 353 args, message, | 328 args, message, |
| 354 paused, onExit, onError, | 329 paused, onExit, onError, |
| 355 errorsAreFatal, checked, | 330 errorsAreFatal, checked, |
| 356 null, /* environment */ | 331 null, /* environment */ |
| 357 packageRootString, packagesList); | 332 packageRootString, packagesList); |
| 358 Completer completer = new Completer<Isolate>.sync(); | 333 Completer completer = new Completer<Isolate>.sync(); |
| 359 readyPort.handler = (readyMessage) { | 334 readyPort.handler = (readyMessage) { |
| 360 readyPort.close(); | 335 readyPort.close(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 static Isolate _getCurrentIsolate() { | 464 static Isolate _getCurrentIsolate() { |
| 490 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate(); | 465 List portAndCapabilities = _getPortAndCapabilitiesOfCurrentIsolate(); |
| 491 return new Isolate(portAndCapabilities[0], | 466 return new Isolate(portAndCapabilities[0], |
| 492 pauseCapability: portAndCapabilities[1], | 467 pauseCapability: portAndCapabilities[1], |
| 493 terminateCapability: portAndCapabilities[2]); | 468 terminateCapability: portAndCapabilities[2]); |
| 494 } | 469 } |
| 495 | 470 |
| 496 static List _getPortAndCapabilitiesOfCurrentIsolate() | 471 static List _getPortAndCapabilitiesOfCurrentIsolate() |
| 497 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate"; | 472 native "Isolate_getPortAndCapabilitiesOfCurrentIsolate"; |
| 498 } | 473 } |
| OLD | NEW |