Skip to content

Commit

Permalink
js-sys: Expose bindings to WebAssembly.Table.prototype.grow
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Sep 6, 2018
1 parent 2d4f36c commit 8dbb0fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/js-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3065,9 +3065,17 @@ pub mod WebAssembly {
/// The `get()` prototype method of the `WebAssembly.Table()` object
/// retrieves a function reference stored at a given index.
///
/// [MDN documentation](
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
#[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;

/// The `grow()` prototype method of the `WebAssembly.Table` object
/// increases the size of the `Table` instance by a specified number of
/// elements.
///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
#[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
}

// WebAssembly.Memory
Expand Down
3 changes: 3 additions & 0 deletions crates/js-sys/tests/wasm/WebAssembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ fn table() {

assert!(table.get(0).is_ok());
assert!(table.get(999).is_err());

table.grow(1).unwrap();
assert_eq!(table.length(), 2);
}

#[wasm_bindgen_test]
Expand Down

0 comments on commit 8dbb0fc

Please sign in to comment.