-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SharedArrayBuffer to Buffer documentation #15489
Closed
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,8 +66,8 @@ differently based on what arguments are provided: | |
memory. | ||
* Passing a string, array, or `Buffer` as the first argument copies the | ||
passed object's data into the `Buffer`. | ||
* Passing an [`ArrayBuffer`] returns a `Buffer` that shares allocated memory with | ||
the given [`ArrayBuffer`]. | ||
* Passing an [`ArrayBuffer`] or a [`SharedArrayBuffer`] returns a `Buffer` that | ||
shares allocated memory with the given array buffer. | ||
|
||
Because the behavior of `new Buffer()` changes significantly based on the type | ||
of value passed as the first argument, applications that do not properly | ||
|
@@ -361,16 +361,16 @@ changes: | |
> [`Buffer.from(arrayBuffer[, byteOffset [, length]])`][`Buffer.from(arrayBuffer)`] | ||
> instead. | ||
|
||
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a | ||
[`TypedArray`]. | ||
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`] or the | ||
`.buffer` property of a [`TypedArray`]. | ||
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0` | ||
* `length` {integer} Number of bytes to expose. | ||
**Default:** `arrayBuffer.length - byteOffset` | ||
|
||
This creates a view of the [`ArrayBuffer`] without copying the underlying | ||
memory. For example, when passed a reference to the `.buffer` property of a | ||
[`TypedArray`] instance, the newly created `Buffer` will share the same | ||
allocated memory as the [`TypedArray`]. | ||
This creates a view of the [`ArrayBuffer`] or [`SharedArrayBuffer`] without | ||
copying the underlying memory. For example, when passed a reference to the | ||
`.buffer` property of a [`TypedArray`] instance, the newly created `Buffer` will | ||
share the same allocated memory as the [`TypedArray`]. | ||
|
||
The optional `byteOffset` and `length` arguments specify a memory range within | ||
the `arrayBuffer` that will be shared by the `Buffer`. | ||
|
@@ -703,8 +703,8 @@ console.log(`${str}: ${str.length} characters, ` + | |
`${Buffer.byteLength(str, 'utf8')} bytes`); | ||
``` | ||
|
||
When `string` is a `Buffer`/[`DataView`]/[`TypedArray`]/[`ArrayBuffer`], the | ||
actual byte length is returned. | ||
When `string` is a `Buffer`/[`DataView`]/[`TypedArray`]/[`ArrayBuffer`]/ | ||
[`SharedArrayBuffer`], the actual byte length is returned. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
|
||
### Class Method: Buffer.compare(buf1, buf2) | ||
<!-- YAML | ||
|
@@ -807,8 +807,8 @@ A `TypeError` will be thrown if `array` is not an `Array`. | |
added: v5.10.0 | ||
--> | ||
|
||
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`] or the `.buffer` property of a | ||
[`TypedArray`]. | ||
* `arrayBuffer` {ArrayBuffer} An [`ArrayBuffer`], [`SharedArrayBuffer`], or the | ||
`.buffer` property of a [`TypedArray`]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
* `byteOffset` {integer} Index of first byte to expose. **Default:** `0` | ||
* `length` {integer} Number of bytes to expose. | ||
**Default:** `arrayBuffer.length - byteOffset` | ||
|
@@ -852,7 +852,8 @@ const buf = Buffer.from(ab, 0, 2); | |
console.log(buf.length); | ||
``` | ||
|
||
A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`]. | ||
A `TypeError` will be thrown if `arrayBuffer` is not an [`ArrayBuffer`] or a | ||
[`SharedArrayBuffer`]. | ||
|
||
### Class Method: Buffer.from(buffer) | ||
<!-- YAML | ||
|
@@ -2713,6 +2714,7 @@ This value may depend on the JS engine that is being used. | |
[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView | ||
[`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify | ||
[`RangeError`]: errors.html#errors_class_rangeerror | ||
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer | ||
[`String#indexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf | ||
[`String#lastIndexOf()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf | ||
[`String.prototype.length`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change
{ArrayBuffer}
to{ArrayBuffer|SharedArrayBuffer}
as well?