Jsdom: Maximum call stack size exceeded when extending global with parentWindow

Created on 23 Jan 2014  路  4Comments  路  Source: jsdom/jsdom

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.

Most helpful comment

@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.

All 4 comments

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?

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.

@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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

domenic picture domenic  路  3Comments

lehni picture lehni  路  4Comments

philipwalton picture philipwalton  路  4Comments

jacekpl picture jacekpl  路  4Comments

jhegedus42 picture jhegedus42  路  4Comments