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

Function catch_trap_calling_across_stores

tests/all/traps.rs:887–964  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

885
886#[test]
887fn catch_trap_calling_across_stores() -> Result<()> {
888 let _ = env_logger::try_init();
889
890 let engine = Engine::default();
891
892 let mut child_store = Store::new(&engine, ());
893 let child_module = Module::new(
894 child_store.engine(),
895 r#"
896 (module $child
897 (func $trap (export "trap")
898 unreachable
899 )
900 )
901 "#,
902 )?;
903 let child_instance = Instance::new(&mut child_store, &child_module, &[])?;
904
905 struct ParentCtx {
906 child_store: Store<()>,
907 child_instance: Instance,
908 }
909
910 let mut linker = Linker::new(&engine);
911 linker.func_wrap(
912 "host",
913 "catch_child_trap",
914 move |mut caller: Caller<'_, ParentCtx>| {
915 let mut ctx = caller.as_context_mut();
916 let data = ctx.data_mut();
917 let func = data
918 .child_instance
919 .get_typed_func::<(), ()>(&mut data.child_store, "trap")
920 .expect("trap function should be exported");
921
922 let trap = func.call(&mut data.child_store, ()).unwrap_err();
923 trap.assert_contains("unreachable");
924
925 let trace = trap.downcast_ref::<WasmBacktrace>().unwrap().frames();
926
927 assert_eq!(trace.len(), 1);
928 assert_eq!(trace[0].func_name(), Some("trap"));
929 // For now, we only get stack frames for Wasm in this store, not
930 // across all stores.
931 //
932 // assert_eq!(trace[1].func_name(), Some("run"));
933
934 Ok(())
935 },
936 )?;
937
938 let mut store = Store::new(
939 &engine,
940 ParentCtx {
941 child_store,
942 child_instance,
943 },
944 );

Callers

nothing calls this directly

Calls 12

OkFunction · 0.85
assert_containsMethod · 0.80
newFunction · 0.50
engineMethod · 0.45
func_wrapMethod · 0.45
as_context_mutMethod · 0.45
data_mutMethod · 0.45
expectMethod · 0.45
callMethod · 0.45
framesMethod · 0.45
unwrapMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected