compiler: adds support for FunctionListeners (#869)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2022-11-29 15:15:49 +09:00
committed by GitHub
parent b49622b881
commit 84d733eb0a
29 changed files with 352 additions and 114 deletions

View File

@@ -189,11 +189,11 @@ func (r *runtime) CompileModule(ctx context.Context, binary []byte) (CompiledMod
c := &compiledModule{module: internal, compiledEngine: r.store.Engine}
if c.listeners, err = buildListeners(ctx, r, internal); err != nil {
if c.listeners, err = buildListeners(ctx, internal); err != nil {
return nil, err
}
if err = r.store.Engine.CompileModule(ctx, internal); err != nil {
if err = r.store.Engine.CompileModule(ctx, internal, c.listeners); err != nil {
return nil, err
}
@@ -201,15 +201,12 @@ func (r *runtime) CompileModule(ctx context.Context, binary []byte) (CompiledMod
return c, nil
}
func buildListeners(ctx context.Context, r *runtime, internal *wasm.Module) ([]experimentalapi.FunctionListener, error) {
func buildListeners(ctx context.Context, internal *wasm.Module) ([]experimentalapi.FunctionListener, error) {
// Test to see if internal code are using an experimental feature.
fnlf := ctx.Value(experimentalapi.FunctionListenerFactoryKey{})
if fnlf == nil {
return nil, nil
}
if !r.isInterpreter {
return nil, errors.New("context includes a FunctionListenerFactoryKey, which is only supported in the interpreter")
}
factory := fnlf.(experimentalapi.FunctionListenerFactory)
importCount := internal.ImportFuncCount()
listeners := make([]experimentalapi.FunctionListener, len(internal.FunctionSection))