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

Unified Diff: lib/io/string_stream.dart

Issue 11345027: Do error propagation for decoder errors in string stream. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | « no previous file | tests/standalone/io/string_stream_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/io/string_stream.dart
===================================================================
--- lib/io/string_stream.dart (revision 14280)
+++ lib/io/string_stream.dart (working copy)
@@ -30,6 +30,9 @@
// no line break is present. The line break character sequence is
// discarded.
String get decodedLine;
+
+ // Set the handler that will be called if an error ocurs while decoding.
+ void set onError(Function callback);
}
@@ -166,6 +169,7 @@
int _charOffset = 0; // Character number of the first character in the list.
int _charCount = 0; // Total number of characters decoded.
int _lastCharCode = -1;
+ Function onError;
final int LF = 10;
final int CR = 13;
@@ -221,7 +225,13 @@
while (_bufferList.length > 0) {
int byte = _bufferList.next();
if (byte > 127) {
- throw new DecoderException("Illegal ASCII character $byte");
+ var error = new DecoderException("Illegal ASCII character $byte");
+ if (onError != null) {
+ onError(error);
+ return false;
+ } else {
+ throw error;
+ }
}
addChar(byte);
}
@@ -409,6 +419,11 @@
void set onError(void callback(e)) {
_input.onError = callback;
+ _decoder.onError = (e) {
+ _clientCloseHandler = null;
+ _input.close();
+ callback(e);
+ };
}
void _onData() {
@@ -425,9 +440,8 @@
void _onClosed() {
_inputClosed = true;
- if (_decoder.isEmpty && _clientCloseHandler != null) {
+ if (_decoder.isEmpty && _clientCloseHandler != null) {
_clientCloseHandler();
- _closed = true;
} else {
_checkScheduleCallback();
}
« no previous file with comments | « no previous file | tests/standalone/io/string_stream_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698