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

Function drop_externref_via_table_set

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

Source from the content-addressed store, hash-verified

223#[test]
224#[cfg_attr(miri, ignore)]
225fn drop_externref_via_table_set() -> Result<()> {
226 let (mut store, module) = ref_types_module(
227 false,
228 r#"
229 (module
230 (table $t 1 externref)
231
232 (func (export "table-set") (param externref)
233 (table.set $t (i32.const 0) (local.get 0))
234 )
235 )
236 "#,
237 )?;
238
239 let instance = Instance::new(&mut store, &module, &[])?;
240 let table_set = instance.get_func(&mut store, "table-set").unwrap();
241
242 let foo_is_dropped = Arc::new(AtomicBool::new(false));
243 let bar_is_dropped = Arc::new(AtomicBool::new(false));
244
245 {
246 let mut scope = RootScope::new(&mut store);
247
248 let foo = ExternRef::new(&mut scope, SetFlagOnDrop(foo_is_dropped.clone()))?;
249 let bar = ExternRef::new(&mut scope, SetFlagOnDrop(bar_is_dropped.clone()))?;
250
251 {
252 let args = vec![Val::ExternRef(Some(foo))];
253 table_set.call(&mut scope, &args, &mut [])?;
254 }
255
256 scope.as_context_mut().gc(None)?;
257 assert!(!foo_is_dropped.load(SeqCst));
258 assert!(!bar_is_dropped.load(SeqCst));
259
260 {
261 let args = vec![Val::ExternRef(Some(bar))];
262 table_set.call(&mut scope, &args, &mut [])?;
263 }
264 }
265
266 store.gc(None)?;
267 assert!(foo_is_dropped.load(SeqCst));
268 assert!(!bar_is_dropped.load(SeqCst));
269
270 table_set.call(&mut store, &[Val::ExternRef(None)], &mut [])?;
271 store.gc(None)?;
272 assert!(foo_is_dropped.load(SeqCst));
273 assert!(bar_is_dropped.load(SeqCst));
274
275 Ok(())
276}
277
278#[test]
279#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected