()
| 460 | #[test] |
| 461 | #[cfg_attr(miri, ignore)] |
| 462 | fn host_sets_struct_global() -> Result<()> { |
| 463 | let mut store = gc_store()?; |
| 464 | |
| 465 | let module = Module::new( |
| 466 | store.engine(), |
| 467 | r#" |
| 468 | (module |
| 469 | (type (struct (field i8))) |
| 470 | (global $g (export "g") (mut (ref null 0)) (ref.null 0)) |
| 471 | (func (export "f") (result (ref null 0)) |
| 472 | global.get $g |
| 473 | ) |
| 474 | ) |
| 475 | "#, |
| 476 | )?; |
| 477 | |
| 478 | let instance = Instance::new(&mut store, &module, &[])?; |
| 479 | let g = instance.get_global(&mut store, "g").unwrap(); |
| 480 | |
| 481 | let struct_ty = StructType::new( |
| 482 | store.engine(), |
| 483 | [FieldType::new(Mutability::Const, StorageType::I8)], |
| 484 | )?; |
| 485 | let pre = StructRefPre::new(&mut store, struct_ty.clone()); |
| 486 | let s0 = StructRef::new(&mut store, &pre, &[Val::I32(42)])?; |
| 487 | g.set(&mut store, s0.into())?; |
| 488 | |
| 489 | // Get the global from the host. |
| 490 | let val = g.get(&mut store); |
| 491 | let anyref = val.unwrap_anyref().expect("non-null"); |
| 492 | let s1 = anyref.unwrap_struct(&store)?; |
| 493 | assert_eq!(s1.field(&mut store, 0)?.unwrap_i32(), 42); |
| 494 | assert!(Rooted::ref_eq(&store, &s0, &s1)?); |
| 495 | |
| 496 | // Get the global from the guest. |
| 497 | let f = instance.get_typed_func::<(), Option<Rooted<StructRef>>>(&mut store, "f")?; |
| 498 | let s2 = f.call(&mut store, ())?.expect("non-null"); |
| 499 | assert_eq!(s2.field(&mut store, 0)?.unwrap_i32(), 42); |
| 500 | assert!(Rooted::ref_eq(&store, &s0, &s2)?); |
| 501 | |
| 502 | Ok(()) |
| 503 | } |
| 504 | |
| 505 | #[test] |
| 506 | #[cfg_attr(miri, ignore)] |
nothing calls this directly
no test coverage detected