Removes api.ImportRenamer for a different approach to "env" (#680)

Before, we introduced a type `api.ImportRenamer` to resolve conflicts
where the "env" module was shared between AssemblyScript and
user-defined functions. This API was never used in GitHub, and is
complicated.

AssemblyScript also isn't the only ABI to share the "env" module, as
other web APIs like Emscripten do also. The less complicated approach is
to have packages that need to share "env" use
`ModuleBuilder.ExportFunctions` instead, and use namespaces as needed if
there is overlap.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-07-11 14:57:26 +08:00
committed by GitHub
parent 09a8aa6030
commit 14d892d310
14 changed files with 322 additions and 493 deletions

View File

@@ -9,7 +9,6 @@ import (
"testing"
"testing/fstest"
"github.com/tetratelabs/wazero/api"
internalsys "github.com/tetratelabs/wazero/internal/sys"
testfs "github.com/tetratelabs/wazero/internal/testing/fs"
"github.com/tetratelabs/wazero/internal/testing/require"
@@ -190,12 +189,6 @@ func TestRuntimeConfig_FeatureToggle(t *testing.T) {
}
func TestCompileConfig(t *testing.T) {
im := func(externType api.ExternType, oldModule, oldName string) (newModule, newName string) {
return "a", oldName
}
im2 := func(externType api.ExternType, oldModule, oldName string) (newModule, newName string) {
return "b", oldName
}
mp := func(minPages uint32, maxPages *uint32) (min, capacity, max uint32) {
return 0, 1, 1
}
@@ -204,20 +197,6 @@ func TestCompileConfig(t *testing.T) {
with func(CompileConfig) CompileConfig
expected *compileConfig
}{
{
name: "WithImportRenamer",
with: func(c CompileConfig) CompileConfig {
return c.WithImportRenamer(im)
},
expected: &compileConfig{importRenamer: im},
},
{
name: "WithImportRenamer twice",
with: func(c CompileConfig) CompileConfig {
return c.WithImportRenamer(im).WithImportRenamer(im2)
},
expected: &compileConfig{importRenamer: im2},
},
{
name: "WithMemorySizer",
with: func(c CompileConfig) CompileConfig {
@@ -242,7 +221,6 @@ func TestCompileConfig(t *testing.T) {
// We cannot compare func, but we can compare reflect.Value
// See https://go.dev/ref/spec#Comparison_operators
require.Equal(t, reflect.ValueOf(tc.expected.importRenamer), reflect.ValueOf(rc.importRenamer))
require.Equal(t, reflect.ValueOf(tc.expected.memorySizer), reflect.ValueOf(rc.memorySizer))
// The source wasn't modified
require.Equal(t, &compileConfig{}, input)