Makes wazero.CompiledCode an interface instead of a struct (#519)

This makes wazero.CompiledCode an interface instead of a struct to
prevent it from being used incorrectly. For example, even though the
fields are not exported, someone can mistakenly instantiate this
when it is a struct, and in doing so violate internal assumptions.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-05-02 11:44:01 +08:00
committed by GitHub
parent a91140f7f7
commit fbea2de984
8 changed files with 61 additions and 36 deletions

View File

@@ -853,12 +853,12 @@ func TestCompiledCode_Close(t *testing.T) {
for _, ctx := range []context.Context{nil, testCtx} { // Ensure it doesn't crash on nil!
e := &mockEngine{name: "1", cachedModules: map[*wasm.Module]struct{}{}}
var cs []*CompiledCode
var cs []*compiledCode
for i := 0; i < 10; i++ {
m := &wasm.Module{}
err := e.CompileModule(ctx, m)
require.NoError(t, err)
cs = append(cs, &CompiledCode{module: m, compiledEngine: e})
cs = append(cs, &compiledCode{module: m, compiledEngine: e})
}
// Before Close.