Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart |
| index 38938be500f17aec5d12bd33a354718345ff6028..4805d089c9db09ed2185bd6db3ed5df597a83cbe 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart |
| @@ -9,6 +9,7 @@ import 'dart:convert'; |
| import 'dart:isolate'; |
| import 'package:barback/barback.dart'; |
| +import 'package:barback/src/internal_asset.dart'; |
| import 'package:source_maps/source_maps.dart'; |
| import '../barback.dart'; |
| @@ -30,6 +31,7 @@ import 'dart:mirrors'; |
| import 'http://<<HOST_AND_PORT>>/packages/source_maps/span.dart'; |
| import 'http://<<HOST_AND_PORT>>/packages/stack_trace/stack_trace.dart'; |
| import 'http://<<HOST_AND_PORT>>/packages/barback/barback.dart'; |
| +import 'http://<<HOST_AND_PORT>>/packages/barback/src/internal_asset.dart'; |
|
Bob Nystrom
2013/11/08 19:22:14
Add a TODO to not import from "src" once barback h
nweiz
2013/11/08 22:03:49
Done.
|
| /// Sets up the initial communication with the host isolate. |
| void main(_, SendPort replyTo) { |
| @@ -99,7 +101,7 @@ class ForeignTransform implements Transform { |
| /// Creates a transform from a serializable map sent from the host isolate. |
| ForeignTransform(Map transform) |
| : _port = transform['port'], |
| - primaryInput = _deserializeAsset(transform['primaryInput']) { |
| + primaryInput = deserializeAsset(transform['primaryInput']) { |
| _logger = new TransformLogger((assetId, level, message, span) { |
| _call(_port, { |
| 'type': 'log', |
| @@ -115,7 +117,7 @@ class ForeignTransform implements Transform { |
| return _call(_port, { |
| 'type': 'getInput', |
| 'id': _serializeId(id) |
| - }).then(_deserializeAsset); |
| + }).then(deserializeAsset); |
| } |
| Future<String> readInputAsString(AssetId id, {Encoding encoding}) { |
| @@ -129,7 +131,7 @@ class ForeignTransform implements Transform { |
| void addOutput(Asset output) { |
| _call(_port, { |
| 'type': 'addOutput', |
| - 'output': _serializeAsset(output) |
| + 'output': serializeAsset(output) |
| }); |
| } |
| } |
| @@ -184,7 +186,7 @@ Map _serializeTransformer(Transformer transformer) { |
| port.listen((wrappedMessage) { |
| _respond(wrappedMessage, (message) { |
| if (message['type'] == 'isPrimary') { |
| - return transformer.isPrimary(_deserializeAsset(message['asset'])); |
| + return transformer.isPrimary(deserializeAsset(message['asset'])); |
| } else { |
| assert(message['type'] == 'apply'); |
| return transformer.apply( |
| @@ -211,13 +213,6 @@ Map _serializeTransformerGroup(TransformerGroup group) { |
| }; |
| } |
| -/// Converts a serializable map into an [Asset]. |
| -Asset _deserializeAsset(Map asset) { |
| - return new Asset.fromStream( |
| - _deserializeId(asset['id']), |
| - _deserializeStream(asset['stream'])); |
| -} |
| - |
| /// The body of a [StreamTransformer] that deserializes the values in a stream |
| /// sent by [_serializeStream]. |
| StreamSubscription _deserializeTransformer(Stream input, bool cancelOnError) { |
| @@ -238,49 +233,9 @@ StreamSubscription _deserializeTransformer(Stream input, bool cancelOnError) { |
| return subscription; |
| } |
| -/// Convert a [SendPort] whose opposite is waiting to send us a stream into a |
| -/// [Stream]. |
| -/// |
| -/// No stream data will actually be sent across the isolate boundary until |
| -/// someone subscribes to the returned stream. |
| -Stream _deserializeStream(SendPort sendPort) { |
| - return callbackStream(() { |
| - var receivePort = new ReceivePort(); |
| - sendPort.send(receivePort.sendPort); |
| - return receivePort.transform( |
| - const StreamTransformer(_deserializeTransformer)); |
| - }); |
| -} |
| - |
| /// Converts a serializable map into an [AssetId]. |
| AssetId _deserializeId(Map id) => new AssetId(id['package'], id['path']); |
| -/// Converts [asset] into a serializable map. |
| -Map _serializeAsset(Asset asset) { |
| - return { |
| - 'id': _serializeId(asset.id), |
| - 'stream': _serializeStream(asset.read()) |
| - }; |
| -} |
| - |
| -/// Converts [stream] into a [SendPort] with which another isolate can request |
| -/// the data from [stream]. |
| -SendPort _serializeStream(Stream stream) { |
| - var receivePort = new ReceivePort(); |
| - receivePort.first.then((sendPort) { |
| - stream.listen((data) => sendPort.send({'type': 'data', 'data': data}), |
| - onDone: () => sendPort.send({'type': 'done'}), |
| - onError: (error, stackTrace) { |
| - sendPort.send({ |
| - 'type': 'error', |
| - 'error': CrossIsolateException.serialize(error, stackTrace) |
| - }); |
| - }); |
| - }); |
| - |
| - return receivePort.sendPort; |
| -} |
| - |
| /// Converts [id] into a serializable map. |
| Map _serializeId(AssetId id) => {'package': id.package, 'path': id.path}; |
| @@ -503,7 +458,7 @@ class _ForeignTransformer extends Transformer { |
| Future<bool> isPrimary(Asset asset) { |
| return _call(_port, { |
| 'type': 'isPrimary', |
| - 'asset': _serializeAsset(asset) |
| + 'asset': serializeAsset(asset) |
| }); |
| } |
| @@ -547,11 +502,11 @@ Map _serializeTransform(Transform transform) { |
| _respond(wrappedMessage, (message) { |
| if (message['type'] == 'getInput') { |
| return transform.getInput(_deserializeId(message['id'])) |
| - .then(_serializeAsset); |
| + .then((asset) => serializeAsset(asset)); |
| } |
| if (message['type'] == 'addOutput') { |
| - transform.addOutput(_deserializeAsset(message['output'])); |
| + transform.addOutput(deserializeAsset(message['output'])); |
| return null; |
| } |
| @@ -576,17 +531,10 @@ Map _serializeTransform(Transform transform) { |
| return { |
| 'port': receivePort.sendPort, |
| - 'primaryInput': _serializeAsset(transform.primaryInput) |
| + 'primaryInput': serializeAsset(transform.primaryInput) |
| }; |
| } |
| -/// Converts a serializable map into an [Asset]. |
| -Asset _deserializeAsset(Map asset) { |
| - return new Asset.fromStream( |
| - _deserializeId(asset['id']), |
| - _deserializeStream(asset['stream'])); |
| -} |
| - |
| /// A transformer that deserializes the values in a stream sent by |
| /// [_serializeStream]. |
| StreamSubscription _deserializeTransformer(Stream input, bool cancelOnError) { |
| @@ -607,20 +555,6 @@ StreamSubscription _deserializeTransformer(Stream input, bool cancelOnError) { |
| return subscription; |
| } |
| -/// Convert a [SendPort] whose opposite is waiting to send us a stream into a |
| -/// [Stream]. |
| -/// |
| -/// No stream data will actually be sent across the isolate boundary until |
| -/// someone subscribes to the returned stream. |
| -Stream _deserializeStream(SendPort sendPort) { |
| - return callbackStream(() { |
| - var receivePort = new ReceivePort(); |
| - sendPort.send(receivePort.sendPort); |
| - return receivePort.transform( |
| - const StreamTransformer(_deserializeTransformer)); |
| - }); |
| -} |
| - |
| /// Converts a serializable map into an [AssetId]. |
| AssetId _deserializeId(Map id) => new AssetId(id['package'], id['path']); |
| @@ -639,34 +573,6 @@ Location _deserializeLocation(Map location) { |
| location['line'], location['column']); |
| } |
| -// TODO(nweiz): add custom serialization code for assets that can be more |
| -// efficiently serialized. |
| -/// Converts [asset] into a serializable map. |
| -Map _serializeAsset(Asset asset) { |
| - return { |
| - 'id': _serializeId(asset.id), |
| - 'stream': _serializeStream(asset.read()) |
| - }; |
| -} |
| - |
| -/// Converts [stream] into a [SendPort] with which another isolate can request |
| -/// the data from [stream]. |
| -SendPort _serializeStream(Stream stream) { |
| - var receivePort = new ReceivePort(); |
| - receivePort.first.then((sendPort) { |
| - stream.listen((data) => sendPort.send({'type': 'data', 'data': data}), |
| - onDone: () => sendPort.send({'type': 'done'}), |
| - onError: (error, stackTrace) { |
| - sendPort.send({ |
| - 'type': 'error', |
| - 'error': CrossIsolateException.serialize(error, stackTrace) |
| - }); |
| - }); |
| - }); |
| - |
| - return receivePort.sendPort; |
| -} |
| - |
| /// Converts [id] into a serializable map. |
| Map _serializeId(AssetId id) => {'package': id.package, 'path': id.path}; |