()
| 652 | |
| 653 | #[test] |
| 654 | fn instantiate_with_struct_global() -> Result<()> { |
| 655 | let mut store = gc_store()?; |
| 656 | |
| 657 | let module = Module::new( |
| 658 | store.engine(), |
| 659 | r#" |
| 660 | (module |
| 661 | (type (struct (field i8))) |
| 662 | (import "" "" (global (ref null 0))) |
| 663 | (export "g" (global 0)) |
| 664 | ) |
| 665 | "#, |
| 666 | )?; |
| 667 | |
| 668 | let struct_ty = StructType::new( |
| 669 | store.engine(), |
| 670 | [FieldType::new(Mutability::Const, StorageType::I8)], |
| 671 | )?; |
| 672 | let global_ty = GlobalType::new( |
| 673 | ValType::Ref(RefType::new( |
| 674 | true, |
| 675 | HeapType::ConcreteStruct(struct_ty.clone()), |
| 676 | )), |
| 677 | Mutability::Const, |
| 678 | ); |
| 679 | |
| 680 | // Instantiate with a null-ref global. |
| 681 | let g = Global::new(&mut store, global_ty.clone(), Val::AnyRef(None))?; |
| 682 | let instance = Instance::new(&mut store, &module, &[g.into()])?; |
| 683 | let g = instance.get_global(&mut store, "g").expect("export exists"); |
| 684 | let val = g.get(&mut store); |
| 685 | assert!(val.unwrap_anyref().is_none()); |
| 686 | |
| 687 | // Instantiate with a non-null-ref global. |
| 688 | let pre = StructRefPre::new(&mut store, struct_ty); |
| 689 | let s0 = StructRef::new(&mut store, &pre, &[Val::I32(42)])?; |
| 690 | let g = Global::new(&mut store, global_ty, s0.into())?; |
| 691 | let instance = Instance::new(&mut store, &module, &[g.into()])?; |
| 692 | let g = instance.get_global(&mut store, "g").expect("export exists"); |
| 693 | let val = g.get(&mut store); |
| 694 | let anyref = val.unwrap_anyref().expect("non-null"); |
| 695 | let s1 = anyref.unwrap_struct(&store)?; |
| 696 | assert_eq!(s1.field(&mut store, 0)?.unwrap_i32(), 42); |
| 697 | assert!(Rooted::ref_eq(&store, &s0, &s1)?); |
| 698 | |
| 699 | Ok(()) |
| 700 | } |
| 701 | |
| 702 | #[test] |
| 703 | fn can_put_funcrefs_in_structs() -> Result<()> { |
nothing calls this directly
no test coverage detected