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

Commit

Permalink
buffer: fix map and set parent to undefined
Browse files Browse the repository at this point in the history
In 4c9b30d removal of the prototype attributes meant NativeBuffer() no
longer had the same object map as Buffer(). By now setting the same
properties in the same order both constructors will produce the same
map.

The same commit changed "parent" from undefined to null. This caused a
failure in Buffer#slice() where it was checked if parent === undefined.
Causing the incorrect parent to be set.

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
  • Loading branch information
trevnorris committed Sep 24, 2014
1 parent 7fd35e6 commit 7c3c51b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Buffer(subject, encoding) {
'size: 0x' + kMaxLength.toString(16) + ' bytes');
}

this.parent = null;
this.parent = undefined;
if (this.length <= (Buffer.poolSize >>> 1) && this.length > 0) {
if (this.length > poolSize - poolOffset)
createPool();
Expand Down Expand Up @@ -118,7 +118,9 @@ function SlowBuffer(length) {
// Objects created in C++. Significantly faster than calling the Buffer
// function.
function NativeBuffer(length) {
this.length = length;
this.length = length >>> 0;
// Set this to keep the object map the same.
this.parent = undefined;
}
NativeBuffer.prototype = Buffer.prototype;

Expand Down

1 comment on commit 7c3c51b

@kennyluck
Copy link

Choose a reason for hiding this comment

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

Oops. I missed this...... I guess I just copied the code from our internal blog so I'll blame @JacksonTian for this. ;) Thanks for the fix!

Please sign in to comment.