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

Function TestCallFuncFromCaller

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

Source from the content-addressed store, hash-verified

363}
364
365func TestCallFuncFromCaller(t *testing.T) {
366 wasm, err := Wat2Wasm(`
367 (module
368 (import "" "f2" (func $f2))
369 (func (export "f1")
370 (call $f2)
371 (call $f2))
372 (func (export "f3")
373 (nop)))
374 `)
375 require.NoError(t, err)
376
377 store := NewStore(NewEngine())
378 f := NewFunc(store, NewFuncType(nil, nil), func(c *Caller, args []Val) ([]Val, *Trap) {
379 fn := c.GetExport("f3").Func()
380 _, err := fn.Call(store)
381 require.NoError(t, err)
382 return nil, nil
383 })
384
385 module, err := NewModule(store.Engine, wasm)
386 require.NoError(t, err)
387
388 instance, err := NewInstance(store, module, []AsExtern{f})
389 require.NoError(t, err)
390
391 _, err = instance.GetFunc(store, "f1").Call(store)
392 require.NoError(t, err)
393}
394
395func TestPanicTraps(t *testing.T) {
396 wasm, err := Wat2Wasm(`

Callers

nothing calls this directly

Calls 11

GetFuncMethod · 0.95
Wat2WasmFunction · 0.85
NewStoreFunction · 0.85
NewEngineFunction · 0.85
NewFuncFunction · 0.85
NewFuncTypeFunction · 0.85
NewModuleFunction · 0.85
NewInstanceFunction · 0.85
FuncMethod · 0.80
CallMethod · 0.80
GetExportMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…