()
| 678 | #[test] |
| 679 | #[cfg_attr(miri, ignore)] |
| 680 | fn wasm_sets_array_global() -> Result<()> { |
| 681 | let mut store = gc_store()?; |
| 682 | |
| 683 | let module = Module::new( |
| 684 | store.engine(), |
| 685 | r#" |
| 686 | (module |
| 687 | (type (array i8)) |
| 688 | (global $g (export "g") (mut (ref null 0)) (ref.null 0)) |
| 689 | (func (export "get") (result (ref null 0)) |
| 690 | global.get $g |
| 691 | ) |
| 692 | (func (export "set") (param (ref null 0)) |
| 693 | local.get 0 |
| 694 | global.set $g |
| 695 | ) |
| 696 | ) |
| 697 | "#, |
| 698 | )?; |
| 699 | |
| 700 | let array_ty = ArrayType::new( |
| 701 | store.engine(), |
| 702 | FieldType::new(Mutability::Const, StorageType::I8), |
| 703 | ); |
| 704 | let pre = ArrayRefPre::new(&mut store, array_ty.clone()); |
| 705 | let a0 = ArrayRef::new_fixed(&mut store, &pre, &[Val::I32(42)])?; |
| 706 | |
| 707 | let instance = Instance::new(&mut store, &module, &[])?; |
| 708 | let set = instance.get_func(&mut store, "set").unwrap(); |
| 709 | set.call(&mut store, &[a0.into()], &mut [])?; |
| 710 | |
| 711 | // Get the global from the host. |
| 712 | let g = instance.get_global(&mut store, "g").unwrap(); |
| 713 | let val = g.get(&mut store); |
| 714 | let anyref = val.unwrap_anyref().expect("non-null"); |
| 715 | let a1 = anyref.unwrap_array(&store)?; |
| 716 | assert_eq!(a1.len(&store)?, 1); |
| 717 | assert_eq!(a1.get(&mut store, 0)?.unwrap_i32(), 42); |
| 718 | assert!(Rooted::ref_eq(&store, &a0, &a1)?); |
| 719 | |
| 720 | // Get the global from the guest. |
| 721 | let f = instance.get_typed_func::<(), Option<Rooted<ArrayRef>>>(&mut store, "get")?; |
| 722 | let a2 = f.call(&mut store, ())?.expect("non-null"); |
| 723 | assert_eq!(a2.len(&store)?, 1); |
| 724 | assert_eq!(a2.get(&mut store, 0)?.unwrap_i32(), 42); |
| 725 | assert!(Rooted::ref_eq(&store, &a0, &a2)?); |
| 726 | |
| 727 | Ok(()) |
| 728 | } |
| 729 | |
| 730 | #[test] |
| 731 | #[cfg_attr(miri, ignore)] |
nothing calls this directly
no test coverage detected