Skip to content
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

Maximum call stack size exceeded when extending global with parentWindow #729

Closed
JacksonGariety opened this issue Jan 23, 2014 · 4 comments

Comments

@JacksonGariety
Copy link

I've noticed when extending the global variable with jsdom().parentWindow, and also including a large library such as bluebird or engine.io, JSDOM errors with a maximum call stack size exceeded.

JSDOM does continue to function if wrapped in a try...catch statement, so would it be possible to gracefully handle this error within JSDOM?

_(global).extend(jsdom().parentWindow)
var engine = require('engine.io')

Results in:

node_modules/jsdom/lib/jsdom/browser/index.js:121
this.setTimeout = function (fn, ms) { return startTimer(setTimeout, clearT
                           ^
RangeError: Maximum call stack size exceeded

I understand the use case is quite bizarre, but I'm curious as to what this error really means.

@JacksonGariety
Copy link
Author

This is an issue because jsdom's window.setTimeout contains a call to global.setTimeout. When they are the same, there's a stack overflow.

Since NodeJS has setTimeout, is there any reason window.setTimeout can't just be a clone of the native function?

@brianmcd
Copy link
Contributor

It's been a while since I've worked on JSDOM, but IIRC the JSDOM timer implementation keeps track of open timers so we can cancel them in window.close to avoid memory leaks from dangling timers.

@JacksonGariety
Copy link
Author

@brianmcd ahhhh I see why it's doing this now.

If any crazy people have this problem in the future, use _.defaults instead of _.extend to avoid this issue.

@grahaml
Copy link

grahaml commented Nov 19, 2014

So happy you posted your last comment about using defaults instead of extend. Thanks @JacksonGariety!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants