[Pkg-javascript-commits] [node-expat] 15/371: processingInstruction & comment events
Jonas Smedegaard
dr at jones.dk
Sun Feb 28 09:59:40 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 1eab835cf22ca57d925eaaf10a8a38d349685cc7
Author: Astro <astro at spaceboyz.net>
Date: Sun May 23 16:11:04 2010 +0200
processingInstruction & comment events
---
expat.cc | 28 +++++++++++++++++++++++++++-
test.js | 11 +++++++++--
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/expat.cc b/expat.cc
index 723cf96..292c0f1 100644
--- a/expat.cc
+++ b/expat.cc
@@ -7,7 +7,8 @@ extern "C" {
using namespace v8;
using namespace node;
-static Persistent<String> sym_startElement, sym_endElement, sym_text;
+static Persistent<String> sym_startElement, sym_endElement,
+ sym_text, sym_processingInstruction, sym_comment;
class Parser : public EventEmitter {
public:
@@ -26,6 +27,8 @@ public:
sym_startElement = NODE_PSYMBOL("startElement");
sym_endElement = NODE_PSYMBOL("endElement");
sym_text = NODE_PSYMBOL("text");
+ sym_processingInstruction = NODE_PSYMBOL("processingInstruction");
+ sym_comment = NODE_PSYMBOL("comment");
}
protected:
@@ -48,6 +51,8 @@ protected:
XML_SetUserData(parser, this);
XML_SetElementHandler(parser, StartElement, EndElement);
XML_SetCharacterDataHandler(parser, Text);
+ XML_SetProcessingInstructionHandler(parser, ProcessingInstruction);
+ XML_SetCommentHandler(parser, Comment);
}
~Parser()
@@ -97,6 +102,7 @@ private:
XML_Parser parser;
/*** SAX callbacks ***/
+ /* Should a local HandleScope be used in those callbacks? */
static void StartElement(void *userData,
const XML_Char *name, const XML_Char **atts)
@@ -132,6 +138,26 @@ private:
Handle<Value> argv[1] = { String::New(s, len) };
parser->Emit(sym_text, 1, argv);
}
+
+ static void ProcessingInstruction(void *userData,
+ const XML_Char *target, const XML_Char *data)
+ {
+ Parser *parser = reinterpret_cast<Parser *>(userData);
+
+ /* Trigger event */
+ Handle<Value> argv[2] = { String::New(target), String::New(data) };
+ parser->Emit(sym_processingInstruction, 2, argv);
+ }
+
+ static void Comment(void *userData,
+ const XML_Char *data)
+ {
+ Parser *parser = reinterpret_cast<Parser *>(userData);
+
+ /* Trigger event */
+ Handle<Value> argv[1] = { String::New(data) };
+ parser->Emit(sym_comment, 1, argv);
+ }
};
diff --git a/test.js b/test.js
index 88d9f33..0ba7af1 100644
--- a/test.js
+++ b/test.js
@@ -35,8 +35,11 @@ function expect(s, evs_expected) {
p.addListener('text', function(s) {
evs_received.push(['text', s]);
});
- p.addListener('cdata', function(s) {
- evs_received.push(['cdata', s]);
+ p.addListener('processingInstruction', function(target, data) {
+ evs_received.push(['processingInstruction', target, data]);
+ });
+ p.addListener('comment', function(s) {
+ evs_received.push(['comment', s]);
});
for(var l = 0; l < s.length; l += step)
p.parse(s.substr(l, step), false);
@@ -85,5 +88,9 @@ expect("<r>ß</r>",
[['startElement', 'r', {}],
['text', "ß"],
['endElement', 'r']]);
+expect("<?i like xml?>",
+ [['processingInstruction', 'i', 'like xml']]);
+expect("<!-- no comment -->",
+ [['comment', ' no comment ']]);
sys.puts("Ran "+tests+" tests with "+iterations+" iterations: "+fails+" failures.");
--
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