Skip to content

Commit

Permalink
buffer: fix check for .buffer property
Browse files Browse the repository at this point in the history
isSharedArrayBuffer in fromObject was missing obj.buffer
moved the 'length' in obj check so that it is checked first making
the code slightly more performant and able to handle SharedArrayBuffer
without relying on an explicit check.

Ref: #8510
PR-URL: #8739
Reviewed-By: Ilkka Myller <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
ojss authored and jasnell committed Oct 10, 2016
1 parent 13b4687 commit 58f9b6d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ function fromObject(obj) {
}

if (obj) {
if (isArrayBuffer(obj.buffer) || 'length' in obj ||
isSharedArrayBuffer(obj)) {
if ('length' in obj || isArrayBuffer(obj.buffer) ||
isSharedArrayBuffer(obj.buffer)) {
if (typeof obj.length !== 'number' || obj.length !== obj.length) {
return new FastBuffer();
}
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-buffer-sharedarraybuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ assert.deepStrictEqual(arr_buf, ar_buf, 0);
// Checks for calling Buffer.byteLength on a SharedArrayBuffer

assert.strictEqual(Buffer.byteLength(sab), sab.byteLength, 0);

assert.doesNotThrow(() => Buffer.from({buffer: sab}));

0 comments on commit 58f9b6d

Please sign in to comment.