()
| 730 | #[test] |
| 731 | #[cfg_attr(miri, ignore)] |
| 732 | fn 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)] |
nothing calls this directly
no test coverage detected