[Pkg-javascript-commits] [node-expat] 147/371: Imported Upstream version 1.5.0

Jonas Smedegaard dr at jones.dk
Sun Feb 28 09:59:56 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 4ee9fd06934070795e0fd72d3a2217b47e21e276
Author: Jonas Smedegaard <dr at jones.dk>
Date:   Fri Apr 13 12:54:47 2012 -0400

    Imported Upstream version 1.5.0
---
 lib/node-expat.js |  3 +++
 node-expat.cc     | 41 ++++++++++++++++++++++++++++++++++-------
 package.json      |  4 ++--
 test.js           | 30 +++++++++++++++++++++++++++---
 4 files changed, 66 insertions(+), 12 deletions(-)

diff --git a/lib/node-expat.js b/lib/node-expat.js
index 765515e..76962b2 100644
--- a/lib/node-expat.js
+++ b/lib/node-expat.js
@@ -40,6 +40,9 @@ exports.Parser.prototype.pause = function() {
 exports.Parser.prototype.resume = function() {
     return this.parser.resume();
 };
+exports.Parser.prototype.reset = function() {
+    return this.parser.reset();
+};
 exports.Parser.prototype.getCurrentLineNumber = function() {
     return this.parser.getCurrentLineNumber();
 };
diff --git a/node-expat.cc b/node-expat.cc
index c35b3b2..2904918 100644
--- a/node-expat.cc
+++ b/node-expat.cc
@@ -29,6 +29,7 @@ public:
     NODE_SET_PROTOTYPE_METHOD(t, "getError", GetError);
     NODE_SET_PROTOTYPE_METHOD(t, "stop", Stop);
     NODE_SET_PROTOTYPE_METHOD(t, "resume", Resume);
+    NODE_SET_PROTOTYPE_METHOD(t, "reset", Reset);
     NODE_SET_PROTOTYPE_METHOD(t, "getCurrentLineNumber", GetCurrentLineNumber);
     NODE_SET_PROTOTYPE_METHOD(t, "getCurrentColumnNumber", GetCurrentColumnNumber);
     NODE_SET_PROTOTYPE_METHOD(t, "getCurrentByteIndex", GetCurrentByteIndex);
@@ -73,6 +74,16 @@ protected:
     parser = XML_ParserCreate(encoding);
     assert(parser != NULL);
 
+    attachHandlers();
+  }
+
+  ~Parser()
+  {
+    XML_ParserFree(parser);
+  }
+
+  void attachHandlers()
+  {
     XML_SetUserData(parser, this);
     XML_SetElementHandler(parser, StartElement, EndElement);
     XML_SetCharacterDataHandler(parser, Text);
@@ -82,12 +93,7 @@ protected:
     XML_SetXmlDeclHandler(parser, XmlDecl);
     XML_SetEntityDeclHandler(parser, EntityDecl);
   }
-
-  ~Parser()
-  {
-    XML_ParserFree(parser);
-  }
-
+    
   /*** parse() ***/
 
   static Handle<Value> Parse(const Arguments& args)
@@ -235,6 +241,27 @@ protected:
     return XML_ResumeParser(parser) != 0;
   }
   
+  static Handle<Value> Reset(const Arguments& args)
+  {
+    Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
+    HandleScope scope;
+    XML_Char *encoding = NULL;
+    if (args.Length() == 1 && args[0]->IsString())
+      {
+        encoding = new XML_Char[32];
+        args[0]->ToString()->WriteAscii(encoding, 0, 32);
+      }
+
+    int status = parser->reset(encoding);
+    if (status) 
+      parser->attachHandlers();
+    return scope.Close(status ? True() : False());
+  }
+
+  int reset(XML_Char *encoding)
+  {
+      return XML_ParserReset(parser, encoding) != 0;
+  }
   const XML_LChar *getError()
   {
     enum XML_Error code;
@@ -287,7 +314,7 @@ private:
 
   /* no default ctor */
   Parser();
-
+        
   /*** SAX callbacks ***/
   /* Should a local HandleScope be used in those callbacks? */
 
diff --git a/package.json b/package.json
index 00672d2..778aae6 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
 { "name": "node-expat"
-,"version": "1.4.5"
+,"version": "1.5.0"
 ,"main": "./lib/node-expat"
 ,"description": "NodeJS binding for fast XML parsing."
 ,"keywords": ["xml","sax","expat","libexpat","parse","parsing"]
@@ -18,7 +18,7 @@
 	   , "email": "astro at spaceboyz.net"
 	   , "web": "http://spaceboyz.net/~astro/"
 	   }
-,"contributors": ["Stephan Maka", "Derek Hammer", "Iein Valdez", "Peter Körner", "Camilo Aguilar", "Michael Weibel"]
+,"contributors": ["Stephan Maka", "Derek Hammer", "Iein Valdez", "Peter Körner", "Camilo Aguilar", "Michael Weibel", "Alexey Zhuchkov", "Satyam Shekhar"]
 ,"licenses": [{ "type": "MIT" }]
 ,"engines": { "node": ">=0.4" }
 }
diff --git a/test.js b/test.js
index 6b5a2dd..8b28781 100644
--- a/test.js
+++ b/test.js
@@ -22,9 +22,13 @@ function collapseTexts(evs) {
 }
 
 function expect(s, evs_expected) {
-    for(var step = s.length; step > 0; step--) {
+  for(var step = s.length; step > 0; step--) {
+    expectWithParserAndStep(s, evs_expected, new expat.Parser("UTF-8"), step);
+  }
+}
+
+function expectWithParserAndStep(s, evs_expected, p, step) {
 	var evs_received = [];
-	var p = new expat.Parser("UTF-8");
 	//p.setEncoding("UTF-8");
 	p.addListener('startElement', function(name, attrs) {
 	    evs_received.push(['startElement', name, attrs]);
@@ -66,7 +70,6 @@ function expect(s, evs_expected) {
 	var expected = JSON.stringify(evs_expected);
 	var received = JSON.stringify(collapseTexts(evs_received));
 	assert.equal(received, expected);
-    }
 }
 
 vows.describe('node-expat').addBatch({
@@ -170,6 +173,27 @@ vows.describe('node-expat').addBatch({
 	    expect("<&", [['error']]);
 	}
     },
+
+    'reset': {
+  'complete doc without error': function() {
+	    var p = new expat.Parser("UTF-8");
+	    expectWithParserAndStep("<start><first /><second>text</second></start>", [['startElement', 'start', {}], ['startElement', 'first', {}],  ['endElement', 'first'],  ['startElement', 'second', {}], ['text', "text"], ['endElement', 'second'], ['endElement', 'start']], 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);
+  },
+  'incomplete doc without error': function() {
+      var p = new expat.Parser("UTF-8");
+	    expectWithParserAndStep("<start><first /><second>text</second>", [['startElement', 'start', {}], ['startElement', 'first', {}],  ['endElement', 'first'],  ['startElement', 'second', {}], ['text', "text"], ['endElement', 'second']], 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);     
+  },
+  'with doc error': function() {
+	    var p = new expat.Parser("UTF-8");
+	    expectWithParserAndStep("</end>", [["error"]], 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);
+  }
+    },
     'stop and resume': {
 	topic: function() {
 	    var cb = this.callback;

-- 
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