Skip to content

Bindings for TypedArray subclasses #486

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 2 commits into from
Jul 17, 2018
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
192 changes: 173 additions & 19 deletions src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,6 @@ extern "C" {
pub fn parse_float(text: &str) -> f64;
}

// UInt8Array
#[wasm_bindgen]
extern "C" {
pub type Uint8Array;

/// The `Uint8Array()` constructor creates an array of unsigned 8-bit integers.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Uint8Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Uint8Array, value: JsValue, start: u32, end: u32) -> Uint8Array;
}

// Array
#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -590,6 +571,44 @@ extern "C" {
pub fn to_string(this: &Error) -> JsString;
}

// Float32Array
#[wasm_bindgen]
extern "C" {
pub type Float32Array;

/// The `Float32Array()` constructor creates an array of 32-bit floats.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Float32Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Float32Array, value: f32, start: u32, end: u32) -> Float32Array;
}

// Float64Array
#[wasm_bindgen]
extern "C" {
pub type Float64Array;

/// The `Float64Array()` constructor creates an array of 64-bit floats.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Float64Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Float64Array, value: f64, start: u32, end: u32) -> Float64Array;
}

// Function
#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -671,6 +690,63 @@ extern {
pub fn throw(this: &Generator, error: &Error) -> Result<JsValue, JsValue>;
}

// Int8Array
#[wasm_bindgen]
extern "C" {
pub type Int8Array;

/// The `Int8Array()` constructor creates an array of signed 8-bit integers.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Int8Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Int8Array, value: i8, start: u32, end: u32) -> Int8Array;
}

// Int16Array
#[wasm_bindgen]
extern "C" {
pub type Int16Array;

/// The `Int16Array()` constructor creates an array of signed 16-bit integers.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Int16Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Int16Array, value: i16, start: u32, end: u32) -> Int16Array;
}

// Int32Array
#[wasm_bindgen]
extern "C" {
pub type Int32Array;

/// The `Int32Array()` constructor creates an array of signed 32-bit integers.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Int32Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Int32Array, value: i32, start: u32, end: u32) -> Int32Array;
}

// Map
#[wasm_bindgen]
extern {
Expand Down Expand Up @@ -1737,6 +1813,84 @@ extern {
pub fn values(set: &Set) -> SetIterator;
}

// Uint8Array
#[wasm_bindgen]
extern "C" {
pub type Uint8Array;

/// The `Uint8Array()` constructor creates an array of unsigned 8-bit integers.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Uint8Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Uint8Array, value: u8, start: u32, end: u32) -> Uint8Array;
}

// Uint8ClampedArray
#[wasm_bindgen]
extern "C" {
pub type Uint8ClampedArray;

/// The `Uint8ClampedArray()` constructor creates an array of unsigned 8-bit integers clamped
/// to 0-255; if you specified a value that is out of the range of [0,255], 0 or 255 will be
/// set instead.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Uint8ClampedArray;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Uint8ClampedArray, value: u8, start: u32, end: u32) -> Uint8ClampedArray;
}

// Uint16Array
#[wasm_bindgen]
extern "C" {
pub type Uint16Array;

/// The `Uint16Array()` constructor creates an array of unsigned 16-bit integers.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Uint16Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Uint16Array, value: u16, start: u32, end: u32) -> Uint16Array;
}

// Uint32Array
#[wasm_bindgen]
extern "C" {
pub type Uint32Array;

/// The `Uint32Array()` constructor creates an array of unsigned 32-bit integers.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
#[wasm_bindgen(constructor)]
pub fn new(constructor_arg: JsValue) -> Uint32Array;

/// The fill() method fills all the elements of an array from a start index
/// to an end index with a static value. The end index is not included.
///
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Uint32Array, value: u32, start: u32, end: u32) -> Uint32Array;
}

// WeakMap
#[wasm_bindgen]
extern "C" {
Expand Down
Loading