json-stringify-safe icon indicating copy to clipboard operation
json-stringify-safe copied to clipboard

RangeError: Maximum call stack size exceeded

Open benbuckman opened this issue 12 years ago • 9 comments

This breaks with any Backbone view (I assume an example of a common type of object). For example, with backbone, in Chrome, in the console:

safeStringify = require('safe-json-stringify')
m = new Backbone.Model
v = new Backbone.View({ model: m })
safeStringify(v)

Throws an error, "RangeError: Maximum call stack size exceeded"

With the model (m), interestingly, it doesn't throw an error, but it writes an empty object, "{}".

Is this supposed to work only on simple objects, not instances of pseudo-classes?

Thanks

benbuckman avatar Jul 31 '13 19:07 benbuckman

I think it's returning a stringified empty object for the model in that case, because the model's attributes are empty, and it's using toJSON to retrieve the attributes. (I didn't realize JSON.stringify checks toJSON, good to know.) The view error is still a problem, anyway.

Thanks

benbuckman avatar Jul 31 '13 19:07 benbuckman

This also fails with a jquery element:

safeStringify = require('safe-json-stringify')
$ = require('jquery')
safeStringify( $('<div>') )

Throws a

TypeError: Accessing selectionDirection on an input element that cannot have a selection.

Normal JSON.stringify throws a

TypeError: Converting circular structure to JSON

(but I was hoping this module would mitigate that situation)

benbuckman avatar Jul 31 '13 23:07 benbuckman

I also had a max call stack crash on a DOM event I was trying to stringify. My browser tab actually froze up from it. Maybe it should limit recursion somehow?

davedx avatar Jun 13 '14 07:06 davedx

Oh, right, toJSON should probably be called as well and before the circular detection. I'll get to it, too!

moll avatar Mar 03 '15 20:03 moll

+1 This module is used within raven's sentry and this has become an issue on a project I'm working on.

macdja38 avatar Feb 23 '17 12:02 macdja38

ACK. ;)

moll avatar Feb 23 '17 12:02 moll

Similar to jQuery, this issue is occurring when used with Cheerio. Crashing the browser when stringifying Cheerio objects.

joshiefishbein avatar Nov 07 '19 19:11 joshiefishbein

This issue still exists, in my case causing an infinite loop until the browser runs out of resources. Trying to serialize an thrown exception in an Angular application

zakhenry avatar Mar 26 '20 21:03 zakhenry

This issue causes an error in bunyan logger. The whole app crashes and being recycled.

ilog2000 avatar Feb 02 '21 17:02 ilog2000