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

Function host_sets_array_in_table

tests/all/arrays.rs:732–776  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

730#[test]
731#[cfg_attr(miri, ignore)]
732fn host_sets_array_in_table() -> Result<()> {
733 let mut store = gc_store()?;
734
735 let module = Module::new(
736 store.engine(),
737 r#"
738 (module
739 (type (array i8))
740 (table $t (export "t") 1 1 (ref null 0) (ref.null 0))
741 (func (export "f") (result (ref null 0))
742 i32.const 0
743 table.get $t
744 )
745 )
746 "#,
747 )?;
748
749 let instance = Instance::new(&mut store, &module, &[])?;
750 let t = instance.get_table(&mut store, "t").unwrap();
751
752 let array_ty = ArrayType::new(
753 store.engine(),
754 FieldType::new(Mutability::Const, StorageType::I8),
755 );
756 let pre = ArrayRefPre::new(&mut store, array_ty.clone());
757 let a0 = ArrayRef::new_fixed(&mut store, &pre, &[Val::I32(42)])?;
758 t.set(&mut store, 0, a0.into())?;
759
760 // Get the global from the host.
761 let val = t.get(&mut store, 0).expect("in bounds");
762 let anyref = val.unwrap_any().expect("non-null");
763 let a1 = anyref.unwrap_array(&store)?;
764 assert_eq!(a1.len(&store)?, 1);
765 assert_eq!(a1.get(&mut store, 0)?.unwrap_i32(), 42);
766 assert!(Rooted::ref_eq(&store, &a0, &a1)?);
767
768 // Get the global from the guest.
769 let f = instance.get_typed_func::<(), Option<Rooted<ArrayRef>>>(&mut store, "f")?;
770 let a2 = f.call(&mut store, ())?.expect("non-null");
771 assert_eq!(a2.len(&store)?, 1);
772 assert_eq!(a2.get(&mut store, 0)?.unwrap_i32(), 42);
773 assert!(Rooted::ref_eq(&store, &a0, &a2)?);
774
775 Ok(())
776}
777
778#[test]
779#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 13

gc_storeFunction · 0.85
OkFunction · 0.85
unwrap_anyMethod · 0.80
newFunction · 0.50
engineMethod · 0.45
unwrapMethod · 0.45
get_tableMethod · 0.45
cloneMethod · 0.45
setMethod · 0.45
expectMethod · 0.45
getMethod · 0.45
unwrap_arrayMethod · 0.45

Tested by

no test coverage detected