()
| 1043 | |
| 1044 | #[tokio::test(flavor = "multi_thread")] |
| 1045 | async fn sync_then_async_trap() -> Result<()> { |
| 1046 | // Test the trapping and capturing the stack with the following sequence of |
| 1047 | // calls: |
| 1048 | // |
| 1049 | // a[sync] ---> b[host] ---> c[async] |
| 1050 | |
| 1051 | drop(env_logger::try_init()); |
| 1052 | |
| 1053 | let wat = r#" |
| 1054 | (module |
| 1055 | (import "" "b" (func $b)) |
| 1056 | (func $a (export "a") |
| 1057 | call $b |
| 1058 | ) |
| 1059 | (func $c (export "c") |
| 1060 | unreachable |
| 1061 | ) |
| 1062 | ) |
| 1063 | "#; |
| 1064 | |
| 1065 | let mut async_store = Store::new(&Engine::default(), ()); |
| 1066 | |
| 1067 | let async_module = Module::new(async_store.engine(), wat)?; |
| 1068 | |
| 1069 | let mut async_linker = Linker::new(async_store.engine()); |
| 1070 | async_linker.func_wrap("", "b", |_caller: Caller<_>| -> () { unreachable!() })?; |
| 1071 | |
| 1072 | let async_instance = async_linker |
| 1073 | .instantiate_async(&mut async_store, &async_module) |
| 1074 | .await?; |
| 1075 | |
| 1076 | struct SyncCtx { |
| 1077 | async_instance: Instance, |
| 1078 | async_store: Store<()>, |
| 1079 | } |
| 1080 | |
| 1081 | let mut sync_store = Store::new( |
| 1082 | &Engine::default(), |
| 1083 | SyncCtx { |
| 1084 | async_instance, |
| 1085 | async_store, |
| 1086 | }, |
| 1087 | ); |
| 1088 | |
| 1089 | let sync_module = Module::new(sync_store.engine(), wat)?; |
| 1090 | |
| 1091 | let mut sync_linker = Linker::new(sync_store.engine()); |
| 1092 | sync_linker.func_wrap("", "b", move |mut caller: Caller<SyncCtx>| -> Result<()> { |
| 1093 | log::info!("Called `b`..."); |
| 1094 | let async_instance = caller.data().async_instance; |
| 1095 | let async_store = &mut caller.data_mut().async_store; |
| 1096 | |
| 1097 | log::info!("Calling `c`..."); |
| 1098 | let c = async_instance |
| 1099 | .get_typed_func::<(), ()>(&mut *async_store, "c") |
| 1100 | .unwrap(); |
| 1101 | tokio::task::block_in_place(|| { |
| 1102 | tokio::runtime::Handle::current() |
nothing calls this directly
no test coverage detected