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

Function uncaught_exception_events

tests/all/debug.rs:599–644  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

597#[tokio::test]
598#[cfg_attr(miri, ignore)]
599async fn uncaught_exception_events() -> wasmtime::Result<()> {
600 let _ = env_logger::try_init();
601
602 let (module, mut store) = get_module_and_store(
603 |config| {
604 config.wasm_exceptions(true);
605 },
606 r#"
607 (module
608 (tag $t (param i32))
609 (func (export "main")
610 call 1)
611 (func
612 (local $i i32)
613 (local.set $i (i32.const 100))
614 (throw $t (i32.const 42))))
615 "#,
616 )?;
617
618 debug_event_checker!(
619 D, store,
620 { 0 ;
621 wasmtime::DebugEvent::Exception(e) => {
622 assert_eq!(e.field(&mut store, 0).unwrap().unwrap_i32(), 42);
623 let stack = store.debug_exit_frames().next().unwrap();
624 assert_eq!(stack.num_locals(&mut store).unwrap(), 1);
625 assert_eq!(stack.local(&mut store, 0).unwrap().unwrap_i32(), 100);
626 let stack = stack.parent(&mut store).unwrap().unwrap();
627 let stack = stack.parent(&mut store).unwrap();
628 assert!(stack.is_none());
629 }
630 }
631 );
632
633 let (handler, counter) = D::new_and_counter();
634 store.set_debug_handler(handler);
635
636 let instance = Instance::new_async(&mut store, &module, &[]).await?;
637 let func = instance.get_func(&mut store, "main").unwrap();
638 let mut results = [];
639 let result = func.call_async(&mut store, &[], &mut results).await;
640 assert!(result.is_err()); // Uncaught exception.
641 assert_eq!(counter.load(Ordering::Relaxed), 1);
642
643 Ok(())
644}
645
646#[tokio::test]
647#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 7

get_module_and_storeFunction · 0.85
OkFunction · 0.85
set_debug_handlerMethod · 0.80
wasm_exceptionsMethod · 0.45
unwrapMethod · 0.45
get_funcMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected