Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Unified Diff: sdk/lib/utf/utf_stream.dart

Issue 25354003: Redo StreamTransformers so they work with Stack traces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/websocket_impl.dart ('k') | tests/co19/co19-co19.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/utf/utf_stream.dart
diff --git a/sdk/lib/utf/utf_stream.dart b/sdk/lib/utf/utf_stream.dart
index 590790ad32791c1a64291bc380b52d825ddc21af..18675d84a1adf0dc72be3ae576dca11809e69a2f 100644
--- a/sdk/lib/utf/utf_stream.dart
+++ b/sdk/lib/utf/utf_stream.dart
@@ -5,14 +5,28 @@
part of dart.utf;
abstract class _StringDecoder
- extends StreamEventTransformer<List<int>, String> {
+ implements StreamTransformer<List<int>, String>, EventSink<List<int>> {
List<int> _carry;
List<int> _buffer;
int _replacementChar;
+ EventSink<String> _outSink;
+
_StringDecoder(int this._replacementChar);
- void handleData(List<int> bytes, EventSink<String> sink) {
+ Stream<String> bind(Stream<List<int>> stream) {
+ return new Stream.eventTransformed(
+ stream,
+ (EventSink<String> sink) {
+ if (_outSink != null) {
+ throw new StateError("String decoder already used");
+ }
+ _outSink = sink;
+ return this;
+ });
+ }
+
+ void add(List<int> bytes) {
try {
_buffer = <int>[];
List<int> carry = _carry;
@@ -55,24 +69,28 @@ abstract class _StringDecoder
}
if (_buffer.length > 0) {
// Limit to 'goodChars', if lower than actual charCodes in the buffer.
- sink.add(new String.fromCharCodes(_buffer));
+ _outSink.add(new String.fromCharCodes(_buffer));
}
_buffer = null;
- } catch (e) {
- sink.addError(e);
+ } catch (e, stackTrace) {
+ _outSink.addError(e, stackTrace);
}
}
- void handleDone(EventSink<String> sink) {
+ void addError(Object error, [StackTrace stackTrace]) {
+ _outSink.addError(error, stackTrace);
+ }
+
+ void close() {
if (_carry != null) {
if (_replacementChar != null) {
- sink.add(new String.fromCharCodes(
+ _outSink.add(new String.fromCharCodes(
new List.filled(_carry.length, _replacementChar)));
} else {
throw new ArgumentError('Invalid codepoint');
}
}
- sink.close();
+ _outSink.close();
}
int _processBytes(int getNext());
@@ -152,12 +170,32 @@ class Utf8DecoderTransformer extends _StringDecoder {
abstract class _StringEncoder
- extends StreamEventTransformer<String, List<int>> {
+ implements StreamTransformer<String, List<int>>, EventSink<String> {
+
+ EventSink<List<int>> _outSink;
- void handleData(String data, EventSink<List<int>> sink) {
- sink.add(_processString(data));
+ Stream<List<int>> bind(Stream<String> stream) {
+ return new Stream.eventTransformed(
+ stream,
+ (EventSink<List<int>> sink) {
+ if (_outSink != null) {
+ throw new StateError("String encoder already used");
+ }
+ _outSink = sink;
+ return this;
+ });
+ }
+
+ void add(String data) {
+ _outSink.add(_processString(data));
}
+ void addError(Object error, [StackTrace stackTrace]) {
+ _outSink.addError(error, stackTrace);
+ }
+
+ void close() { _outSink.close(); }
+
List<int> _processString(String string);
}
« no previous file with comments | « sdk/lib/io/websocket_impl.dart ('k') | tests/co19/co19-co19.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698