Browse Source

Safe Constructor: Buffer

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
f86ad1693f
  1. 10
      src/node_buffer.cc
  2. 2
      test/simple/test-buffer.js

10
src/node_buffer.cc

@ -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);

2
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);

Loading…
Cancel
Save