| Index: lib/src/dart.dart
|
| diff --git a/lib/src/dart.dart b/lib/src/dart.dart
|
| index 5f4aea5fa09a3454a9bce8c7d0adfc3ee547b91a..e59b37f8f395eddf0762e4d6c7efcfb0bf559959 100644
|
| --- a/lib/src/dart.dart
|
| +++ b/lib/src/dart.dart
|
| @@ -11,6 +11,7 @@ import 'dart:isolate';
|
| import 'package:path/path.dart' as p;
|
|
|
| import 'io.dart';
|
| +import 'isolate_wrapper.dart';
|
| import 'remote_exception.dart';
|
|
|
| /// Runs [code] in an isolate.
|
| @@ -24,23 +25,28 @@ import 'remote_exception.dart';
|
| /// [String] or a [Uri].
|
| Future<Isolate> runInIsolate(String code, message, {packageRoot}) {
|
| // TODO(nweiz): load code from a local server rather than from a file.
|
| - return withTempDir((dir) {
|
| - var dartPath = p.join(dir, 'runInIsolate.dart');
|
| - new File(dartPath).writeAsStringSync(code);
|
| - var port = new ReceivePort();
|
| - return Isolate.spawn(_isolateBuffer, {
|
| - 'replyTo': port.sendPort,
|
| - 'uri': p.toUri(dartPath).toString(),
|
| - 'packageRoot': packageRoot == null ? null : packageRoot.toString(),
|
| - 'message': message
|
| - }).then((isolate) {
|
| - return port.first.then((response) {
|
| - if (response['type'] != 'error') return isolate;
|
| - isolate.kill();
|
| - var asyncError = RemoteException.deserialize(response['error']);
|
| - return new Future.error(asyncError.error, asyncError.stackTrace);
|
| - });
|
| + var dir = Directory.systemTemp.createTempSync().path;
|
| + var dartPath = p.join(dir, 'runInIsolate.dart');
|
| + new File(dartPath).writeAsStringSync(code);
|
| + var port = new ReceivePort();
|
| + return Isolate.spawn(_isolateBuffer, {
|
| + 'replyTo': port.sendPort,
|
| + 'uri': p.toUri(dartPath).toString(),
|
| + 'packageRoot': packageRoot == null ? null : packageRoot.toString(),
|
| + 'message': message
|
| + }).then((isolate) {
|
| + return port.first.then((response) {
|
| + if (response['type'] != 'error') return isolate;
|
| + isolate.kill();
|
| + var asyncError = RemoteException.deserialize(response['error']);
|
| + return new Future.error(asyncError.error, asyncError.stackTrace);
|
| });
|
| + }).catchError((error) {
|
| + new Directory(dir).deleteSync(recursive: true);
|
| + throw error;
|
| + }).then((isolate) {
|
| + return new IsolateWrapper(isolate,
|
| + () => new Directory(dir).deleteSync(recursive: true));
|
| });
|
| }
|
|
|
|
|