diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-27 06:00:36 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-11-27 06:00:36 +0800 |
commit | de75d542f37a4aa3574c788cec522994ac537f1d (patch) | |
tree | 4ad766a141257721f2056ad81d0314ef8737c2bd | |
parent | b9db5b37f2d6d8a78769ef62b2ffb81674476fba (diff) | |
parent | f27e826b140089cbeb722feec96b1aae3e7645a3 (diff) | |
download | go-tangerine-de75d542f37a4aa3574c788cec522994ac537f1d.tar.gz go-tangerine-de75d542f37a4aa3574c788cec522994ac537f1d.tar.zst go-tangerine-de75d542f37a4aa3574c788cec522994ac537f1d.zip |
Merge pull request #1999 from karalabe/javascript-timer-argcheck
jrse: fix #1082, fail if setTimeout/setInterval lack callback
-rw-r--r-- | jsre/jsre.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/jsre/jsre.go b/jsre/jsre.go index af7d507c6..a4c9d970b 100644 --- a/jsre/jsre.go +++ b/jsre/jsre.go @@ -85,7 +85,6 @@ func (self *JSRE) runEventLoop() { ready := make(chan *jsTimer) newTimer := func(call otto.FunctionCall, interval bool) (*jsTimer, otto.Value) { - delay, _ := call.Argument(1).ToInteger() if 0 >= delay { delay = 1 @@ -105,7 +104,6 @@ func (self *JSRE) runEventLoop() { if err != nil { panic(err) } - return timer, value } @@ -127,8 +125,20 @@ func (self *JSRE) runEventLoop() { } return otto.UndefinedValue() } - vm.Set("setTimeout", setTimeout) - vm.Set("setInterval", setInterval) + vm.Set("_setTimeout", setTimeout) + 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("clearInterval", clearTimeout) @@ -154,7 +164,7 @@ loop: if err != nil { fmt.Println("js error:", err, arguments) } - + _, inreg := registry[timer] // when clearInterval is called from within the callback don't reset it if timer.interval && inreg { timer.timer.Reset(timer.duration) |