MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / test_invoke_func_via_table

Function test_invoke_func_via_table

tests/all/invoke_func_via_table.rs:7–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5
6#[test]
7fn 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}

Callers

nothing calls this directly

Calls 9

OkFunction · 0.85
newFunction · 0.50
contextMethod · 0.45
engineMethod · 0.45
unwrapMethod · 0.45
unwrap_funcMethod · 0.45
getMethod · 0.45
get_tableMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected