Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
buffer: remove Buffer#toArrayBuffer()
Browse files Browse the repository at this point in the history
A recent change to v8's API now makes it impossible to memcpy to a
v8::ArrayBuffer without causing it to be externalized. This means that
the garbage collector will not automatically free the memory when the
object is collected.

When/If the necessary API is included to allow the above
Buffer#toArrayBuffer() will be reintroduced.

Signed-off-by: Timothy J Fontaine <tjfontaine@gmail.com>
  • Loading branch information
trevnorris committed May 12, 2014
1 parent e1aa066 commit b1a44df
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 38 deletions.
4 changes: 0 additions & 4 deletions doc/api/buffer.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,6 @@ buffer.
var b = new Buffer(50);
b.fill("h");

### buf.toArrayBuffer()

Creates a new `ArrayBuffer` with the copied memory of the buffer instance.

## buffer.INSPECT_MAX_BYTES

* Number, Default: 50
Expand Down
22 changes: 0 additions & 22 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,26 +572,6 @@ void WriteDoubleBE(const FunctionCallbackInfo<Value>& args) {
}


void ToArrayBuffer(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());

ARGS_THIS(args.This());
void* adata = malloc(obj_length);

if (adata == NULL) {
FatalError("node::Buffer::ToArrayBuffer("
"const FunctionCallbackInfo<v8::Value>&)",
"Out Of Memory");
}

memcpy(adata, obj_data, obj_length);

Local<ArrayBuffer> abuf = ArrayBuffer::New(env->isolate(), adata, obj_length);
args.GetReturnValue().Set(abuf);
}


void ByteLength(const FunctionCallbackInfo<Value> &args) {
Environment* env = Environment::GetCurrent(args.GetIsolate());
HandleScope scope(env->isolate());
Expand Down Expand Up @@ -679,8 +659,6 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
NODE_SET_METHOD(proto, "writeFloatBE", WriteFloatBE);
NODE_SET_METHOD(proto, "writeFloatLE", WriteFloatLE);

NODE_SET_METHOD(proto, "toArrayBuffer", ToArrayBuffer);

NODE_SET_METHOD(proto, "copy", Copy);
NODE_SET_METHOD(proto, "fill", Fill);

Expand Down
12 changes: 0 additions & 12 deletions test/simple/test-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,18 +1006,6 @@ assert.throws(function() {
}
})();

// Test Buffers to ArrayBuffers
var b = new Buffer(5).fill('abcdf');
var c = b.toArrayBuffer();
assert.equal(c.byteLength, 5);
assert.equal(Object.prototype.toString.call(c), '[object ArrayBuffer]');
var d = new Uint8Array(c);
for (var i = 0; i < 5; i++)
assert.equal(d[i], b[i]);
b.fill('ghijk');
for (var i = 0; i < 5; i++)
assert.notEqual(d[i], b[i]);


assert.throws(function () {
new Buffer(smalloc.kMaxLength + 1);
Expand Down

0 comments on commit b1a44df

Please sign in to comment.