MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / recursive_async

Function recursive_async

tests/all/async_functions.rs:665–698  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

663#[tokio::test]
664#[cfg_attr(miri, ignore)]
665async fn recursive_async() -> Result<()> {
666 let _ = env_logger::try_init();
667 let mut store = async_store();
668 let m = Module::new(
669 store.engine(),
670 "(module
671 (func (export \"overflow\") call 0)
672 (func (export \"normal\"))
673 )",
674 )?;
675 let i = Instance::new_async(&mut store, &m, &[]).await?;
676 let overflow = i.get_typed_func::<(), ()>(&mut store, "overflow")?;
677 let normal = i.get_typed_func::<(), ()>(&mut store, "normal")?;
678 let f2 = Func::wrap_async(&mut store, move |mut caller, _: ()| {
679 let normal = normal.clone();
680 let overflow = overflow.clone();
681 Box::new(async move {
682 // recursive async calls shouldn't immediately stack overflow...
683 normal.call_async(&mut caller, ()).await?;
684
685 // ... but calls that actually stack overflow should indeed stack
686 // overflow
687 let err = overflow
688 .call_async(&mut caller, ())
689 .await
690 .unwrap_err()
691 .downcast::<Trap>()?;
692 assert_eq!(err, Trap::StackOverflow);
693 Ok(())
694 })
695 });
696 f2.call_async(&mut store, &[], &mut []).await?;
697 Ok(())
698}
699
700#[tokio::test]
701#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 6

OkFunction · 0.85
async_storeFunction · 0.70
newFunction · 0.50
engineMethod · 0.45
cloneMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected