Closed
Description
Panic crash with setInterval with invalid parameters:
> setInterval()
panic: runtime error: index out of range
goroutine 119 [running]:
github.com/ethereum/go-ethereum/jsre.(*JSRE).runEventLoop(0xc2081d1240)
/build/ethereum-JpVrVd/ethereum-0.9.23+23trusty/obj-x86_64-linux-gnu/src/github.com/ethereum/go-ethereum/jsre/jsre.go:168 +0xb8c
created by github.com/ethereum/go-ethereum/jsre.New
/build/ethereum-JpVrVd/ethereum-0.9.23+23trusty/obj-x86_64-linux-gnu/src/github.com/ethereum/go-ethereum/jsre/jsre.go:65 +0x280
goroutine 1 [runnable]:
Relevant code jsre/jsre.go
:
func (self *JSRE) runEventLoop() {
registry := map[*jsTimer]*jsTimer{}
ready := make(chan *jsTimer)
newTimer := func(call otto.FunctionCall, interval bool) (*jsTimer, otto.Value) {
delay, _ := call.Argument(1).ToInteger()
if 0 >= delay {
delay = 1
}
timer := &jsTimer{
duration: time.Duration(delay) * time.Millisecond,
call: call,
interval: interval,
}
registry[timer] = timer
timer.timer = time.AfterFunc(timer.duration, func() {
ready <- timer
})
value, err := call.Otto.ToValue(timer)
if err != nil {
panic(err)
}
return timer, value
}
setTimeout := func(call otto.FunctionCall) otto.Value {
_, value := newTimer(call, false)
return value
}
setInterval := func(call otto.FunctionCall) otto.Value {
_, value := newTimer(call, true)
return value
}
clearTimeout := func(call otto.FunctionCall) otto.Value {
timer, _ := call.Argument(0).Export()
if timer, ok := timer.(*jsTimer); ok {
timer.timer.Stop()
delete(registry, timer)
}
return otto.UndefinedValue()
}
self.vm.Set("setTimeout", setTimeout)
self.vm.Set("setInterval", setInterval)
self.vm.Set("clearTimeout", clearTimeout)
self.vm.Set("clearInterval", clearTimeout)
Specifically:
if err != nil {
panic(err)
}
Panic crash? Seems a bit drastic... I'd submit a patch, but the panic looks pretty intentional.