Skip to content

Commit

Permalink
buffer: fix assertion error in WeakCallback
Browse files Browse the repository at this point in the history
`CallbackInfo` is now bound to `ArrayBuffer` instance, not `Uint8Array`,
therefore `SPREAD_ARG` will abort with:

    Assertion failed: ((object)->IsUint8Array())

Make changes necessary to migrate it to `ArrayBuffer`.

See: nodejs#3080 (comment)
  • Loading branch information
indutny committed Oct 12, 2015
1 parent 51325c0 commit 9d4624a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ void CallbackInfo::WeakCallback(


void CallbackInfo::WeakCallback(Isolate* isolate, Local<Object> object) {
SPREAD_ARG(object, obj);
CHECK_EQ(obj_offset, 0);
CHECK_EQ(obj_c.ByteLength(), obj_length);
CHECK(object->IsArrayBuffer());
Local<ArrayBuffer> buf = object.As<ArrayBuffer>();
ArrayBuffer::Contents obj_c = buf->GetContents();
char* const obj_data = static_cast<char*>(obj_c.Data());
CHECK_NE(obj_data, nullptr);

obj->Buffer()->Neuter();
buf->Neuter();
callback_(obj_data, hint_);
int64_t change_in_bytes = -static_cast<int64_t>(sizeof(*this));
isolate->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
Expand Down
4 changes: 4 additions & 0 deletions test/addons/buffer-free-callback/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ var buf = binding.alloc();
var slice = buf.slice(32);
buf = null;
binding.check(slice);
slice = null;
gc();
gc();
gc();

0 comments on commit 9d4624a

Please sign in to comment.