Skip to content

Commit e8f6f49

Browse files
authored
README: Document ArrayBuffer.prototype.sliceToImmutable (#45)
1 parent 83479c9 commit e8f6f49

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ w3c machine learning workshop [issue #93](https://github.com/w3c/machine-learnin
7979

8080
## Solution
8181

82-
This proposal introduces additional methods and read-only accessor properties to `ArrayBuffer.prototype` that fit naturally into those explained above. Just as a buffer can be resizable or not, and detached or not, this proposal enables buffers to be immutable or not. Just as `transferToFixedSize` moves the contents of a original buffer into a newly created non-resizable buffer, this proposal provides a transfer operation that moves the contents of an original original buffer into a newly created immutable buffer. Altogether, this proposal only adds to `ArrayBuffer.prototype` one method
83-
- `transferToImmutable(newByteLength?: number) :ArrayBuffer` -- move the contents of the original buffer into a new immutable buffer, detach the original buffer, and return the new buffer.
82+
This proposal introduces additional methods and read-only accessor properties to `ArrayBuffer.prototype` that fit naturally into those explained above. Just as a buffer can be resizable or not, and detached or not, this proposal enables buffers to be immutable or not. Just as `transferToFixedSize` moves the contents of a original buffer into a newly created non-resizable buffer, this proposal provides a transfer operation that moves the contents of an original original buffer into a newly created immutable buffer. Altogether, this proposal only adds to `ArrayBuffer.prototype` one read-only accessor
8483

85-
and one read-only accessor
8684
- `immutable: boolean` -- is this buffer immutable, or can its contents be changed?
8785

86+
and two methods
87+
88+
- `transferToImmutable(newByteLength?: number) :ArrayBuffer` -- move the contents of the original buffer into a new immutable buffer, detach the original buffer, and return the new buffer.
89+
- `sliceToImmutable(start?: number, end?: number) :ArrayBuffer` -- create a new immutable buffer from a range of the original buffer's contents in a way that allows implementations to easily minimize and sometimes even eliminate copying them.
90+
8891
An immutable buffer cannot be detached, resized, or further transferred. Its `maxByteLength` is the same as its `byteLength`. A `DataView` or `TypedArray` using an immutable buffer as its backing store can be frozen and immutable. `ArrayBuffer`s, `DataView`s, and `TypedArray`s that are frozen and immutable could be placed in ROM without going beyond JavaScript's official semantics.
8992

9093
The ArrayBuffer `slice` method and TypedArray methods that create new ArrayBuffers (`filter`, `map`, `slice`, `toReversed`, etc.) make no effort to preserve immutability, just like they make no effort to preserve resizability (although use of SpeciesConstructor in those methods means that _lack_ of resizability/immutability in the result cannot be guaranteed for the latter).

0 commit comments

Comments
 (0)