View Full Version : YAHOO.ext.util.JSON.encode() infinite loop on CustomEvents

20 Dec 2006, 7:55 AM
If found that the encode() method infinitely loops when an object contains CustomEvent objects within it. I had to add the following condition to the list of conditions starting on line 95 of JSON.js:

else if(o instanceof YAHOO.util.CustomEvent) {
return 'null';

Is there a better way to solve this Jack?

20 Dec 2006, 2:13 PM
The implementation is based on Crockford's JSON encode and objects with circular references are not supported (there's no easy way to detect it). I know it's a pain, but you might consider adding a method to your class such as toObject or something that returns an object literal with the values you really want to encode.

20 Dec 2006, 3:32 PM
Dang, that adds a serious amount of overhead to our simple objects. It'll be easier for me to special case those object types with circular refs. If you find a better solution please let me know :) Thanks!