-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #8266 PR-URL: #8311 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
e9b6fbb
commit c21458a
Showing
4 changed files
with
25 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
/* | ||
* Fix for https://github.com/nodejs/node/issues/8266 | ||
* | ||
* Zero length Buffer objects should expose the `buffer` property of the | ||
* TypedArrays, via the `parent` property. | ||
*/ | ||
require('../common'); | ||
const assert = require('assert'); | ||
|
||
// If the length of the buffer object is zero | ||
assert((new Buffer(0)).parent instanceof ArrayBuffer); | ||
|
||
// If the length of the buffer object is equal to the underlying ArrayBuffer | ||
assert((new Buffer(Buffer.poolSize)).parent instanceof ArrayBuffer); | ||
|
||
// Same as the previous test, but with user created buffer | ||
const arrayBuffer = new ArrayBuffer(0); | ||
assert.strictEqual(new Buffer(arrayBuffer).parent, arrayBuffer); | ||
assert.strictEqual(new Buffer(arrayBuffer).buffer, arrayBuffer); | ||
assert.strictEqual(Buffer.from(arrayBuffer).parent, arrayBuffer); | ||
assert.strictEqual(Buffer.from(arrayBuffer).buffer, arrayBuffer); |