jrse: fix #1082, fail if setTimeout/setInterval lack callback

This commit is contained in:
Péter Szilágyi 2015-11-23 13:03:31 +02:00
parent ae9e9efa31
commit f27e826b14
1 changed files with 15 additions and 5 deletions

View File

@ -85,7 +85,6 @@ func (self *JSRE) runEventLoop() {
ready := make(chan *jsTimer) ready := make(chan *jsTimer)
newTimer := func(call otto.FunctionCall, interval bool) (*jsTimer, otto.Value) { newTimer := func(call otto.FunctionCall, interval bool) (*jsTimer, otto.Value) {
delay, _ := call.Argument(1).ToInteger() delay, _ := call.Argument(1).ToInteger()
if 0 >= delay { if 0 >= delay {
delay = 1 delay = 1
@ -105,7 +104,6 @@ func (self *JSRE) runEventLoop() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
return timer, value return timer, value
} }
@ -127,8 +125,20 @@ func (self *JSRE) runEventLoop() {
} }
return otto.UndefinedValue() return otto.UndefinedValue()
} }
vm.Set("setTimeout", setTimeout) vm.Set("_setTimeout", setTimeout)
vm.Set("setInterval", setInterval) vm.Set("_setInterval", setInterval)
vm.Run(`var setTimeout = function(args) {
if (arguments.length < 1) {
throw TypeError("Failed to execute 'setTimeout': 1 argument required, but only 0 present.");
}
return _setTimeout.apply(this, arguments);
}`)
vm.Run(`var setInterval = function(args) {
if (arguments.length < 1) {
throw TypeError("Failed to execute 'setInterval': 1 argument required, but only 0 present.");
}
return _setInterval.apply(this, arguments);
}`)
vm.Set("clearTimeout", clearTimeout) vm.Set("clearTimeout", clearTimeout)
vm.Set("clearInterval", clearTimeout) vm.Set("clearInterval", clearTimeout)