|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | const binding = process.binding('buffer'); |
5 | | -const { isArrayBuffer } = process.binding('util'); |
| 5 | +const { isArrayBuffer, isSharedArrayBuffer } = process.binding('util'); |
6 | 6 | const bindingObj = {}; |
7 | 7 | const internalUtil = require('internal/util'); |
8 | 8 |
|
@@ -103,7 +103,7 @@ Buffer.from = function(value, encodingOrOffset, length) { |
103 | 103 | if (typeof value === 'number') |
104 | 104 | throw new TypeError('"value" argument must not be a number'); |
105 | 105 |
|
106 | | - if (isArrayBuffer(value)) |
| 106 | + if (isArrayBuffer(value) || isSharedArrayBuffer(value)) |
107 | 107 | return fromArrayBuffer(value, encodingOrOffset, length); |
108 | 108 |
|
109 | 109 | if (typeof value === 'string') |
@@ -264,7 +264,8 @@ function fromObject(obj) { |
264 | 264 | } |
265 | 265 |
|
266 | 266 | if (obj) { |
267 | | - if (isArrayBuffer(obj.buffer) || 'length' in obj) { |
| 267 | + if (isArrayBuffer(obj.buffer) || 'length' in obj || |
| 268 | + isSharedArrayBuffer(obj)) { |
268 | 269 | if (typeof obj.length !== 'number' || obj.length !== obj.length) { |
269 | 270 | return new FastBuffer(); |
270 | 271 | } |
@@ -351,8 +352,10 @@ function base64ByteLength(str, bytes) { |
351 | 352 |
|
352 | 353 | function byteLength(string, encoding) { |
353 | 354 | if (typeof string !== 'string') { |
354 | | - if (ArrayBuffer.isView(string) || isArrayBuffer(string)) |
| 355 | + if (ArrayBuffer.isView(string) || isArrayBuffer(string) || |
| 356 | + isSharedArrayBuffer(string)) { |
355 | 357 | return string.byteLength; |
| 358 | + } |
356 | 359 |
|
357 | 360 | string = '' + string; |
358 | 361 | } |
|
0 commit comments