js-sys: Add bindings to WebAssembly.Table.prototype.get

Part of #275
This commit is contained in:
Nick Fitzgerald 2018-09-06 14:54:49 -07:00
parent fb5e6e9c06
commit 2d4f36c9da
2 changed files with 10 additions and 0 deletions

View File

@ -3061,6 +3061,13 @@ pub mod WebAssembly {
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
#[wasm_bindgen(method, getter, js_namespace = WebAssembly)] #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
pub fn length(this: &Table) -> u32; 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<Function, JsValue>;
} }
// WebAssembly.Memory // WebAssembly.Memory

View File

@ -127,6 +127,9 @@ fn table_error() {
fn table() { fn table() {
let table = WebAssembly::Table::new(&get_table_object().into()).unwrap(); let table = WebAssembly::Table::new(&get_table_object().into()).unwrap();
assert_eq!(table.length(), 1); assert_eq!(table.length(), 1);
assert!(table.get(0).is_ok());
assert!(table.get(999).is_err());
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]