Opened 11 years ago
Closed 10 years ago
#13079 closed defect (wontfix)
infinitely recursive object when calling dojo.toJson(dojo)
Reported by: | rott | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | high | Milestone: | 1.8 |
Component: | Core | Version: | 1.6.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description (last modified by )
This bug is similar to h#12867
SVN rev [25191]. Using Chrome browser.
If I call dojo.toJson(dojo) I get the error:
Uncaught TypeError: Converting circular structure to JSON
A possible fix is to add this clause to the conditional in dojo.js at line 153:
(hasCache[name]===undefined || force) && (name != 'json-stringify') && (hasCache[name] = test);
I'm pretty sure that's not the right fix, but I'm hoping it's a good enough clue to figure out what's going on. What that added conditional, I can now call dojo.toJson(dojo)
Change History (7)
comment:1 Changed 11 years ago by
Description: | modified (diff) |
---|---|
Owner: | set to Kris Zyp |
comment:2 Changed 11 years ago by
Fair point, but in the interest of disclosing the *real* problem... :)
Use of analytics, and the dojox.analytics.plugins.window plugin effectively results in a call to dojo.toJson(dojo) or dojo.toJson(window) which results in the infinite recursion problem. How about this as a fix; add the following line just below the assignment for 'hasCache' at line 150, so we would have lines 150 and 151 as:
hasCache = has.cache = defaultConfig.hasCache; hasCache.__json__ = function() {};
Just throwing some ideas out there. This solves the problem for me, but again, don't know for sure that it's a good solution. Perhaps it is due to it only affecting json serialization of the hasCache object and nothing else.
comment:3 Changed 11 years ago by
That's seriously the only place where there is a circular reference in Dojo? I would bet if you load some more modules you would get a lot more circular references.
comment:4 Changed 11 years ago by
If this is for analaytics/debugging purposes, it seems like you want to use a real inspector/JavaScript serializer, JSON serialization seems like the wrong tool for the job.
comment:5 Changed 11 years ago by
That's just the only one I've found so far. I'm not understanding your suggestion for a "real inspector/JavaScript serializer", though. I can dig into dojox.analytics to see what the genesis and inspiration was for it. Perhaps it needs some re-working. Thanks! If your assertion is that dojox.analytics needs fixed, then we can close this ticket. If you would please, and if you have some, provide some pointers to alternatives to serializing to json for the analytics package.
comment:6 Changed 11 years ago by
The serializer that Node use's for it's REPL is great (handles circular references, functions, dates, etc): https://github.com/joyent/node/blob/master/lib/util.js#L62-276
comment:7 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Presumably this is an invalid ticket since the second line of the dojo.toJson() documentation says that it doesn't work on objects with loops:
It's also not supposed to work on objects with functions in them.