| 233 | |
| 234 | #[test] |
| 235 | fn test_trap_trace_cb() -> Result<()> { |
| 236 | let mut store = Store::<()>::default(); |
| 237 | let wat = r#" |
| 238 | (module $hello_mod |
| 239 | (import "" "throw" (func $throw)) |
| 240 | (func (export "run") (call $hello)) |
| 241 | (func $hello (call $throw)) |
| 242 | ) |
| 243 | "#; |
| 244 | |
| 245 | let fn_type = FuncType::new(store.engine(), None, None); |
| 246 | let fn_func = Func::new(&mut store, fn_type, |_, _, _| bail!("cb throw")); |
| 247 | |
| 248 | let module = Module::new(store.engine(), wat)?; |
| 249 | let instance = Instance::new(&mut store, &module, &[fn_func.into()])?; |
| 250 | let run_func = instance.get_typed_func::<(), ()>(&mut store, "run")?; |
| 251 | |
| 252 | let e = run_func.call(&mut store, ()).unwrap_err(); |
| 253 | |
| 254 | let trace = e.downcast_ref::<WasmBacktrace>().unwrap().frames(); |
| 255 | assert_eq!(trace.len(), 2); |
| 256 | assert_eq!(trace[0].module().name().unwrap(), "hello_mod"); |
| 257 | assert_eq!(trace[0].func_index(), 2); |
| 258 | assert_eq!(trace[1].module().name().unwrap(), "hello_mod"); |
| 259 | assert_eq!(trace[1].func_index(), 1); |
| 260 | e.assert_contains("cb throw"); |
| 261 | |
| 262 | Ok(()) |
| 263 | } |
| 264 | |
| 265 | #[test] |
| 266 | fn test_trap_stack_overflow() -> Result<()> { |