forked from PKU-ASAL/PKUWA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstance.rs
More file actions
57 lines (51 loc) · 1.6 KB
/
instance.rs
File metadata and controls
57 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use anyhow::Result;
use wasmtime::component::*;
use wasmtime::{Module, Store};
#[test]
fn instance_exports() -> Result<()> {
let engine = super::engine();
let component = r#"
(component
(import "a" (instance $i))
(import "b" (instance $i2 (export "m" (core module))))
(alias export $i2 "m" (core module $m))
(component $c
(component $c
(export "m" (core module $m))
)
(instance $c (instantiate $c))
(export "i" (instance $c))
)
(instance $c (instantiate $c))
(export "i" (instance $c))
(export "r" (instance $i))
(export "r2" (instance $i2))
)
"#;
let component = Component::new(&engine, component)?;
let mut store = Store::new(&engine, ());
let mut linker = Linker::new(&engine);
linker.instance("a")?;
linker
.instance("b")?
.module("m", &Module::new(&engine, "(module)")?)?;
let instance = linker.instantiate(&mut store, &component)?;
let mut exports = instance.exports(&mut store);
assert!(exports.instance("not an instance").is_none());
let mut i = exports.instance("r").unwrap();
assert!(i.func("x").is_none());
drop(i);
exports.root().instance("i").unwrap();
let mut i2 = exports.instance("r2").unwrap();
assert!(i2.func("m").is_none());
assert!(i2.module("m").is_some());
drop(i2);
exports
.instance("i")
.unwrap()
.instance("i")
.unwrap()
.module("m")
.unwrap();
Ok(())
}