Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
buffer: fix assertion error in WeakCallback
`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: #3080 (comment)
  • Loading branch information
indutny committed Oct 12, 2015
commit 9d4624a39935200bc284ffbbd033e233f6b844bb
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TooTallNate has mentioned how some use a zero-length buffer to keep track of things in their modules. A zero-length buffer would be nullptr. Instead should be like:

if (obj_c.Length() > 0) CHECK_NE(obj_data, nullptr);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to add a test for this case as well.


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