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

Function wasm_sets_array_in_table

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

Source from the content-addressed store, hash-verified

778#[test]
779#[cfg_attr(miri, ignore)]
780fn wasm_sets_array_in_table() -> Result<()> {
781 let mut store = gc_store()?;
782
783 let module = Module::new(
784 store.engine(),
785 r#"
786 (module
787 (type (array i8))
788 (table $t (export "t") 1 1 (ref null 0) (ref.null 0))
789 (func (export "get") (result (ref null 0))
790 i32.const 0
791 table.get $t
792 )
793 (func (export "set") (param (ref null 0))
794 i32.const 0
795 local.get 0
796 table.set $t
797 )
798 )
799 "#,
800 )?;
801
802 let array_ty = ArrayType::new(
803 store.engine(),
804 FieldType::new(Mutability::Const, StorageType::I8),
805 );
806 let pre = ArrayRefPre::new(&mut store, array_ty.clone());
807 let a0 = ArrayRef::new_fixed(&mut store, &pre, &[Val::I32(42)])?;
808
809 let instance = Instance::new(&mut store, &module, &[])?;
810 let set = instance.get_func(&mut store, "set").unwrap();
811 set.call(&mut store, &[a0.into()], &mut [])?;
812
813 // Get the global from the host.
814 let t = instance.get_table(&mut store, "t").unwrap();
815 let val = t.get(&mut store, 0).expect("in bounds");
816 let anyref = val.unwrap_any().expect("non-null");
817 let a1 = anyref.unwrap_array(&store)?;
818 assert_eq!(a1.len(&mut store)?, 1);
819 assert_eq!(a1.get(&mut store, 0)?.unwrap_i32(), 42);
820 assert!(Rooted::ref_eq(&store, &a0, &a1)?);
821
822 // Get the global from the guest.
823 let f = instance.get_typed_func::<(), Option<Rooted<ArrayRef>>>(&mut store, "get")?;
824 let a2 = f.call(&mut store, ())?.expect("non-null");
825 assert_eq!(a2.len(&mut store)?, 1);
826 assert_eq!(a2.get(&mut store, 0)?.unwrap_i32(), 42);
827 assert!(Rooted::ref_eq(&store, &a0, &a2)?);
828
829 Ok(())
830}
831
832#[test]
833fn instantiate_with_array_global() -> Result<()> {

Callers

nothing calls this directly

Calls 13

gc_storeFunction · 0.85
OkFunction · 0.85
unwrap_anyMethod · 0.80
newFunction · 0.50
engineMethod · 0.45
cloneMethod · 0.45
unwrapMethod · 0.45
get_funcMethod · 0.45
callMethod · 0.45
get_tableMethod · 0.45
expectMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected