| 5 | |
| 6 | #[test] |
| 7 | fn test_invoke_func_via_table() -> Result<()> { |
| 8 | let mut store = Store::<()>::default(); |
| 9 | |
| 10 | let wat = r#" |
| 11 | (module |
| 12 | (func $f (result i64) (i64.const 42)) |
| 13 | |
| 14 | (table (export "table") 1 1 funcref) |
| 15 | (elem (i32.const 0) $f) |
| 16 | ) |
| 17 | "#; |
| 18 | let module = Module::new(store.engine(), wat).context("> Error compiling module!")?; |
| 19 | let instance = |
| 20 | Instance::new(&mut store, &module, &[]).context("> Error instantiating module!")?; |
| 21 | |
| 22 | let f = *instance |
| 23 | .get_table(&mut store, "table") |
| 24 | .unwrap() |
| 25 | .get(&mut store, 0) |
| 26 | .unwrap() |
| 27 | .unwrap_func() |
| 28 | .unwrap(); |
| 29 | let mut results = [Val::I32(0)]; |
| 30 | f.call(&mut store, &[], &mut results).unwrap(); |
| 31 | assert_eq!(results[0].unwrap_i64(), 42); |
| 32 | Ok(()) |
| 33 | } |