diff options
Diffstat (limited to 'vendor/github.com/d5/tengo/v2/script.go')
-rw-r--r-- | vendor/github.com/d5/tengo/v2/script.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/vendor/github.com/d5/tengo/v2/script.go b/vendor/github.com/d5/tengo/v2/script.go index 46e48029..82b02f52 100644 --- a/vendor/github.com/d5/tengo/v2/script.go +++ b/vendor/github.com/d5/tengo/v2/script.go @@ -12,7 +12,7 @@ import ( // Script can simplify compilation and execution of embedded scripts. type Script struct { variables map[string]*Variable - modules *ModuleMap + modules ModuleGetter input []byte maxAllocs int64 maxConstObjects int @@ -54,7 +54,7 @@ func (s *Script) Remove(name string) bool { } // SetImports sets import modules. -func (s *Script) SetImports(modules *ModuleMap) { +func (s *Script) SetImports(modules ModuleGetter) { s.modules = modules } @@ -219,6 +219,18 @@ func (c *Compiled) RunContext(ctx context.Context) (err error) { v := NewVM(c.bytecode, c.globals, c.maxAllocs) ch := make(chan error, 1) go func() { + defer func() { + if r := recover(); r != nil { + switch e := r.(type) { + case string: + ch <- fmt.Errorf(e) + case error: + ch <- e + default: + ch <- fmt.Errorf("unknown panic: %v", e) + } + } + }() ch <- v.Run() }() |