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

Function test_import_calling_export

tests/all/import_calling_export.rs:6–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5#[test]
6fn test_import_calling_export() {
7 const WAT: &str = r#"
8 (module
9 (type $t0 (func))
10 (import "" "imp" (func $.imp (type $t0)))
11 (func $run call $.imp)
12 (func $other)
13 (export "run" (func $run))
14 (export "other" (func $other))
15 )
16 "#;
17
18 let mut store = Store::<Option<Func>>::default();
19 let module = Module::new(store.engine(), WAT).expect("failed to create module");
20
21 let func_ty = FuncType::new(store.engine(), None, None);
22 let callback_func = Func::new(&mut store, func_ty, move |mut caller, _, _| {
23 caller
24 .data()
25 .unwrap()
26 .call(&mut caller, &[], &mut [])
27 .expect("expected function not to trap");
28 Ok(())
29 });
30
31 let imports = vec![callback_func.into()];
32 let instance = Instance::new(&mut store, &module, imports.as_slice())
33 .expect("failed to instantiate module");
34
35 let run_func = instance
36 .get_func(&mut store, "run")
37 .expect("expected a run func in the module");
38
39 let other_func = instance
40 .get_func(&mut store, "other")
41 .expect("expected an other func in the module");
42 *store.data_mut() = Some(other_func);
43
44 run_func
45 .call(&mut store, &[], &mut [])
46 .expect("expected function not to trap");
47}
48
49#[test]
50fn test_returns_incorrect_type() -> Result<()> {

Callers

nothing calls this directly

Calls 10

OkFunction · 0.85
newFunction · 0.50
expectMethod · 0.45
engineMethod · 0.45
callMethod · 0.45
unwrapMethod · 0.45
dataMethod · 0.45
as_sliceMethod · 0.45
get_funcMethod · 0.45
data_mutMethod · 0.45

Tested by

no test coverage detected