| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:io'; | 5 import 'dart:io'; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 | 7 |
| 8 final SPAWN_PACKAGE_ROOT = "file:///no/such/file/"; | 8 final SPAWN_PACKAGE_ROOT = "file:///no/such/file/"; |
| 9 | 9 |
| 10 main([args, port]) async { | 10 main([args, port]) async { |
| 11 if (port != null) { | 11 if (port != null) { |
| 12 testPackageRoot(port); | 12 testPackageRoot(port); |
| 13 return; | 13 return; |
| 14 } | 14 } |
| 15 var p = new RawReceivePort(); | 15 var p = new RawReceivePort(); |
| 16 Isolate.spawnUri(Platform.script, | 16 Isolate.spawnUri(Platform.script, [], p.sendPort, |
| 17 [], | 17 packageRoot: Uri.parse(SPAWN_PACKAGE_ROOT)); |
| 18 p.sendPort, | |
| 19 packageRoot: Uri.parse(SPAWN_PACKAGE_ROOT)); | |
| 20 p.handler = (msg) { | 18 p.handler = (msg) { |
| 21 p.close(); | 19 p.close(); |
| 22 if (msg != SPAWN_PACKAGE_ROOT) { | 20 if (msg != SPAWN_PACKAGE_ROOT) { |
| 23 throw "Bad package root in child isolate: $msg"; | 21 throw "Bad package root in child isolate: $msg"; |
| 24 } | 22 } |
| 25 print("SUCCESS"); | 23 print("SUCCESS"); |
| 26 }; | 24 }; |
| 27 print("Spawning isolate's package root: ${await Isolate.packageRoot}"); | 25 print("Spawning isolate's package root: ${await Isolate.packageRoot}"); |
| 28 } | 26 } |
| 29 | 27 |
| 30 testPackageRoot(port) async { | 28 testPackageRoot(port) async { |
| 31 var packageRoot = await Isolate.packageRoot; | 29 var packageRoot = await Isolate.packageRoot; |
| 32 print("Spawned isolate's package root: $packageRoot"); | 30 print("Spawned isolate's package root: $packageRoot"); |
| 33 port.send(packageRoot.toString()); | 31 port.send(packageRoot.toString()); |
| 34 } | 32 } |
| OLD | NEW |