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

Function can_put_funcrefs_in_structs

tests/all/structs.rs:703–730  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

701
702#[test]
703fn can_put_funcrefs_in_structs() -> Result<()> {
704 let mut store = gc_store()?;
705
706 let struct_ty = StructType::new(
707 store.engine(),
708 [FieldType::new(Mutability::Var, RefType::FUNCREF.into())],
709 )?;
710
711 let f0 = Func::wrap(&mut store, |_caller: Caller<()>| -> u32 { 0x1234 });
712 let f1 = Func::wrap(&mut store, |_caller: Caller<()>| -> u32 { 0x5678 });
713
714 let pre = StructRefPre::new(&mut store, struct_ty.clone());
715 let s = StructRef::new(&mut store, &pre, &[f0.into()])?;
716
717 let f = s.field(&mut store, 0)?;
718 let f = f.unwrap_funcref().unwrap();
719 let f = f.typed::<(), u32>(&store)?;
720 assert_eq!(f.call(&mut store, ())?, 0x1234);
721
722 s.set_field(&mut store, 0, f1.into())?;
723
724 let f = s.field(&mut store, 0)?;
725 let f = f.unwrap_funcref().unwrap();
726 let f = f.typed::<(), u32>(&store)?;
727 assert_eq!(f.call(&mut store, ())?, 0x5678);
728
729 Ok(())
730}
731
732#[test]
733#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 9

gc_storeFunction · 0.85
OkFunction · 0.85
unwrap_funcrefMethod · 0.80
newFunction · 0.50
engineMethod · 0.45
cloneMethod · 0.45
fieldMethod · 0.45
unwrapMethod · 0.45
set_fieldMethod · 0.45

Tested by

no test coverage detected