| 478 | |
| 479 | #[test] |
| 480 | fn rust_panic_start_function() -> Result<()> { |
| 481 | let mut store = Store::<()>::default(); |
| 482 | let binary = wat::parse_str( |
| 483 | r#" |
| 484 | (module $a |
| 485 | (import "" "" (func $foo)) |
| 486 | (start $foo) |
| 487 | ) |
| 488 | "#, |
| 489 | )?; |
| 490 | |
| 491 | let module = Module::new(store.engine(), &binary)?; |
| 492 | let sig = FuncType::new(store.engine(), None, None); |
| 493 | let func = Func::new(&mut store, sig, |_, _, _| panic!("this is a panic")); |
| 494 | let err = panic::catch_unwind(AssertUnwindSafe(|| { |
| 495 | drop(Instance::new(&mut store, &module, &[func.into()])); |
| 496 | })) |
| 497 | .unwrap_err(); |
| 498 | assert_eq!(err.downcast_ref::<&'static str>(), Some(&"this is a panic")); |
| 499 | |
| 500 | let func = Func::wrap(&mut store, || -> () { panic!("this is another panic") }); |
| 501 | let err = panic::catch_unwind(AssertUnwindSafe(|| { |
| 502 | drop(Instance::new(&mut store, &module, &[func.into()])); |
| 503 | })) |
| 504 | .unwrap_err(); |
| 505 | assert_eq!( |
| 506 | err.downcast_ref::<&'static str>(), |
| 507 | Some(&"this is another panic") |
| 508 | ); |
| 509 | Ok(()) |
| 510 | } |
| 511 | |
| 512 | #[test] |
| 513 | fn mismatched_arguments() -> Result<()> { |