Adds ResultNames to HostFunctionBuilder and FunctionDefinition (#887)
This adds ResultNames to HostFunctionBuilder and FunctionDefinition which helps for multi-results or special-cased ones. End users can access result names in `FunctionDefinition.ResultNames` or set for their own host functions via `HostFunctionBuilder.WithResultNames`. This change adds them for all built-in functions where result names help. Most notably, GOOS=js uses `ProxyFunc` to allow logging when a function returns multiple results. Before, the results were returned without names: e.g. `11231,1` and now they are named like `n=11231,ok=1`. We soon plan to allow more visibility in WASI, for example, logging results that will write to memory offsets. This infrastructure makes it possible to do that. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
func TestModule_BuildFunctionDefinitions(t *testing.T) {
|
||||
nopCode := &Code{Body: []byte{OpcodeEnd}}
|
||||
fn := func() {}
|
||||
fn := func(uint32) uint32 { return 1 }
|
||||
tests := []struct {
|
||||
name string
|
||||
m *Module
|
||||
@@ -33,16 +33,26 @@ func TestModule_BuildFunctionDefinitions(t *testing.T) {
|
||||
{
|
||||
name: "host func go",
|
||||
m: &Module{
|
||||
TypeSection: []*FunctionType{v_v},
|
||||
TypeSection: []*FunctionType{i32_i32},
|
||||
FunctionSection: []Index{0},
|
||||
CodeSection: []*Code{MustParseGoReflectFuncCode(fn)},
|
||||
NameSection: &NameSection{
|
||||
ModuleName: "m",
|
||||
FunctionNames: NameMap{{Index: Index(0), Name: "fn"}},
|
||||
LocalNames: IndirectNameMap{{Index: Index(0), NameMap: NameMap{{Index: Index(0), Name: "x"}}}},
|
||||
ResultNames: IndirectNameMap{{Index: Index(0), NameMap: NameMap{{Index: Index(0), Name: "y"}}}},
|
||||
},
|
||||
},
|
||||
expected: []*FunctionDefinition{
|
||||
{
|
||||
index: 0,
|
||||
debugName: ".$0",
|
||||
goFunc: MustParseGoReflectFuncCode(fn).GoFunc,
|
||||
funcType: v_v,
|
||||
index: 0,
|
||||
name: "fn",
|
||||
moduleName: "m",
|
||||
debugName: "m.fn",
|
||||
goFunc: MustParseGoReflectFuncCode(fn).GoFunc,
|
||||
funcType: i32_i32,
|
||||
paramNames: []string{"x"},
|
||||
resultNames: []string{"y"},
|
||||
},
|
||||
},
|
||||
expectedExports: map[string]api.FunctionDefinition{},
|
||||
|
||||
Reference in New Issue
Block a user