Skip to content

Commit df5436c

Browse files
ThomasdenHMylesBorins
authored andcommitted
doc: add SharedArrayBuffer to Buffer documentation
PR-URL: #15489 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 8fd316f commit df5436c

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

doc/api/buffer.md

+17-15
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ differently based on what arguments are provided:
6666
memory.
6767
* Passing a string, array, or `Buffer` as the first argument copies the
6868
passed object's data into the `Buffer`.
69-
* Passing an [`ArrayBuffer`] returns a `Buffer` that shares allocated memory with
70-
the given [`ArrayBuffer`].
69+
* Passing an [`ArrayBuffer`] or a [`SharedArrayBuffer`] returns a `Buffer` that
70+
shares allocated memory with the given array buffer.
7171

7272
Because the behavior of `new Buffer()` changes significantly based on the type
7373
of value passed as the first argument, applications that do not properly
@@ -361,16 +361,16 @@ changes:
361361
> [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`]
362362
> instead.
363363
364-
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a
365-
[`TypedArray`].
364+
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`],
365+
[`SharedArrayBuffer`] or the `.buffer` property of a [`TypedArray`].
366366
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`
367367
* `length` {integer} Number of bytes to expose.
368368
**Default:** `arrayBuffer.length - byteOffset`
369369

370-
This creates a view of the [`ArrayBuffer`] without copying the underlying
371-
memory. For example, when passed a reference to the `.buffer` property of a
372-
[`TypedArray`] instance, the newly created `Buffer` will share the same
373-
allocated memory as the [`TypedArray`].
370+
This creates a view of the [`ArrayBuffer`] or [`SharedArrayBuffer`] without
371+
copying the underlying memory. For example, when passed a reference to the
372+
`.buffer` property of a [`TypedArray`] instance, the newly created `Buffer` will
373+
share the same allocated memory as the [`TypedArray`].
374374

375375
The optional `byteOffset` and `length` arguments specify a memory range within
376376
the `arrayBuffer` that will be shared by the `Buffer`.
@@ -684,8 +684,8 @@ changes:
684684
or `ArrayBuffer`.
685685
-->
686686

687-
* `string` {string|Buffer|TypedArray|DataView|ArrayBuffer} A value to
688-
calculate the length of.
687+
* `string` {string|Buffer|TypedArray|DataView|ArrayBuffer|SharedArrayBuffer} A
688+
value to calculate the length of.
689689
* `encoding` {string} If `string` is a string, this is its encoding.
690690
**Default:** `'utf8'`
691691
* Returns: {integer} The number of bytes contained within `string`.
@@ -708,8 +708,8 @@ console.log(`${str}: ${str.length} characters, ` +
708708
`${Buffer.byteLength(str, 'utf8')} bytes`);
709709
```
710710

711-
When `string` is a `Buffer`/[`DataView`]/[`TypedArray`]/[`ArrayBuffer`], the
712-
actual byte length is returned.
711+
When `string` is a `Buffer`/[`DataView`]/[`TypedArray`]/[`ArrayBuffer`]/
712+
[`SharedArrayBuffer`], the actual byte length is returned.
713713

714714
### Class Method: Buffer.compare(buf1, buf2)
715715
<!-- YAML
@@ -812,8 +812,8 @@ A `TypeError` will be thrown if `array` is not an `Array`.
812812
added: v5.10.0
813813
-->
814814

815-
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a
816-
[`TypedArray`].
815+
* `arrayBuffer` {ArrayBuffer|SharedArrayBuffer} An [`ArrayBuffer`],
816+
[`SharedArrayBuffer`], or the `.buffer` property of a [`TypedArray`].
817817
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0`
818818
* `length` {integer} Number of bytes to expose.
819819
**Default:** `arrayBuffer.length - byteOffset`
@@ -857,7 +857,8 @@ const buf = Buffer.from(ab, 0, 2);
857857
console.log(buf.length);
858858
```
859859

860-
A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`].
860+
A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`] or a
861+
[`SharedArrayBuffer`].
861862

862863
### Class Method: Buffer.from(buffer)
863864
<!-- YAML
@@ -2730,6 +2731,7 @@ This value may depend on the JS engine that is being used.
27302731
[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
27312732
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
27322733
[`RangeError`]: errors.html#errors_class_rangeerror
2734+
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
27332735
[`String#indexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
27342736
[`String#lastIndexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf
27352737
[`String.prototype.length`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length

0 commit comments

Comments
 (0)