New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setInterval returns undefined after the window closes #2617
Comments
We should probably make it (and maybe everything in jsdom) throw after the window closes. |
@domenic I think this is actually a bug though. x = window.open("about:blank")
x.setTimeout("document.body.innerText += 'hi'", 1000) // 1
x.close();
x.setTimeout("document.body.innerText += 'hi'", 1000) // 2 |
Actually I was wrong about browser behavior - you can call
logs |
Returning anything but a nonzero integer is against HTML spec. https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval
|
Chrome returns 0 after the window closes, though. So I guess Chrome is against HTML spec here? I would suggest just returning 0 for Chrome compatibility. I agree it should return some sort of integer. |
Basic info:
Node 8
jsdom 15.1.1
Minimal reproduction case
The problem is that in jsdom,
setInterval
returns undefined after the window closes. However, normally setInterval will never return undefined, either in Node or in browsers. So it's reasonable for some code to be nested in a bunch of callbacks, and run after the jsdom window has been closed, but to expect a non-undefined return value forsetInterval
.Specifically, some code in the
simple-peer
library does something likelet returnValue = setInterval(...); if (returnValue.unref) { ... }
to handle the case where timers should be unref'd to let Node exit. That code is correct according to either browsers or Node, but fails in a jsdom environment.Instead, perhaps this could return
0
or some other number? That is normally a valid return value forsetInterval
.How does similar code behave in browsers?
Edit: Chrome just returns 0. It is possible to call
setInterval
on a window after it closes, by calling it from another window.The text was updated successfully, but these errors were encountered: