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

Function trapping

tests/all/component_model/call_hook.rs:249–399  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

247
248#[test]
249fn trapping() -> Result<()> {
250 const TRAP_IN_F: i32 = 0;
251 const TRAP_NEXT_CALL_HOST: i32 = 1;
252 const TRAP_NEXT_RETURN_HOST: i32 = 2;
253 const TRAP_NEXT_CALL_WASM: i32 = 3;
254 const TRAP_NEXT_RETURN_WASM: i32 = 4;
255 const DO_NOTHING: i32 = 5;
256
257 let engine = Engine::default();
258
259 let mut linker = Linker::<State>::new(&engine);
260
261 linker
262 .root()
263 .func_wrap("f", |mut store: _, (action,): (i32,)| -> Result<()> {
264 assert_eq!(store.data().context.last(), Some(&Context::Host));
265 assert_eq!(store.data().calls_into_host, store.data().calls_into_wasm);
266
267 match action {
268 TRAP_IN_F => bail!("trapping in f"),
269 TRAP_NEXT_CALL_HOST => store.data_mut().trap_next_call_host = true,
270 TRAP_NEXT_RETURN_HOST => store.data_mut().trap_next_return_host = true,
271 TRAP_NEXT_CALL_WASM => store.data_mut().trap_next_call_wasm = true,
272 TRAP_NEXT_RETURN_WASM => store.data_mut().trap_next_return_wasm = true,
273 _ => {} // Do nothing
274 }
275
276 Ok(())
277 })?;
278
279 let wat = r#"
280 (component
281 (import "f" (func $f (param "action" s32)))
282
283 (core func $f_lower
284 (canon lower (func $f))
285 )
286 (core module $m
287 (import "" "" (func $f (param i32)))
288
289 (func $export (param i32)
290 (call $f (local.get 0))
291 )
292
293 (export "export" (func $export))
294 )
295 (core instance $i (instantiate $m
296 (with "" (instance
297 (export "" (func $f_lower))
298 ))
299 ))
300 (func (export "export") (param "action" s32)
301 (canon lift
302 (core func $i "export")
303 )
304 )
305 )
306 "#;

Callers

nothing calls this directly

Calls 13

OkFunction · 0.85
is_okMethod · 0.80
into_dataMethod · 0.80
runFunction · 0.70
newFunction · 0.50
func_wrapMethod · 0.45
rootMethod · 0.45
data_mutMethod · 0.45
call_hookMethod · 0.45
expectMethod · 0.45
instantiateMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected