Path: blob/main/tests/all/invoke_func_via_table.rs
1692 views
#![cfg(not(miri))]12use anyhow::Context as _;3use wasmtime::*;45#[test]6fn test_invoke_func_via_table() -> Result<()> {7let mut store = Store::<()>::default();89let wat = r#"10(module11(func $f (result i64) (i64.const 42))1213(table (export "table") 1 1 funcref)14(elem (i32.const 0) $f)15)16"#;17let module = Module::new(store.engine(), wat).context("> Error compiling module!")?;18let instance =19Instance::new(&mut store, &module, &[]).context("> Error instantiating module!")?;2021let f = *instance22.get_table(&mut store, "table")23.unwrap()24.get(&mut store, 0)25.unwrap()26.unwrap_func()27.unwrap();28let mut results = [Val::I32(0)];29f.call(&mut store, &[], &mut results).unwrap();30assert_eq!(results[0].unwrap_i64(), 42);31Ok(())32}333435