Browse Source

buffer: remove Buffer#toArrayBuffer()

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>
archived-io.js-v0.10
Trevor Norris 11 years ago
parent
commit
b1a44dfe9e
  1. 4
      doc/api/buffer.markdown
  2. 22
      src/node_buffer.cc
  3. 12
      test/simple/test-buffer.js

4
doc/api/buffer.markdown

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

22
src/node_buffer.cc

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

12
test/simple/test-buffer.js

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

Loading…
Cancel
Save