File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed
python/pythonmonkey/builtin_modules Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -21,8 +21,9 @@ const {
2121 */
2222function setTimeout ( handler , delayMs = 0 , ...args ) {
2323 // Ensure the first parameter is a function
24+ // We support passing a `code` string to `setTimeout` as the callback function
2425 if ( typeof handler !== "function" ) {
25- throw new TypeError ( "The first parameter to setTimeout() is not a function" )
26+ handler = new Function ( handler )
2627 }
2728
2829 // `setTimeout` allows passing additional arguments to the callback, as spec-ed
Original file line number Diff line number Diff line change @@ -48,15 +48,13 @@ def to_raise(msg):
4848 pm .eval ("clearTimeout(undefined)" )
4949 pm .eval ("clearTimeout()" )
5050
51- # should throw a TypeError when the first parameter to `setTimeout` is not a function
52- with pytest .raises (pm .SpiderMonkeyError , match = "TypeError: The first parameter to setTimeout\\ (\\ ) is not a function" ):
53- pm .eval ("setTimeout()" )
54- with pytest .raises (pm .SpiderMonkeyError , match = "TypeError: The first parameter to setTimeout\\ (\\ ) is not a function" ):
55- pm .eval ("setTimeout(undefined)" )
56- with pytest .raises (pm .SpiderMonkeyError , match = "TypeError: The first parameter to setTimeout\\ (\\ ) is not a function" ):
57- pm .eval ("setTimeout(1)" )
58- with pytest .raises (pm .SpiderMonkeyError , match = "TypeError: The first parameter to setTimeout\\ (\\ ) is not a function" ):
59- pm .eval ("setTimeout('a', 100)" )
51+ # passing a `code` string to `setTimeout` as the callback function
52+ assert "code string" == await pm .eval ("""
53+ new Promise((resolve) => {
54+ globalThis._resolve = resolve
55+ setTimeout("globalThis._resolve('code string'); delete globalThis._resolve", 100)
56+ })
57+ """ )
6058
6159 # making sure the async_fn is run
6260 return True
You can’t perform that action at this time.
0 commit comments