-
Notifications
You must be signed in to change notification settings - Fork 469
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/*** | ||
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)->assertEqual(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)->assertEqual(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 = ArrayBuffer.slice(buffer, ~start=4, ~end=12) | ||
ArrayBuffer.byteLength(sliced)->assertEqual(8) | ||
``` | ||
*/ | ||
@send external slice: (t, ~start: int, ~end: int) => t = "slice" | ||
|
||
/** | ||
`sliceToEnd(arrayBuffer, ~start)` returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from `start` to the end of the buffer. | ||
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 = ArrayBuffer.sliceToEnd(buffer, ~start=8) | ||
ArrayBuffer.byteLength(sliced)->assertEqual(8) | ||
``` | ||
*/ | ||
@send external sliceToEnd: (t, ~start: int) => t = "slice" | ||
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. Just realized: Do we actually need this? Can't we just make Same for Actually So I think we should have the signature @send external slice: (t, ~start: int=?, ~end: int=?) => t = "slice" and deprecate 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. Sounds good! I'll fix. 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. Fixed in 09f1172 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. Thanks a lot! Would you also create PRs for Array, String etc.? |
Uh oh!
There was an error while loading. Please reload this page.