From 2d4f36c9da85ec27f1a7127b29c86440ffafb7a5 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Thu, 6 Sep 2018 14:54:49 -0700 Subject: [PATCH] js-sys: Add bindings to `WebAssembly.Table.prototype.get` Part of #275 --- crates/js-sys/src/lib.rs | 7 +++++++ crates/js-sys/tests/wasm/WebAssembly.rs | 3 +++ 2 files changed, 10 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 07ffd5a0..d2d5e83d 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -3061,6 +3061,13 @@ pub mod WebAssembly { /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length) #[wasm_bindgen(method, getter, js_namespace = WebAssembly)] pub fn length(this: &Table) -> u32; + + /// The `get()` prototype method of the `WebAssembly.Table()` object + /// retrieves a function reference stored at a given index. + /// + /// [MDN documentation]( + #[wasm_bindgen(method, catch, js_namespace = WebAssembly)] + pub fn get(this: &Table, index: u32) -> Result; } // WebAssembly.Memory diff --git a/crates/js-sys/tests/wasm/WebAssembly.rs b/crates/js-sys/tests/wasm/WebAssembly.rs index e0b10931..d2e42a69 100644 --- a/crates/js-sys/tests/wasm/WebAssembly.rs +++ b/crates/js-sys/tests/wasm/WebAssembly.rs @@ -127,6 +127,9 @@ fn table_error() { fn table() { let table = WebAssembly::Table::new(&get_table_object().into()).unwrap(); assert_eq!(table.length(), 1); + + assert!(table.get(0).is_ok()); + assert!(table.get(999).is_err()); } #[wasm_bindgen_test]