fix script timeout bug (#170)
* fix an edge case where script timeout is too short and set even before VM starts execution * vm.StackObjects() -> v.IsStackEmpty()
This commit is contained in:
parent
1ac4090452
commit
8dc0d7b591
2 changed files with 7 additions and 12 deletions
|
@ -77,7 +77,6 @@ func (v *VM) Run() (err error) {
|
|||
v.framesIndex = 1
|
||||
v.ip = -1
|
||||
v.allocs = v.maxAllocs + 1
|
||||
atomic.StoreInt64(&v.aborting, 0)
|
||||
|
||||
v.run()
|
||||
|
||||
|
@ -95,11 +94,6 @@ func (v *VM) Run() (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
// check if stack still has some objects left
|
||||
if v.sp > 0 && atomic.LoadInt64(&v.aborting) == 0 {
|
||||
panic(fmt.Errorf("non empty stack after execution: %d", v.sp))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -121,7 +115,7 @@ func (v *VM) run() {
|
|||
}
|
||||
}()
|
||||
|
||||
for atomic.LoadInt64(&v.aborting) == 0 {
|
||||
for atomic.CompareAndSwapInt64(&v.aborting, 0, 0) {
|
||||
v.ip++
|
||||
|
||||
switch v.curInsts[v.ip] {
|
||||
|
@ -1008,9 +1002,9 @@ func (v *VM) run() {
|
|||
}
|
||||
}
|
||||
|
||||
// Globals returns the global variables.
|
||||
func (v *VM) Globals() []objects.Object {
|
||||
return v.globals
|
||||
// IsStackEmpty tests if the stack is empty or not.
|
||||
func (v *VM) IsStackEmpty() bool {
|
||||
return v.sp == 0
|
||||
}
|
||||
|
||||
func indexAssign(dst, src objects.Object, selectors []objects.Object) error {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package runtime_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
_runtime "runtime"
|
||||
|
@ -250,8 +251,8 @@ func traceCompileRun(file *ast.File, symbols map[string]objects.Object, modules
|
|||
}
|
||||
trace = append(trace, fmt.Sprintf("\n[Globals]\n\n%s", strings.Join(formatGlobals(globals), "\n")))
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
if err == nil && !v.IsStackEmpty() {
|
||||
err = errors.New("non empty stack after execution")
|
||||
}
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue