diff options
Diffstat (limited to 'src/node_buffer.cc')
-rw-r--r-- | src/node_buffer.cc | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 14aa3ef612..12fe1e0962 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -171,13 +171,14 @@ Handle<Value> Buffer::New(const Arguments &args) { HandleScope scope; - if (args[0]->IsInt32()) { - // var buffer = new Buffer(1024); - size_t length = args[0]->Uint32Value(); - new Buffer(args.This(), length); - } else { - return ThrowException(Exception::TypeError(String::New("Bad argument"))); + if (!args[0]->IsUint32()) return ThrowTypeError("Bad argument"); + + size_t length = args[0]->Uint32Value(); + if (length > Buffer::kMaxLength) { + return ThrowRangeError("length > kMaxLength"); } + new Buffer(args.This(), length); + return args.This(); } |