buffer: expose underlying buffer object always

If the Buffer object's length is zero, or equal to the underlying
buffer object's length, `parent` property returns `undefined`.

    > new Buffer(0).parent
    undefined
    > new Buffer(Buffer.poolSize).parent
    undefined

This patch makes the buffer objects to consistently expose the buffer
object via the `parent` property, always.

Fixes: https://github.com/nodejs/node/issues/8266
PR-URL: https://github.com/nodejs/node/pull/8311
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Sakthipriyan Vairamani 2016-08-28 21:21:23 +05:30 committed by Anna Henningsen
parent e9b6fbbf17
commit c21458a15d
No known key found for this signature in database
GPG key ID: D8B9F5AEAE84E4CF
4 changed files with 25 additions and 8 deletions

View file

@ -13,9 +13,7 @@ const buf = Buffer.from(ab);
assert.ok(buf instanceof Buffer);
// For backwards compatibility of old .parent property test that if buf is not
// a slice then .parent should be undefined.
assert.equal(buf.parent, undefined);
assert.equal(buf.parent, buf.buffer);
assert.equal(buf.buffer, ab);
assert.equal(buf.length, ab.byteLength);