Skip to content

Commit

Permalink
parse(): check buffer param and raise TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed May 30, 2010
1 parent 7e87463 commit ada063b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions expat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,21 @@ class Parser : public EventEmitter {
}
else if (args.Length() >= 1 && args[0]->IsObject())
{
/* TODO: is it really a buffer? */
Buffer *buffer = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
return scope.Close(parser->parseBuffer(*buffer, isFinal) ? True() : False());
Local<Object> obj = args[0]->ToObject();
if (Buffer::HasInstance(obj))
{
Buffer *buffer = ObjectWrap::Unwrap<Buffer>(obj);
return scope.Close(parser->parseBuffer(*buffer, isFinal) ? True() : False());
}
else
return ThrowException(
Exception::TypeError(
String::New("Parse buffer must be String or Buffer")));
}
else
return scope.Close(False());
return ThrowException(
Exception::TypeError(
String::New("Parse buffer must be String or Buffer")));
}

/** Parse a v8 String by first writing it to the expat parser's
Expand Down

0 comments on commit ada063b

Please sign in to comment.