Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

const binding = process.binding('buffer');
const { isArrayBuffer } = process.binding('util');
const { isArrayBuffer, isSharedArrayBuffer } = process.binding('util');
const bindingObj = {};
const internalUtil = require('internal/util');

Expand Down Expand Up @@ -103,7 +103,7 @@ Buffer.from = function(value, encodingOrOffset, length) {
if (typeof value === 'number')
throw new TypeError('"value" argument must not be a number');

if (isArrayBuffer(value))
if (isArrayBuffer(value) || isSharedArrayBuffer(value))
return fromArrayBuffer(value, encodingOrOffset, length);

if (typeof value === 'string')
Expand Down
1 change: 1 addition & 0 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using v8::Value;

#define VALUE_METHOD_MAP(V) \
V(isArrayBuffer, IsArrayBuffer) \
V(isSharedArrayBuffer, IsSharedArrayBuffer) \
V(isDataView, IsDataView) \
V(isDate, IsDate) \
V(isMap, IsMap) \
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-buffer-sharedarraybuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*global SharedArrayBuffer*/
'use strict';
// Flags: --harmony-sharedarraybuffer

require('../common');
const assert = require('assert');
const Buffer = require('buffer').Buffer;

const sab = new SharedArrayBuffer(24);
const arr = new Uint16Array(sab);
const ar = new Uint16Array(12);
Copy link
Member

Choose a reason for hiding this comment

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

Just a suggestion, maybe it would be more readable to call them arr1 and arr2?

Copy link
Contributor Author

@ojss ojss Sep 13, 2016

Choose a reason for hiding this comment

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

Sure will do that soon. Better readability I guess.

ar[0] = 5000;
arr[0] = 5000;
arr[1] = 4000;
ar[1] = 4000;

var arr_buf = Buffer.from(arr.buffer);
var ar_buf = Buffer.from(ar.buffer);
Copy link
Member

Choose a reason for hiding this comment

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

I think these can be const, too


assert.deepStrictEqual(arr_buf, ar_buf, 0);
Copy link
Member

Choose a reason for hiding this comment

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

You can probably leave the , 0 out here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Being explicit is better when checking for things.

Copy link
Member

@addaleax addaleax Sep 13, 2016

Choose a reason for hiding this comment

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

The 0 is ignored as a false-y message value, I think it’s just a leftover from a strictEqual() that was there before? (edit: totally agreeing, btw)


arr[1] = 6000;
ar[1] = 6000;

assert.deepStrictEqual(arr_buf, ar_buf, 0);