()
| 1029 | #[tokio::test] |
| 1030 | #[cfg_attr(miri, ignore)] |
| 1031 | async fn invalidated_frame_handles() -> wasmtime::Result<()> { |
| 1032 | let (module, mut store) = get_module_and_store( |
| 1033 | |_config| {}, |
| 1034 | r#" |
| 1035 | (module |
| 1036 | (import "" "" (func)) |
| 1037 | (func (export "main") |
| 1038 | (local i32 i32) |
| 1039 | i32.const 1 |
| 1040 | local.set 0 |
| 1041 | i32.const 2 |
| 1042 | local.set 1 |
| 1043 | call 2 |
| 1044 | call 0) |
| 1045 | (func |
| 1046 | (local i32 i32) |
| 1047 | i32.const 3 |
| 1048 | local.set 0 |
| 1049 | i32.const 4 |
| 1050 | local.set 1 |
| 1051 | call 0)) |
| 1052 | "#, |
| 1053 | )?; |
| 1054 | |
| 1055 | let handle: Arc<Mutex<Option<FrameHandle>>> = Arc::new(Mutex::new(None)); |
| 1056 | |
| 1057 | let hostfunc = Func::wrap_async(&mut store, move |mut caller, _args: ()| { |
| 1058 | let handle = handle.clone(); |
| 1059 | Box::new(async move { |
| 1060 | let frame = handle.lock().unwrap().take(); |
| 1061 | if let Some(frame) = frame { |
| 1062 | // Ensure that the handle has been invalidated. |
| 1063 | assert!(!frame.is_valid(&mut caller)); |
| 1064 | // Ensure that attempts to fetch data from the frame |
| 1065 | // fail with a clean `Err`, not a panic or crash. |
| 1066 | let result = frame.wasm_function_index_and_pc(&mut caller); |
| 1067 | assert!(result.is_err()); |
| 1068 | // Ensure that we can get a new frame handle and use it. |
| 1069 | let frame = caller.debug_exit_frames().next().unwrap(); |
| 1070 | assert_eq!(frame.num_locals(&mut caller)?, 2); |
| 1071 | assert_eq!(frame.local(&mut caller, 0)?.unwrap_i32(), 1); |
| 1072 | assert_eq!(frame.local(&mut caller, 1)?.unwrap_i32(), 2); |
| 1073 | } else { |
| 1074 | let frame = caller.debug_exit_frames().next().unwrap(); |
| 1075 | assert_eq!(frame.num_locals(&mut caller)?, 2); |
| 1076 | assert_eq!(frame.local(&mut caller, 0)?.unwrap_i32(), 3); |
| 1077 | assert_eq!(frame.local(&mut caller, 1)?.unwrap_i32(), 4); |
| 1078 | *handle.lock().unwrap() = Some(frame); |
| 1079 | } |
| 1080 | Ok(()) |
| 1081 | }) |
| 1082 | }); |
| 1083 | |
| 1084 | let instance = Instance::new_async(&mut store, &module, &[Extern::Func(hostfunc)]).await?; |
| 1085 | let main = instance.get_func(&mut store, "main").unwrap(); |
| 1086 | main.call_async(&mut store, &[], &mut []).await?; |
| 1087 | |
| 1088 | Ok(()) |
nothing calls this directly
no test coverage detected