Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/tests/all/i31ref.rs
1690 views
1
use wasmtime::*;
2
3
#[test]
4
fn always_pop_i31ref_lifo_roots() -> Result<()> {
5
let mut config = Config::new();
6
config.wasm_function_references(true);
7
config.wasm_gc(true);
8
9
let engine = Engine::new(&config)?;
10
let mut store = Store::new(&engine, ());
11
12
let anyref = {
13
let mut scope = RootScope::new(&mut store);
14
AnyRef::from_i31(&mut scope, I31::wrapping_u32(42))
15
};
16
17
// The anyref has left its rooting scope and been unrooted.
18
assert!(anyref.is_i31(&store).is_err());
19
20
Ok(())
21
}
22
23
#[test]
24
fn i31ref_to_raw_round_trip() -> Result<()> {
25
let mut config = Config::new();
26
config.wasm_function_references(true);
27
config.wasm_gc(true);
28
29
let engine = Engine::new(&config)?;
30
let mut store = Store::new(&engine, ());
31
32
// Should be able to round trip an `i31ref` to its raw representation and
33
// back again even though we have not forced the allocation of the `GcStore`
34
// yet.
35
let anyref = AnyRef::from_i31(&mut store, I31::wrapping_u32(42));
36
let raw = anyref.to_raw(&mut store)?;
37
let anyref = AnyRef::from_raw(&mut store, raw).expect("should be non-null");
38
assert!(anyref.is_i31(&store)?);
39
assert_eq!(anyref.as_i31(&store)?.unwrap().get_u32(), 42);
40
41
Ok(())
42
}
43
44