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