[Pkg-javascript-commits] [node-expat] 202/371: Parser.write(): check for error and emit 'error'

Jonas Smedegaard dr at jones.dk
Sun Feb 28 10:00:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-expat.

commit cb33880018fc3f96a014140ebfda38b647c86288
Author: Astro <astro at spaceboyz.net>
Date:   Tue Oct 9 01:55:21 2012 +0200

    Parser.write(): check for error and emit 'error'
    
    This is the stream interface. Using parse() will not emit 'error'.
---
 lib/node-expat.js | 11 +++++++++--
 test.js           | 10 ++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/lib/node-expat.js b/lib/node-expat.js
index b023693..45b4a1f 100644
--- a/lib/node-expat.js
+++ b/lib/node-expat.js
@@ -45,12 +45,19 @@ Parser.prototype.destroySoon = function() {
 };
 
 Parser.prototype.write = function(data) {
+    var error, result;
     try {
-	this.parse(data);
+	result = this.parse(data);
+	if (!result)
+	    error = this.getError();
     } catch (e) {
-	this.emit('error', e);
+	error = e;
+    }
+    if (error) {
+	this.emit('error', error);
 	this.emit('close');
     }
+    return result;
 };
 
 Parser.prototype.end = function(data) {
diff --git a/test.js b/test.js
index 99a647c..affc2a9 100644
--- a/test.js
+++ b/test.js
@@ -58,14 +58,16 @@ function expectWithParserAndStep(s, evs_expected, p, step) {
 	p.addListener('entityDecl', function(entityName, isParameterEntity, value, base, systemId, publicId, notationName) {
 	    evs_received.push(['entityDecl', entityName, isParameterEntity, value, base, systemId, publicId, notationName]);
 	});
+	p.addListener('error', function(e) {
+	    evs_received.push(['error', e]);
+	});
 	for(var l = 0; l < s.length; l += step)
 	{
 	    var end = l + step;
 	    if (end > s.length)
 		end = s.length;
 
-	    if (!p.parse(s.slice(l, end), false))
-		evs_received.push(['error']);
+	    p.write(s.slice(l, end));
 	}
 
 	var expected = JSON.stringify(evs_expected);
@@ -171,7 +173,7 @@ vows.describe('node-expat').addBatch({
     },
     'error': {
 	'tag name starting with ampersand': function() {
-	    expect("<&", [['error']]);
+	    expect("<&", [['error', "not well-formed (invalid token)"]]);
 	}
     },
 
@@ -190,7 +192,7 @@ vows.describe('node-expat').addBatch({
   },
   'with doc error': function() {
 	    var p = new expat.Parser("UTF-8");
-	    expectWithParserAndStep("</end>", [["error"]], p, 1000);
+	    expectWithParserAndStep("</end>", [["error", "not well-formed (invalid token)"]], p, 1000);
       p.reset();
 	    expectWithParserAndStep("<restart><third>moretext</third><fourth /></restart>", [['startElement', 'restart', {}], ['startElement', 'third', {}], ['text', "moretext"], ['endElement', 'third'], ['startElement', 'fourth', {}], ['endElement', 'fourth'], ['endElement', 'restart']], p, 1000);
   }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-expat.git



More information about the Pkg-javascript-commits mailing list