Permalink
Browse files

expose stop and resume to the nodejs side

  • Loading branch information...
Peter Körner authored and astro committed Apr 8, 2011
1 parent 0b925cb commit 4c7daa649a29c5cf0baa7d408474633590a861c5
Showing with 40 additions and 1 deletion.
  1. +3 −0 README.markdown
  2. +36 −0 node-expat.cc
  3. +1 −1 package.json
View
@@ -33,6 +33,9 @@ Important events emitted by a parser:
There are more. Use `test.js` for reference.
+It's possible to stop and resume the parser from within element handlers using the parsers
+stop() and resume() methods.
+
## Error handling ##
We don't emit an error event because libexpat doesn't use a callback
View
@@ -27,6 +27,8 @@ class Parser : public EventEmitter {
NODE_SET_PROTOTYPE_METHOD(t, "parse", Parse);
NODE_SET_PROTOTYPE_METHOD(t, "setEncoding", SetEncoding);
NODE_SET_PROTOTYPE_METHOD(t, "getError", GetError);
+ NODE_SET_PROTOTYPE_METHOD(t, "stop", Stop);
+ NODE_SET_PROTOTYPE_METHOD(t, "resume", Resume);
target->Set(String::NewSymbol("Parser"), t->GetFunction());
@@ -189,7 +191,41 @@ class Parser : public EventEmitter {
else
return scope.Close(Null());
}
+
+ /*** stop() ***/
+
+ static Handle<Value> Stop(const Arguments& args)
+ {
+ Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
+ HandleScope scope;
+
+ int status = parser->stop();
+
+ return scope.Close(status ? True() : False());
+ }
+
+ int stop()
+ {
+ return XML_StopParser(parser, XML_TRUE) != 0;
+ }
+
+ /*** resume() ***/
+
+ static Handle<Value> Resume(const Arguments& args)
+ {
+ Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
+ HandleScope scope;
+ int status = parser->resume();
+
+ return scope.Close(status ? True() : False());
+ }
+
+ int resume()
+ {
+ return XML_ResumeParser(parser) != 0;
+ }
+
const XML_LChar *getError()
{
enum XML_Error code;
View
@@ -13,7 +13,7 @@
,"email": "astro@spaceboyz.net"
,"web": "http://spaceboyz.net/~astro/"
}]
-,"contributors": ["Stephan Maka", "Derek Hammer", "Iein Valdez"]
+,"contributors": ["Stephan Maka", "Derek Hammer", "Iein Valdez", "Peter Körner"]
,"licenses": [{ "type": "MIT" }]
,"engine": "node"
}

0 comments on commit 4c7daa6

Please sign in to comment.