feat(js) Add ArrayBuffer::new, ::is_view & ::slice bindings. (#388)

* feat(js) Add `ArrayBuffer::new`, `::is_view` & `::slice` bindings.

* fix(js) Fix number units, comments, add `slice_with_end`.

* test(js) Fix a function name.
This commit is contained in:
Ivan Enderlin
2018-07-04 20:53:49 +02:00
committed by Alex Crichton
parent ad72ea54a9
commit 43de00b347
3 changed files with 150 additions and 0 deletions

View File

@ -254,6 +254,45 @@ extern "C" {
pub fn unshift(this: &Array, value: JsValue) -> u32;
}
// ArrayBuffer
#[wasm_bindgen]
extern "C" {
pub type ArrayBuffer;
/// The `ArrayBuffer` object is used to represent a generic,
/// fixed-length raw binary data buffer. You cannot directly
/// manipulate the contents of an `ArrayBuffer`; instead, you
/// create one of the typed array objects or a `DataView` object
/// which represents the buffer in a specific format, and use that
/// to read and write the contents of the buffer.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
#[wasm_bindgen(constructor)]
pub fn new(length: u32) -> ArrayBuffer;
/// The `slice()` method returns a new `ArrayBuffer` whose contents
/// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
/// up to end, exclusive.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView
#[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
pub fn is_view(value: JsValue) -> bool;
/// The `slice()` method returns a new `ArrayBuffer` whose contents
/// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
/// up to end, exclusive.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice
#[wasm_bindgen(method)]
pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
/// Like `slice()` but with the `end` argument.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice
#[wasm_bindgen(method, js_name = slice)]
pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
}
// Array Iterator
#[wasm_bindgen]
extern "C" {