WebReflection/circular-json

Following Test Case failed

devilankur18 opened this issue · 4 comments

Check this jsfiddle http://jsfiddle.net/devilankur18/WCzyD/

var foo = {1 : window}

 CircularJSON.stringify(foo);

Its throwing error Uncaught RangeError: Maximum call stack size exceeded

Serializing the environment is not a good idea but yeah, I understand that should not fail. I wonder what would you expect in any case to happen when you try to serialize the global context.

The serialization and deserialization mostly happens for sending and receiving data.

This use case occurs when we trying to send big objects to server.

If some object has a reference to global object then either there should be option to get a callback where developer can return whatever he wants. OR it should be replace with some string like for above example it would return {1 : "[OBJECT WINDOW] " }

The serialization and deserialization mostly happens for sending and receiving data.

precisely, not sending or receiving the global object so this is a non issue since that would fail in any case with JSON too.

[Object Window] is not an option because of CircularJSON aim which is to deserialize same way, however the stack of the global object is massive and JSON can fail indeed.

CircularJSON is not a JSON replacement so this might end up being a won't fix as soon as I discover you can pass a receiver and get rid of the global object.

EDIT To be honest and more explicit: you don't need to pass window/global object around ... and you should not do that indeed, because JSON is compatible cross platform, is not a Web thing, and window on web and on a browser, is not the same window on another. I close this

I am talking about use cases when normal json object have references to the global objects. Just like foo has reference for window object. There are pretty common use cases.

The serialization normally fails due to the improper references to global object. I think it might make sense to convert these references to string.

if( property === window ) { 
  return "[OBJECT window]" ;
}

What do you say ?