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

Function instance_exports

tests/all/component_model/instance.rs:7–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5#[test]
6#[cfg_attr(miri, ignore)]
7fn instance_exports() -> Result<()> {
8 let engine = super::engine();
9 let component = r#"
10 (component
11 (import "a" (instance $i))
12 (import "b" (instance $i2 (export "m" (core module))))
13
14 (alias export $i2 "m" (core module $m))
15
16 (component $c
17 (component $c
18 (export "m" (core module $m))
19 )
20 (instance $c (instantiate $c))
21 (export "i" (instance $c))
22 )
23 (instance $c (instantiate $c))
24 (export "i" (instance $c))
25 (export "r" (instance $i))
26 (export "r2" (instance $i2))
27 )
28 "#;
29 let component = Component::new(&engine, component)?;
30 let mut store = Store::new(&engine, ());
31 let mut linker = Linker::new(&engine);
32 linker.instance("a")?;
33 linker
34 .instance("b")?
35 .module("m", &Module::new(&engine, "(module)")?)?;
36 let instance = linker.instantiate(&mut store, &component)?;
37
38 assert!(
39 instance
40 .get_export(&mut store, None, "not an instance")
41 .is_none()
42 );
43 let i = instance.get_export_index(&mut store, None, "r").unwrap();
44 assert!(instance.get_export(&mut store, Some(&i), "x").is_none());
45 instance.get_export(&mut store, None, "i").unwrap();
46 let i2 = instance.get_export_index(&mut store, None, "r2").unwrap();
47 let m = instance
48 .get_export_index(&mut store, Some(&i2), "m")
49 .unwrap();
50 assert!(instance.get_func(&mut store, &m).is_none());
51 assert!(instance.get_module(&mut store, &m).is_some());
52
53 let i = instance.get_export_index(&mut store, None, "i").unwrap();
54 let i = instance
55 .get_export_index(&mut store, Some(&i), "i")
56 .unwrap();
57 let m = instance
58 .get_export_index(&mut store, Some(&i), "m")
59 .unwrap();
60 instance.get_module(&mut store, &m).unwrap();
61
62 Ok(())
63}
64

Callers

nothing calls this directly

Calls 10

OkFunction · 0.85
engineFunction · 0.50
newFunction · 0.50
instanceMethod · 0.45
moduleMethod · 0.45
instantiateMethod · 0.45
unwrapMethod · 0.45
get_export_indexMethod · 0.45
get_exportMethod · 0.45
get_moduleMethod · 0.45

Tested by

no test coverage detected