fix: copy SourceMap in vm OpClosure branch (#392)
This commit is contained in:
parent
e338512259
commit
8a3f5bdb11
2 changed files with 33 additions and 0 deletions
|
@ -541,6 +541,38 @@ func (n *customNumber) binaryOpInt(op token.Token, rhs *tengo.Int) (tengo.Object
|
|||
return nil, tengo.ErrInvalidOperator
|
||||
}
|
||||
|
||||
func TestScript_ImportError(t *testing.T) {
|
||||
m := `
|
||||
exp := import("expression")
|
||||
r := exp(ctx)
|
||||
`
|
||||
|
||||
src := `
|
||||
export func(ctx) {
|
||||
closure := func() {
|
||||
if ctx.actiontimes < 0 { // an error is thrown here because actiontimes is undefined
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return closure()
|
||||
}`
|
||||
|
||||
s := tengo.NewScript([]byte(m))
|
||||
mods := tengo.NewModuleMap()
|
||||
mods.AddSourceModule("expression", []byte(src))
|
||||
s.SetImports(mods)
|
||||
|
||||
err := s.Add("ctx", map[string]interface{}{
|
||||
"ctx": 12,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = s.Run()
|
||||
require.True(t, strings.Contains(err.Error(), "expression:4:6"))
|
||||
}
|
||||
|
||||
func compile(t *testing.T, input string, vars M) *tengo.Compiled {
|
||||
s := tengo.NewScript([]byte(input))
|
||||
for vn, vv := range vars {
|
||||
|
|
1
vm.go
1
vm.go
|
@ -767,6 +767,7 @@ func (v *VM) run() {
|
|||
NumLocals: fn.NumLocals,
|
||||
NumParameters: fn.NumParameters,
|
||||
VarArgs: fn.VarArgs,
|
||||
SourceMap: fn.SourceMap,
|
||||
Free: free,
|
||||
}
|
||||
v.allocs--
|
||||
|
|
Loading…
Reference in a new issue