mirror of https://github.com/nodejs/node.git
Safe Constructor: Buffer
parent
44a287987e
commit
f86ad1693f
|
@ -156,6 +156,16 @@ Buffer* Buffer::New(size_t size) {
|
|||
Handle<Value> Buffer::New(const Arguments &args) {
|
||||
HandleScope scope;
|
||||
|
||||
if (!args.IsConstructCall()) {
|
||||
Local<Value> argv[10];
|
||||
for (int i = 0; i < MIN(args.Length(), 10); i++) {
|
||||
argv[i] = args[i];
|
||||
}
|
||||
Local<Object> instance =
|
||||
constructor_template->GetFunction()->NewInstance(args.Length(), argv);
|
||||
return scope.Close(instance);
|
||||
}
|
||||
|
||||
Buffer *buffer;
|
||||
if (args[0]->IsInt32()) {
|
||||
// var buffer = new Buffer(1024);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue