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 part of vmservice_io; | 5 part of vmservice_io; |
6 | 6 |
7 _sanitizeWindowsPath(path) { | 7 _sanitizeWindowsPath(path) { |
8 // For Windows we need to massage the paths a bit according to | 8 // For Windows we need to massage the paths a bit according to |
9 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx | 9 // http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx |
10 // | 10 // |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 FileRequest(this.sp, this.tag, this.uri, this.resolvedUri, this.libraryUrl); | 62 FileRequest(this.sp, this.tag, this.uri, this.resolvedUri, this.libraryUrl); |
63 } | 63 } |
64 | 64 |
65 bool _traceLoading = false; | 65 bool _traceLoading = false; |
66 | 66 |
67 // State associated with the isolate that is used for loading. | 67 // State associated with the isolate that is used for loading. |
68 class IsolateLoaderState extends IsolateEmbedderData { | 68 class IsolateLoaderState extends IsolateEmbedderData { |
69 IsolateLoaderState(this.isolateId); | 69 IsolateLoaderState(this.isolateId); |
70 | 70 |
71 final int isolateId; | 71 final int isolateId; |
72 | 72 bool _dead = false; |
73 SendPort sp; | 73 SendPort sp; |
74 | 74 |
75 void init(String packageRootFlag, String packagesConfigFlag, | 75 void init(String packageRootFlag, String packagesConfigFlag, |
76 String workingDirectory, String rootScript) { | 76 String workingDirectory, String rootScript) { |
| 77 if (_dead) { |
| 78 return; |
| 79 } |
77 // _workingDirectory must be set first. | 80 // _workingDirectory must be set first. |
78 _workingDirectory = new Uri.directory(workingDirectory); | 81 _workingDirectory = new Uri.directory(workingDirectory); |
79 if (rootScript != null) { | 82 if (rootScript != null) { |
80 _rootScript = Uri.parse(rootScript); | 83 _rootScript = Uri.parse(rootScript); |
81 } | 84 } |
82 // If the --package-root flag was passed. | 85 // If the --package-root flag was passed. |
83 if (packageRootFlag != null) { | 86 if (packageRootFlag != null) { |
84 _setPackageRoot(packageRootFlag); | 87 _setPackageRoot(packageRootFlag); |
85 } | 88 } |
86 // If the --packages flag was passed. | 89 // If the --packages flag was passed. |
87 if (packagesConfigFlag != null) { | 90 if (packagesConfigFlag != null) { |
88 _setPackagesConfig(packagesConfigFlag); | 91 _setPackagesConfig(packagesConfigFlag); |
89 } | 92 } |
90 _fileRequestQueue = new List<FileRequest>(); | 93 if (_fileRequestQueue != null) { |
| 94 _fileRequestQueue = new List<FileRequest>(); |
| 95 } |
91 } | 96 } |
92 | 97 |
93 void cleanup() { | 98 void cleanup() { |
| 99 _dead = true; |
94 if (_packagesPort != null) { | 100 if (_packagesPort != null) { |
95 _packagesPort.close(); | 101 _packagesPort.close(); |
96 _packagesPort = null; | 102 _packagesPort = null; |
97 } | 103 } |
98 } | 104 } |
99 | 105 |
100 // The working directory when the embedder started. | 106 // The working directory when the embedder started. |
101 Uri _workingDirectory; | 107 Uri _workingDirectory; |
102 | 108 |
103 // The root script's uri. | 109 // The root script's uri. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 254 } |
249 if (_traceLoading) { | 255 if (_traceLoading) { |
250 _log("Resolved '$uri' to '$resolvedUri'."); | 256 _log("Resolved '$uri' to '$resolvedUri'."); |
251 } | 257 } |
252 return resolvedUri; | 258 return resolvedUri; |
253 } | 259 } |
254 | 260 |
255 RawReceivePort _packagesPort; | 261 RawReceivePort _packagesPort; |
256 | 262 |
257 void _requestPackagesMap([Uri packageConfig]) { | 263 void _requestPackagesMap([Uri packageConfig]) { |
258 assert(_packagesPort == null); | |
259 assert(_rootScript != null); | 264 assert(_rootScript != null); |
| 265 if (_packagesPort != null) { |
| 266 // Already scheduled. |
| 267 return; |
| 268 } |
260 // Create a port to receive the packages map on. | 269 // Create a port to receive the packages map on. |
261 _packagesPort = new RawReceivePort(_handlePackagesReply); | 270 _packagesPort = new RawReceivePort(_handlePackagesReply); |
262 var sp = _packagesPort.sendPort; | 271 var sp = _packagesPort.sendPort; |
263 | 272 |
264 if (packageConfig != null) { | 273 if (packageConfig != null) { |
265 // Explicitly specified .packages path. | 274 // Explicitly specified .packages path. |
266 _handlePackagesRequest(sp, _traceLoading, -2, packageConfig); | 275 _handlePackagesRequest(sp, _traceLoading, -2, packageConfig); |
267 } else { | 276 } else { |
268 // Search for .packages or packages/ starting at the root script. | 277 // Search for .packages or packages/ starting at the root script. |
269 _handlePackagesRequest(sp, _traceLoading, -1, _rootScript); | 278 _handlePackagesRequest(sp, _traceLoading, -1, _rootScript); |
270 } | 279 } |
271 | 280 |
272 if (_traceLoading) { | 281 if (_traceLoading) { |
273 _log("Requested packages map for '$_rootScript'."); | 282 _log("Requested packages map for '$_rootScript'."); |
274 } | 283 } |
275 } | 284 } |
276 | 285 |
277 void _handlePackagesReply(msg) { | 286 void _handlePackagesReply(msg) { |
278 assert(_packagesPort != null); | 287 if (_packagesPort == null) { |
| 288 return; |
| 289 } |
279 // Make sure to close the _packagePort before any other action. | 290 // Make sure to close the _packagePort before any other action. |
280 _packagesPort.close(); | 291 _packagesPort.close(); |
281 _packagesPort = null; | 292 _packagesPort = null; |
282 | 293 |
283 if (_traceLoading) { | 294 if (_traceLoading) { |
284 _log("Got packages reply: $msg"); | 295 _log("Got packages reply: $msg"); |
285 } | 296 } |
286 if (msg is String) { | 297 if (msg is String) { |
287 if (_traceLoading) { | 298 if (_traceLoading) { |
288 _log("Got failure response on package port: '$msg'"); | 299 _log("Got failure response on package port: '$msg'"); |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 msg[2] = resolvedUri.toString(); | 1150 msg[2] = resolvedUri.toString(); |
1140 msg[3] = null; | 1151 msg[3] = null; |
1141 msg[4] = e.toString(); | 1152 msg[4] = e.toString(); |
1142 sp.send(msg); | 1153 sp.send(msg); |
1143 } | 1154 } |
1144 break; | 1155 break; |
1145 default: | 1156 default: |
1146 _log('Unknown loader request tag=$tag from $isolateId'); | 1157 _log('Unknown loader request tag=$tag from $isolateId'); |
1147 } | 1158 } |
1148 } | 1159 } |
OLD | NEW |