Repository: tetratelabs/wazero
Pull request #326 (2022-03-03 23:54:51)

Unexport moduleInstance.GetExport and remove test-only store.getExport
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>


Patch:
diff --git a/internal/wasm/global.go b/internal/wasm/global.go
index 1906fa47..b1217f75 100644
--- a/internal/wasm/global.go
+++ b/internal/wasm/global.go
@@ -124,7 +124,7 @@ func (g globalF64) String() string {
 
 // Global implements wasm.Module Global
 func (m *PublicModule) Global(name string) publicwasm.Global {
-	exp, err := m.Instance.GetExport(name, ExternTypeGlobal)
+	exp, err := m.Instance.getExport(name, ExternTypeGlobal)
 	if err != nil {
 		return nil
 	}
diff --git a/internal/wasm/host.go b/internal/wasm/host.go
index 9e6688c8..c00cf2bd 100644
--- a/internal/wasm/host.go
+++ b/internal/wasm/host.go
@@ -61,7 +61,7 @@ func (c *ModuleContext) Memory() publicwasm.Memory {
 
 // Function implements wasm.ModuleContext Function
 func (c *ModuleContext) Function(name string) publicwasm.Function {
-	exp, err := c.Module.GetExport(name, ExternTypeFunc)
+	exp, err := c.Module.getExport(name, ExternTypeFunc)
 	if err != nil {
 		return nil
 	}
diff --git a/internal/wasm/store.go b/internal/wasm/store.go
index 7a9d8eab..117e5107 100644
--- a/internal/wasm/store.go
+++ b/internal/wasm/store.go
@@ -373,7 +373,7 @@ func (m *ModuleInstance) addExport(name string, e *ExportInstance) error {
 }
 
 // GetExport returns an export of the given name and type or errs if not exported or the wrong type.
-func (m *ModuleInstance) GetExport(name string, et ExternType) (*ExportInstance, error) {
+func (m *ModuleInstance) getExport(name string, et ExternType) (*ExportInstance, error) {
 	exp, ok := m.Exports[name]
 	if !ok {
 		return nil, fmt.Errorf("%q is not exported in module %q", name, m.Name)
@@ -642,7 +642,7 @@ type PublicModule struct {
 
 // Function implements wasm.Module Function
 func (m *PublicModule) Function(name string) publicwasm.Function {
-	exp, err := m.Instance.GetExport(name, ExternTypeFunc)
+	exp, err := m.Instance.getExport(name, ExternTypeFunc)
 	if err != nil {
 		return nil
 	}
@@ -651,7 +651,7 @@ func (m *PublicModule) Function(name string) publicwasm.Function {
 
 // Memory implements wasm.Module Memory
 func (m *PublicModule) Memory(name string) publicwasm.Memory {
-	exp, err := m.Instance.GetExport(name, ExternTypeMemory)
+	exp, err := m.Instance.getExport(name, ExternTypeMemory)
 	if err != nil {
 		return nil
 	}
@@ -663,15 +663,6 @@ func (s *Store) HostModule(moduleName string) publicwasm.HostModule {
 	return s.moduleInstances[moduleName].hostModule
 }
 
-func (s *Store) getExport(moduleName string, name string, et ExternType) (exp *ExportInstance, err error) {
-	if m, ok := s.moduleInstances[moduleName]; !ok {
-		return nil, fmt.Errorf("module %s not instantiated", moduleName)
-	} else if exp, err = m.GetExport(name, et); err != nil {
-		return
-	}
-	return
-}
-
 func (s *Store) resolveImports(module *Module) (
 	functions []*FunctionInstance, globals []*GlobalInstance,
 	table *TableInstance, memory *MemoryInstance,
@@ -690,7 +681,7 @@ func (s *Store) resolveImports(module *Module) (
 		moduleImports[m] = struct{}{}
 
 		var exp *ExportInstance
-		exp, err = m.GetExport(is.Name, is.Type)
+		exp, err = m.getExport(is.Name, is.Type)
 		if err != nil {
 			return
 		}


Test patch:
diff --git a/internal/wasm/store_test.go b/internal/wasm/store_test.go
index f18a6dbc..862dcc12 100644
--- a/internal/wasm/store_test.go
+++ b/internal/wasm/store_test.go
@@ -139,7 +139,10 @@ func TestStore_ExportImportedHostFunction(t *testing.T) {
 		}, "test")
 		require.NoError(t, err)
 
-		ei, err := s.getExport("test", "host.fn", ExternTypeFunc)
+		mod, ok := s.moduleInstances["test"]
+		require.True(t, ok)
+
+		ei, err := mod.getExport("host.fn", ExternTypeFunc)
 		require.NoError(t, err)
 		os.Environ()
 		// We expect the host function to be called in context of the importing module.