()
| 831 | |
| 832 | #[test] |
| 833 | fn instantiate_with_array_global() -> Result<()> { |
| 834 | let mut store = gc_store()?; |
| 835 | |
| 836 | let module = Module::new( |
| 837 | store.engine(), |
| 838 | r#" |
| 839 | (module |
| 840 | (type (array i8)) |
| 841 | (import "" "" (global (ref null 0))) |
| 842 | (export "g" (global 0)) |
| 843 | ) |
| 844 | "#, |
| 845 | )?; |
| 846 | |
| 847 | let array_ty = ArrayType::new( |
| 848 | store.engine(), |
| 849 | FieldType::new(Mutability::Const, StorageType::I8), |
| 850 | ); |
| 851 | let global_ty = GlobalType::new( |
| 852 | ValType::Ref(RefType::new( |
| 853 | true, |
| 854 | HeapType::ConcreteArray(array_ty.clone()), |
| 855 | )), |
| 856 | Mutability::Const, |
| 857 | ); |
| 858 | |
| 859 | // Instantiate with a null-ref global. |
| 860 | let g = Global::new(&mut store, global_ty.clone(), Val::AnyRef(None))?; |
| 861 | let instance = Instance::new(&mut store, &module, &[g.into()])?; |
| 862 | let g = instance.get_global(&mut store, "g").expect("export exists"); |
| 863 | let val = g.get(&mut store); |
| 864 | assert!(val.unwrap_anyref().is_none()); |
| 865 | |
| 866 | // Instantiate with a non-null-ref global. |
| 867 | let pre = ArrayRefPre::new(&mut store, array_ty); |
| 868 | let a0 = ArrayRef::new_fixed(&mut store, &pre, &[Val::I32(42)])?; |
| 869 | let g = Global::new(&mut store, global_ty, a0.into())?; |
| 870 | let instance = Instance::new(&mut store, &module, &[g.into()])?; |
| 871 | let g = instance.get_global(&mut store, "g").expect("export exists"); |
| 872 | let val = g.get(&mut store); |
| 873 | let anyref = val.unwrap_anyref().expect("non-null"); |
| 874 | let a1 = anyref.unwrap_array(&store)?; |
| 875 | assert_eq!(a1.len(&mut store)?, 1); |
| 876 | assert_eq!(a1.get(&mut store, 0)?.unwrap_i32(), 42); |
| 877 | assert!(Rooted::ref_eq(&store, &a0, &a1)?); |
| 878 | |
| 879 | Ok(()) |
| 880 | } |
| 881 | |
| 882 | #[test] |
| 883 | fn arrayref_to_anyref_rooted() -> Result<()> { |
nothing calls this directly
no test coverage detected