[Pkg-javascript-commits] [node-expat] 71/371: implement entityDecl event + test
Jonas Smedegaard
dr at jones.dk
Sun Feb 28 09:59:46 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 c9162d03aea606c0001db50d67e5478accc2a54a
Author: Astro <astro at spaceboyz.net>
Date: Fri Jun 10 00:20:00 2011 +0200
implement entityDecl event + test
---
node-expat.cc | 22 +++++++++++++++++++++-
test.js | 10 ++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/node-expat.cc b/node-expat.cc
index 9917043..59194a5 100644
--- a/node-expat.cc
+++ b/node-expat.cc
@@ -12,7 +12,7 @@ using namespace node;
static Persistent<String> sym_startElement, sym_endElement,
sym_startCdata, sym_endCdata,
sym_text, sym_processingInstruction,
- sym_comment, sym_xmlDecl;
+ sym_comment, sym_xmlDecl, sym_entityDecl;
class Parser : public EventEmitter {
public:
@@ -40,6 +40,7 @@ public:
sym_processingInstruction = NODE_PSYMBOL("processingInstruction");
sym_comment = NODE_PSYMBOL("comment");
sym_xmlDecl = NODE_PSYMBOL("xmlDecl");
+ sym_entityDecl = NODE_PSYMBOL("entityDecl");
}
protected:
@@ -75,6 +76,7 @@ protected:
XML_SetProcessingInstructionHandler(parser, ProcessingInstruction);
XML_SetCommentHandler(parser, Comment);
XML_SetXmlDeclHandler(parser, XmlDecl);
+ XML_SetEntityDeclHandler(parser, EntityDecl);
}
~Parser()
@@ -328,6 +330,24 @@ private:
Boolean::New(standalone) };
parser->Emit(sym_xmlDecl, 3, argv);
}
+
+ static void EntityDecl(void *userData, const XML_Char *entityName, int is_parameter_entity,
+ const XML_Char *value, int value_length, const XML_Char *base,
+ const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName)
+ {
+ Parser *parser = reinterpret_cast<Parser *>(userData);
+
+ /* Trigger event */
+ Handle<Value> argv[7] = { entityName ? String::New(entityName) : Null(),
+ Boolean::New(is_parameter_entity),
+ value ? String::New(value) : Null(),
+ base ? String::New(base) : Null(),
+ systemId ? String::New(systemId) : Null(),
+ publicId ? String::New(publicId) : Null(),
+ notationName ? String::New(notationName) : Null(),
+ };
+ parser->Emit(sym_entityDecl, 7, argv);
+ }
};
diff --git a/test.js b/test.js
index 8148ab1..94ead47 100644
--- a/test.js
+++ b/test.js
@@ -52,6 +52,9 @@ function expect(s, evs_expected) {
p.addListener('endCdata', function() {
evs_received.push(['endCdata']);
});
+ p.addListener('entityDecl', function(entityName, isParameterEntity, value, base, systemId, publicId, notationName) {
+ evs_received.push(['entityDecl', entityName, isParameterEntity, value, base, systemId, publicId, notationName]);
+ });
for(var l = 0; l < s.length; l += step)
{
var end = l + step;
@@ -203,6 +206,13 @@ expect(new Buffer('<foo><![CDATA[bar]]></foo>'),
['text', 'bar'],
['endCdata'],
['endElement', 'foo']]);
+expect('<!DOCTYPE b [<!ELEMENT b (#PCDATA)>' +
+ '<!ENTITY l0 "ha"><!ENTITY l1 "&l0;&l0;"><!ENTITY l2 "&l1;&l1;">' +
+ ']><b>&l2;</b>',
+ [["entityDecl","l0",false,"ha",null,null,null,null],
+ ["entityDecl","l1",false,"&l0;&l0;",null,null,null,null],
+ ["entityDecl","l2",false,"&l1;&l1;",null,null,null,null],
+ ["startElement","b",{}],["text","hahahaha"],["endElement","b"]]);
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