Skip to content

Commit 2d4f36c

Browse files
committed
js-sys: Add bindings to WebAssembly.Table.prototype.get
Part of rustwasm#275
1 parent fb5e6e9 commit 2d4f36c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

crates/js-sys/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,6 +3061,13 @@ pub mod WebAssembly {
30613061
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
30623062
#[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
30633063
pub fn length(this: &Table) -> u32;
3064+
3065+
/// The `get()` prototype method of the `WebAssembly.Table()` object
3066+
/// retrieves a function reference stored at a given index.
3067+
///
3068+
/// [MDN documentation](
3069+
#[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
3070+
pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
30643071
}
30653072

30663073
// WebAssembly.Memory

crates/js-sys/tests/wasm/WebAssembly.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ fn table_error() {
127127
fn table() {
128128
let table = WebAssembly::Table::new(&get_table_object().into()).unwrap();
129129
assert_eq!(table.length(), 1);
130+
131+
assert!(table.get(0).is_ok());
132+
assert!(table.get(999).is_err());
130133
}
131134

132135
#[wasm_bindgen_test]

0 commit comments

Comments
 (0)