OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// A library for compiling Dart code and manipulating analyzer parse trees. | 5 /// A library for compiling Dart code and manipulating analyzer parse trees. |
6 library pub.dart; | 6 library pub.dart; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 /// | 157 /// |
158 /// If [snapshot] is passed, the isolate will be loaded from that path if it | 158 /// If [snapshot] is passed, the isolate will be loaded from that path if it |
159 /// exists. Otherwise, a snapshot of the isolate's code will be saved to that | 159 /// exists. Otherwise, a snapshot of the isolate's code will be saved to that |
160 /// path once the isolate is loaded. | 160 /// path once the isolate is loaded. |
161 Future runInIsolate(String code, message, {packageRoot, String snapshot}) | 161 Future runInIsolate(String code, message, {packageRoot, String snapshot}) |
162 async { | 162 async { |
163 if (snapshot != null && fileExists(snapshot)) { | 163 if (snapshot != null && fileExists(snapshot)) { |
164 log.fine("Spawning isolate from $snapshot."); | 164 log.fine("Spawning isolate from $snapshot."); |
165 if (packageRoot != null) packageRoot = Uri.parse(packageRoot.toString()); | 165 if (packageRoot != null) packageRoot = Uri.parse(packageRoot.toString()); |
166 try { | 166 try { |
167 await Isolate.spawnUri(p.toUri(snapshot), [], message, | 167 // Make the snapshot URI absolute to work around sdk#8440. |
| 168 await Isolate.spawnUri(p.toUri(p.absolute(snapshot)), [], message, |
168 packageRoot: packageRoot); | 169 packageRoot: packageRoot); |
169 return; | 170 return; |
170 } on IsolateSpawnException catch (error) { | 171 } on IsolateSpawnException catch (error) { |
171 log.fine("Couldn't load existing snapshot $snapshot:\n$error"); | 172 log.fine("Couldn't load existing snapshot $snapshot:\n$error"); |
172 // Do nothing, we will regenerate the snapshot below. | 173 // Do nothing, we will regenerate the snapshot below. |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
176 await withTempDir((dir) async { | 177 await withTempDir((dir) async { |
177 var dartPath = p.join(dir, 'runInIsolate.dart'); | 178 var dartPath = p.join(dir, 'runInIsolate.dart'); |
178 writeTextFile(dartPath, code, dontLogContents: true); | 179 writeTextFile(dartPath, code, dontLogContents: true); |
179 var port = new ReceivePort(); | 180 var port = new ReceivePort(); |
180 await Isolate.spawn(_isolateBuffer, { | 181 await Isolate.spawn(_isolateBuffer, { |
181 'replyTo': port.sendPort, | 182 'replyTo': port.sendPort, |
182 'uri': p.toUri(dartPath).toString(), | 183 // Make the snapshot URI absolute to work around sdk#8440. |
| 184 'uri': p.toUri(p.absolute(dartPath)).toString(), |
183 'packageRoot': packageRoot == null ? null : packageRoot.toString(), | 185 'packageRoot': packageRoot == null ? null : packageRoot.toString(), |
184 'message': message | 186 'message': message |
185 }); | 187 }); |
186 | 188 |
187 var response = await port.first; | 189 var response = await port.first; |
188 if (response['type'] == 'error') { | 190 if (response['type'] == 'error') { |
189 throw new CrossIsolateException.deserialize(response['error']); | 191 throw new CrossIsolateException.deserialize(response['error']); |
190 } | 192 } |
191 | 193 |
192 if (snapshot == null) return; | 194 if (snapshot == null) return; |
(...skipping 26 matching lines...) Expand all Loading... |
219 Isolate.spawnUri(Uri.parse(message['uri']), [], message['message'], | 221 Isolate.spawnUri(Uri.parse(message['uri']), [], message['message'], |
220 packageRoot: packageRoot) | 222 packageRoot: packageRoot) |
221 .then((_) => replyTo.send({'type': 'success'})) | 223 .then((_) => replyTo.send({'type': 'success'})) |
222 .catchError((e, stack) { | 224 .catchError((e, stack) { |
223 replyTo.send({ | 225 replyTo.send({ |
224 'type': 'error', | 226 'type': 'error', |
225 'error': CrossIsolateException.serialize(e, stack) | 227 'error': CrossIsolateException.serialize(e, stack) |
226 }); | 228 }); |
227 }); | 229 }); |
228 } | 230 } |
OLD | NEW |