MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime-go / TestPanicTraps

Function TestPanicTraps

func_test.go:395–434  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

393}
394
395func TestPanicTraps(t *testing.T) {
396 wasm, err := Wat2Wasm(`
397 (module
398 (import "" "" (func $i (param i32)))
399 (func (export "h")
400 i32.const 0
401 call $i
402 i32.const 1
403 call $i)
404 )`)
405 require.NoError(t, err)
406
407 store := NewStore(NewEngine())
408 correctPanic := false
409 f := WrapFunc(store, func(arg int32) {
410 if arg == 0 {
411 correctPanic = true
412 panic("got the right argument")
413 } else {
414 correctPanic = false
415 panic("expected zero")
416 }
417 })
418
419 module, err := NewModule(store.Engine, wasm)
420 require.NoError(t, err)
421
422 instance, err := NewInstance(store, module, []AsExtern{f})
423 require.NoError(t, err)
424
425 f = instance.GetFunc(store, "h")
426 var lastPanic interface{}
427 func() {
428 defer func() { lastPanic = recover() }()
429 f.Call(store)
430 panic("should have panicked")
431 }()
432 require.NotNil(t, lastPanic, "expected a panic")
433 require.True(t, correctPanic, "wasm was resumed after initial panic")
434}

Callers

nothing calls this directly

Calls 8

GetFuncMethod · 0.95
Wat2WasmFunction · 0.85
NewStoreFunction · 0.85
NewEngineFunction · 0.85
WrapFuncFunction · 0.85
NewModuleFunction · 0.85
NewInstanceFunction · 0.85
CallMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…