()
| 631 | #[test] |
| 632 | #[cfg_attr(miri, ignore)] |
| 633 | fn host_sets_array_global() -> Result<()> { |
| 634 | let mut store = gc_store()?; |
| 635 | |
| 636 | let module = Module::new( |
| 637 | store.engine(), |
| 638 | r#" |
| 639 | (module |
| 640 | (type (array i8)) |
| 641 | (global $g (export "g") (mut (ref null 0)) (ref.null 0)) |
| 642 | (func (export "f") (result (ref null 0)) |
| 643 | global.get $g |
| 644 | ) |
| 645 | ) |
| 646 | "#, |
| 647 | )?; |
| 648 | |
| 649 | let instance = Instance::new(&mut store, &module, &[])?; |
| 650 | let g = instance.get_global(&mut store, "g").unwrap(); |
| 651 | |
| 652 | let array_ty = ArrayType::new( |
| 653 | store.engine(), |
| 654 | FieldType::new(Mutability::Const, StorageType::I8), |
| 655 | ); |
| 656 | let pre = ArrayRefPre::new(&mut store, array_ty.clone()); |
| 657 | let a0 = ArrayRef::new_fixed(&mut store, &pre, &[Val::I32(42)])?; |
| 658 | g.set(&mut store, a0.into())?; |
| 659 | |
| 660 | // Get the global from the host. |
| 661 | let val = g.get(&mut store); |
| 662 | let anyref = val.unwrap_anyref().expect("non-null"); |
| 663 | let a1 = anyref.unwrap_array(&store)?; |
| 664 | assert_eq!(a1.len(&store)?, 1); |
| 665 | assert_eq!(a1.get(&mut store, 0)?.unwrap_i32(), 42); |
| 666 | assert!(Rooted::ref_eq(&store, &a0, &a1)?); |
| 667 | |
| 668 | // Get the global from the guest. |
| 669 | let f = instance.get_typed_func::<(), Option<Rooted<ArrayRef>>>(&mut store, "f")?; |
| 670 | let a2 = f.call(&mut store, ())?.expect("non-null"); |
| 671 | assert_eq!(a2.len(&store)?, 1); |
| 672 | assert_eq!(a2.get(&mut store, 0)?.unwrap_i32(), 42); |
| 673 | assert!(Rooted::ref_eq(&store, &a0, &a2)?); |
| 674 | |
| 675 | Ok(()) |
| 676 | } |
| 677 | |
| 678 | #[test] |
| 679 | #[cfg_attr(miri, ignore)] |
nothing calls this directly
no test coverage detected