()
| 601 | #[test] |
| 602 | #[cfg_attr(miri, ignore)] |
| 603 | fn wasm_sets_struct_in_table() -> Result<()> { |
| 604 | let mut store = gc_store()?; |
| 605 | |
| 606 | let module = Module::new( |
| 607 | store.engine(), |
| 608 | r#" |
| 609 | (module |
| 610 | (type (struct (field i8))) |
| 611 | (table $t (export "t") 1 1 (ref null 0) (ref.null 0)) |
| 612 | (func (export "get") (result (ref null 0)) |
| 613 | i32.const 0 |
| 614 | table.get $t |
| 615 | ) |
| 616 | (func (export "set") (param (ref null 0)) |
| 617 | i32.const 0 |
| 618 | local.get 0 |
| 619 | table.set $t |
| 620 | ) |
| 621 | ) |
| 622 | "#, |
| 623 | )?; |
| 624 | |
| 625 | let struct_ty = StructType::new( |
| 626 | store.engine(), |
| 627 | [FieldType::new(Mutability::Const, StorageType::I8)], |
| 628 | )?; |
| 629 | let pre = StructRefPre::new(&mut store, struct_ty.clone()); |
| 630 | let s0 = StructRef::new(&mut store, &pre, &[Val::I32(42)])?; |
| 631 | |
| 632 | let instance = Instance::new(&mut store, &module, &[])?; |
| 633 | let set = instance.get_func(&mut store, "set").unwrap(); |
| 634 | set.call(&mut store, &[s0.into()], &mut [])?; |
| 635 | |
| 636 | // Get the global from the host. |
| 637 | let t = instance.get_table(&mut store, "t").unwrap(); |
| 638 | let val = t.get(&mut store, 0).expect("in bounds"); |
| 639 | let anyref = val.unwrap_any().expect("non-null"); |
| 640 | let s1 = anyref.unwrap_struct(&store)?; |
| 641 | assert_eq!(s1.field(&mut store, 0)?.unwrap_i32(), 42); |
| 642 | assert!(Rooted::ref_eq(&store, &s0, &s1)?); |
| 643 | |
| 644 | // Get the global from the guest. |
| 645 | let f = instance.get_typed_func::<(), Option<Rooted<StructRef>>>(&mut store, "get")?; |
| 646 | let s2 = f.call(&mut store, ())?.expect("non-null"); |
| 647 | assert_eq!(s2.field(&mut store, 0)?.unwrap_i32(), 42); |
| 648 | assert!(Rooted::ref_eq(&store, &s0, &s2)?); |
| 649 | |
| 650 | Ok(()) |
| 651 | } |
| 652 | |
| 653 | #[test] |
| 654 | fn instantiate_with_struct_global() -> Result<()> { |
nothing calls this directly
no test coverage detected