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

Function call_wrapped_func

tests/all/component_model/call_hook.rs:13–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11// Crate a synchronous Func, call it directly:
12#[test]
13fn call_wrapped_func() -> Result<()> {
14 let wat = r#"
15 (component
16 (import "f" (func $f))
17
18 (core func $f_lower
19 (canon lower (func $f))
20 )
21 (core module $m
22 (import "" "" (func $f))
23
24 (func $export
25 (call $f)
26 )
27
28 (export "export" (func $export))
29 )
30 (core instance $i (instantiate $m
31 (with "" (instance
32 (export "" (func $f_lower))
33 ))
34 ))
35 (func (export "export")
36 (canon lift
37 (core func $i "export")
38 )
39 )
40 )
41 "#;
42
43 let engine = Engine::default();
44 let component = Component::new(&engine, wat)?;
45
46 let mut linker = Linker::<State>::new(&engine);
47 linker
48 .root()
49 .func_wrap("f", |_, _: ()| -> Result<()> { Ok(()) })?;
50
51 let mut store = Store::new(&engine, State::default());
52 store.call_hook(sync_call_hook);
53 let inst = linker
54 .instantiate(&mut store, &component)
55 .expect("instantiate");
56
57 let export = inst
58 .get_typed_func::<(), ()>(&mut store, "export")
59 .expect("looking up `export`");
60
61 export.call(&mut store, ())?;
62
63 let s = store.into_data();
64 assert_eq!(s.calls_into_host, 1);
65 assert_eq!(s.returns_from_host, 1);
66 assert_eq!(s.calls_into_wasm, 1);
67 assert_eq!(s.returns_from_wasm, 1);
68
69 Ok(())
70}

Callers

nothing calls this directly

Calls 9

OkFunction · 0.85
into_dataMethod · 0.80
newFunction · 0.50
func_wrapMethod · 0.45
rootMethod · 0.45
call_hookMethod · 0.45
expectMethod · 0.45
instantiateMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected