Permalink
Browse files

Parser stream interface: write() & end() emit 'error'

  • Loading branch information...
1 parent 2e11630 commit bde1fcb2656661a4ae14164cec833a1771f9a594 @astro committed Jun 22, 2012
Showing with 21 additions and 4 deletions.
  1. +21 −4 lib/node-expat.js
View
@@ -44,11 +44,28 @@ Parser.prototype.destroySoon = function() {
this.destroy();
};
-Parser.prototype.write = Parser.prototype.parse;
+Parser.prototype.write = function(data) {
+ try {
+ this.parse(data);
+ } catch (e) {
+ this.emit('error', e);
+ this.emit('close');
+ }
+};
+
+Parser.prototype.end = function(data) {
+ var error;
+ try {
+ this.parse(data || "", true);
+ } catch (e) {
+ error = e;
+ }
-Parser.prototype.end = function() {
- this.emit('end');
- this.emit('close');
+ if (!error)
+ this.emit('end');
+ else
+ this.emit('error', error);
+ this.emit('close');
};
Parser.prototype.reset = function() {

0 comments on commit bde1fcb

Please sign in to comment.