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

Function wasm_dropping_refs

tests/all/gc.rs:98–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96#[test]
97#[cfg_attr(miri, ignore)]
98fn wasm_dropping_refs() -> Result<()> {
99 let (mut store, module) = ref_types_module(
100 false,
101 r#"
102 (module
103 (func (export "drop_ref") (param externref)
104 nop
105 )
106 )
107 "#,
108 )?;
109
110 let instance = Instance::new(&mut store, &module, &[])?;
111 let drop_ref = instance.get_func(&mut store, "drop_ref").unwrap();
112
113 let num_refs_dropped = Arc::new(AtomicUsize::new(0));
114
115 for _ in 0..4096 {
116 let mut scope = RootScope::new(&mut store);
117 let r = ExternRef::new(&mut scope, CountDrops(num_refs_dropped.clone()))?;
118 let args = [Val::ExternRef(Some(r))];
119 drop_ref.call(&mut scope, &args, &mut [])?;
120 }
121
122 // After doing a GC, all the refs should have been dropped.
123 store.gc(None)?;
124 assert_eq!(num_refs_dropped.load(SeqCst), 4096);
125
126 return Ok(());
127}
128
129#[test]
130#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 10

ref_types_moduleFunction · 0.85
OkFunction · 0.85
CountDropsClass · 0.70
newFunction · 0.50
ExternRefClass · 0.50
unwrapMethod · 0.45
get_funcMethod · 0.45
cloneMethod · 0.45
callMethod · 0.45
gcMethod · 0.45

Tested by

no test coverage detected