Skip to content

Commit

Permalink
remove parseFile from SaxParser
Browse files Browse the repository at this point in the history
If you want to parse a file, use the node fs module and then parseString.
  • Loading branch information
defunctzombie committed Dec 20, 2011
1 parent 00712c5 commit 7abb5a0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 60 deletions.
6 changes: 0 additions & 6 deletions lib/sax_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ var SaxParser = function(callbacks) {

// store existing functions because util.inherits overrides the prototype
var parseString = bindings.SaxParser.prototype.parseString;
var parseFile = bindings.SaxParser.prototype.parseFile;

util.inherits(bindings.SaxParser, events.EventEmitter);

bindings.SaxParser.prototype.parseString = parseString;
bindings.SaxParser.prototype.parseFile = parseFile;

var SaxPushParser = function(callbacks) {
var parser = new bindings.SaxPushParser();
Expand All @@ -35,14 +33,10 @@ var SaxPushParser = function(callbacks) {
};

var push = bindings.SaxPushParser.prototype.push;
var parseString = bindings.SaxPushParser.prototype.parseString;
var parseFile = bindings.SaxPushParser.prototype.parseFile;

util.inherits(bindings.SaxPushParser, events.EventEmitter);

bindings.SaxPushParser.prototype.push = push;
bindings.SaxPushParser.prototype.parseString = parseString;
bindings.SaxPushParser.prototype.parseFile = parseFile;

module.exports.SaxParser = SaxParser;
module.exports.SaxPushParser = SaxPushParser;
Expand Down
29 changes: 0 additions & 29 deletions src/xml_sax_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,6 @@ XmlSaxParser::parse_string(const char* str,
releaseContext();
}

v8::Handle<v8::Value>
XmlSaxParser::ParseFile(const v8::Arguments& args) {
v8::HandleScope scope;
LIBXMLJS_ARGUMENT_TYPE_CHECK(args[0],
IsString,
"Bad Argument: parseFile requires a filename");

XmlSaxParser *parser = ObjectWrap::Unwrap<XmlSaxParser>(args.Holder());

v8::String::Utf8Value parsable(args[0]->ToString());
parser->parse_file(*parsable);

// TODO(sprsquish): return based on the parser
return scope.Close(v8::Boolean::New(true));
}

void
XmlSaxParser::parse_file(const char* filename) {
context_ = xmlCreateFileParserCtxt(filename);
parse();
context_->sax = NULL;
releaseContext();
}

void
XmlSaxParser::parse() {
initializeContext();
Expand Down Expand Up @@ -525,14 +501,9 @@ XmlSaxParser::Initialize(v8::Handle<v8::Object> target) {
"parseString",
XmlSaxParser::ParseString);

NODE_SET_PROTOTYPE_METHOD(sax_parser_template,
"parseFile",
XmlSaxParser::ParseFile);

target->Set(v8::String::NewSymbol("SaxParser"),
sax_parser_template->GetFunction());


v8::Local<v8::FunctionTemplate> push_parser_t =
v8::FunctionTemplate::New(NewPushParser);

Expand Down
27 changes: 2 additions & 25 deletions test/xml_sax_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,12 @@ function createParser(parserType, callbacks) {

var filename = __dirname + '/fixtures/sax_parser.xml';

module.exports.sax_push = function(assert) {
module.exports.sax = function(assert) {
var callbacks = clone(callbackTest);
var str = fs.readFileSync(filename, 'utf8');
var parser = createParser('SaxParser', callbacks);
parser.parseString(str);
var control = JSON.stringify(callbackControl);
var test = JSON.stringify(callbacks);
assert.equal(control, test);
assert.deepEqual(callbackControl, callbacks);
assert.done();
};

Expand All @@ -147,16 +145,6 @@ module.exports.sax_push_chunked = function(assert) {

var control = clone(callbackControl);
control.error = [["Extra content at the end of the document\n"]];
assert.equal(JSON.stringify(control), JSON.stringify(callbacks));
assert.done();
};

module.exports.sax = function(assert) {
var callbacks = clone(callbackTest);
var parser = createParser('SaxParser', callbacks);
parser.parseFile(filename);

var control = clone(callbackControl);
assert.deepEqual(control, callbacks);
assert.done();
};
Expand All @@ -175,14 +163,3 @@ module.exports.string_parser = function(assert) {
assert.done();
};

module.exports.file_parser = function(assert) {
var callbacks = clone(callbackTest);
var parser = createParser('SaxParser', callbacks);
for (var i=0; i<10; ++i) {
gc();
parser.parseFile(filename);
}

assert.ok(true);
assert.done();
};

0 comments on commit 7abb5a0

Please sign in to comment.