Chromium Code Reviews| 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 library pub.load_transformers; | 5 library pub.load_transformers; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
| 10 | 10 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 return controller.stream; | 359 return controller.stream; |
| 360 } | 360 } |
| 361 """; | 361 """; |
| 362 | 362 |
| 363 /// Load and return all transformers and groups from the library identified by | 363 /// Load and return all transformers and groups from the library identified by |
| 364 /// [id]. | 364 /// [id]. |
| 365 Future<Set> loadTransformers(BuildEnvironment environment, TransformerId id) { | 365 Future<Set> loadTransformers(BuildEnvironment environment, TransformerId id) { |
| 366 return id.getAssetId(environment.barback).then((assetId) { | 366 return id.getAssetId(environment.barback).then((assetId) { |
| 367 var path = assetId.path.replaceFirst('lib/', ''); | 367 var path = assetId.path.replaceFirst('lib/', ''); |
| 368 // TODO(nweiz): load from a "package:" URI when issue 12474 is fixed. | 368 // TODO(nweiz): load from a "package:" URI when issue 12474 is fixed. |
| 369 var baseUrl = baseUrlForAddress(environment.server.address, | 369 var baseUrl = baseUrlForAddress(environment.servers.first.address, |
| 370 environment.server.port); | 370 environment.servers.first.port); |
|
Bob Nystrom
2014/02/19 00:36:52
Document why using .first is OK.
nweiz
2014/02/19 01:25:58
Done.
| |
| 371 var uri = '$baseUrl/packages/${id.package}/$path'; | 371 var uri = '$baseUrl/packages/${id.package}/$path'; |
| 372 var code = 'import "$uri";\n' + | 372 var code = 'import "$uri";\n' + |
| 373 _TRANSFORMER_ISOLATE.replaceAll('<<URL_BASE>>', baseUrl); | 373 _TRANSFORMER_ISOLATE.replaceAll('<<URL_BASE>>', baseUrl); |
| 374 log.fine("Loading transformers from $assetId"); | 374 log.fine("Loading transformers from $assetId"); |
| 375 | 375 |
| 376 var port = new ReceivePort(); | 376 var port = new ReceivePort(); |
| 377 return dart.runInIsolate(code, port.sendPort) | 377 return dart.runInIsolate(code, port.sendPort) |
| 378 .then((_) => port.first) | 378 .then((_) => port.first) |
| 379 .then((sendPort) { | 379 .then((sendPort) { |
| 380 return _call(sendPort, { | 380 return _call(sendPort, { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 }); | 553 }); |
| 554 | 554 |
| 555 return Chain.track(receivePort.first).then((response) { | 555 return Chain.track(receivePort.first).then((response) { |
| 556 if (response['type'] == 'success') return response['value']; | 556 if (response['type'] == 'success') return response['value']; |
| 557 assert(response['type'] == 'error'); | 557 assert(response['type'] == 'error'); |
| 558 return new Future.error( | 558 return new Future.error( |
| 559 new dart.CrossIsolateException.deserialize(response['error']), | 559 new dart.CrossIsolateException.deserialize(response['error']), |
| 560 new Chain.current()); | 560 new Chain.current()); |
| 561 }); | 561 }); |
| 562 } | 562 } |
| OLD | NEW |