Skip to content

Docstrings for ArrayBuffer #7594

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

Merged
merged 3 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/artifacts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,9 @@ lib/ocaml/Stdlib_Array.resi
lib/ocaml/Stdlib_ArrayBuffer.cmi
lib/ocaml/Stdlib_ArrayBuffer.cmj
lib/ocaml/Stdlib_ArrayBuffer.cmt
lib/ocaml/Stdlib_ArrayBuffer.cmti
lib/ocaml/Stdlib_ArrayBuffer.res
lib/ocaml/Stdlib_ArrayBuffer.resi
lib/ocaml/Stdlib_AsyncIterator.cmi
lib/ocaml/Stdlib_AsyncIterator.cmj
lib/ocaml/Stdlib_AsyncIterator.cmt
Expand Down
5 changes: 3 additions & 2 deletions runtime/Stdlib_ArrayBuffer.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ type t
@new external make: int => t = "ArrayBuffer"
@get external byteLength: t => int = "byteLength"

@send external slice: (t, ~start: int, ~end: int) => t = "slice"
@send external sliceToEnd: (t, ~start: int) => t = "slice"
@send external slice: (t, ~start: int=?, ~end: int=?) => t = "slice"

@deprecated("Use `slice` instead.") @send external sliceToEnd: (t, ~start: int) => t = "slice"
56 changes: 56 additions & 0 deletions runtime/Stdlib_ArrayBuffer.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/***
Functions for interacting with JavaScript ArrayBuffer.
See: [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
*/

/**
Type representing an ArrayBuffer object used to represent a generic raw binary data buffer.
*/
@notUndefined
type t

/**
`make(length)` creates a new ArrayBuffer with the specified length in bytes.
See [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/ArrayBuffer) on MDN.
## Examples
```rescript
let buffer = ArrayBuffer.make(8)
ArrayBuffer.byteLength(buffer) == 8
```
## Exceptions
- `RangeError`: If `length` is larger than `Number.MAX_SAFE_INTEGER` or negative.
*/
@new external make: int => t = "ArrayBuffer"

/**
`byteLength(arrayBuffer)` returns the size, in bytes, of the ArrayBuffer.
See [`ArrayBuffer.byteLength`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength) on MDN.
## Examples
```rescript
let buffer = ArrayBuffer.make(16)
ArrayBuffer.byteLength(buffer) == 16
```
*/
@get external byteLength: t => int = "byteLength"

/**
`slice(arrayBuffer, ~start, ~end)` returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from `start`, inclusive, up to `end`, exclusive.
See [`ArrayBuffer.slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice) on MDN.
## Examples
```rescript
let buffer = ArrayBuffer.make(16)
let sliced = buffer->ArrayBuffer.slice(~start=4, ~end=12)
ArrayBuffer.byteLength(sliced) == 8
```
*/
@send external slice: (t, ~start: int=?, ~end: int=?) => t = "slice"

@deprecated("Use `slice` instead.") @send external sliceToEnd: (t, ~start: int) => t = "slice"