diff --git a/src/node_buffer.cc b/src/node_buffer.cc index a809ae96d5..599c83b6de 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -156,6 +156,16 @@ Buffer* Buffer::New(size_t size) { Handle Buffer::New(const Arguments &args) { HandleScope scope; + if (!args.IsConstructCall()) { + Local argv[10]; + for (int i = 0; i < MIN(args.Length(), 10); i++) { + argv[i] = args[i]; + } + Local instance = + constructor_template->GetFunction()->NewInstance(args.Length(), argv); + return scope.Close(instance); + } + Buffer *buffer; if (args[0]->IsInt32()) { // var buffer = new Buffer(1024); diff --git a/test/simple/test-buffer.js b/test/simple/test-buffer.js index c6e6cc5ec6..7a3f1549d9 100644 --- a/test/simple/test-buffer.js +++ b/test/simple/test-buffer.js @@ -4,7 +4,7 @@ assert = require("assert"); var Buffer = require('buffer').Buffer; -var b = new Buffer(1024); +var b = Buffer(1024); // safe constructor console.log("b.length == " + b.length); assert.strictEqual(1024, b.length);