json-stringify-safe
json-stringify-safe copied to clipboard
RangeError: Maximum call stack size exceeded
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
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
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)
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?
Oh, right, toJSON should probably be called as well and before the circular detection.
I'll get to it, too!
+1 This module is used within raven's sentry and this has become an issue on a project I'm working on.
ACK. ;)
Similar to jQuery, this issue is occurring when used with Cheerio. Crashing the browser when stringifying Cheerio objects.
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
This issue causes an error in bunyan logger. The whole app crashes and being recycled.