(config: &mut Config)
| 1559 | #[wasmtime_test(wasm_features(reference_types, gc_types))] |
| 1560 | #[cfg_attr(miri, ignore)] |
| 1561 | fn calls_with_funcref_and_externref(config: &mut Config) -> wasmtime::Result<()> { |
| 1562 | let engine = Engine::new(&config)?; |
| 1563 | let mut store = Store::<()>::new(&engine, ()); |
| 1564 | let module = Module::new( |
| 1565 | store.engine(), |
| 1566 | r#" |
| 1567 | (module |
| 1568 | (import "" "witness" (func $witness (param funcref externref))) |
| 1569 | (func (export "f") (param funcref externref) (result externref funcref) |
| 1570 | local.get 0 |
| 1571 | local.get 1 |
| 1572 | call $witness |
| 1573 | local.get 1 |
| 1574 | local.get 0 |
| 1575 | ) |
| 1576 | ) |
| 1577 | |
| 1578 | "#, |
| 1579 | )?; |
| 1580 | let mut linker = Linker::new(store.engine()); |
| 1581 | linker.func_wrap( |
| 1582 | "", |
| 1583 | "witness", |
| 1584 | |mut caller: Caller<'_, ()>, func: Option<Func>, externref: Option<Rooted<ExternRef>>| { |
| 1585 | if func.is_some() { |
| 1586 | assert_my_funcref(&mut caller, func.as_ref())?; |
| 1587 | } |
| 1588 | if externref.is_some() { |
| 1589 | assert_my_externref(&caller, externref); |
| 1590 | } |
| 1591 | Ok(()) |
| 1592 | }, |
| 1593 | )?; |
| 1594 | let instance = linker.instantiate(&mut store, &module)?; |
| 1595 | |
| 1596 | let typed = instance |
| 1597 | .get_typed_func::<(Option<Func>, Option<Rooted<ExternRef>>), (Option<Rooted<ExternRef>>, Option<Func>)>( |
| 1598 | &mut store, "f", |
| 1599 | )?; |
| 1600 | let untyped = typed.func(); |
| 1601 | |
| 1602 | let my_funcref = Func::wrap(&mut store, || 100u32); |
| 1603 | let my_externref = ExternRef::new(&mut store, 99u32)?; |
| 1604 | let mut results = [Val::I32(0), Val::I32(0)]; |
| 1605 | |
| 1606 | fn assert_my_funcref(mut store: impl AsContextMut, func: Option<&Func>) -> Result<()> { |
| 1607 | let mut store = store.as_context_mut(); |
| 1608 | let func = func.unwrap(); |
| 1609 | assert_eq!(func.typed::<(), u32>(&store)?.call(&mut store, ())?, 100); |
| 1610 | Ok(()) |
| 1611 | } |
| 1612 | fn assert_my_externref(store: impl AsContext, externref: Option<Rooted<ExternRef>>) { |
| 1613 | assert_eq!( |
| 1614 | externref |
| 1615 | .unwrap() |
| 1616 | .data(&store) |
| 1617 | .unwrap() |
| 1618 | .unwrap() |
nothing calls this directly
no test coverage detected