Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/tests/all/invoke_func_via_table.rs
1692 views
1
#![cfg(not(miri))]
2
3
use anyhow::Context as _;
4
use wasmtime::*;
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
}
34
35