#375 closed defect (fixed)
dojo.json.evalJson never returns the eval results?
Reported by: | skinner | Owned by: | anonymous |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Core | Version: | 0.2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Currently, the dojo.json.evalJson definition looks like this:
evalJson: function(/* jsonString */ json){ // FIXME: should this accept mozilla's optional second arg? try { return eval("(" + json + ")"); }catch(e){ dojo.debug(e); }finally{ return json; } },
In Firefox 1.5, I think the finally block *always* executes, which means that the evalJson() always returns the same string as it was passed, rather than returning the results of the eval() call.
I think you want this instead:
evalJson: function(/* jsonString */ json){ // FIXME: should this accept mozilla's optional second arg? try { return eval("(" + json + ")"); }catch(e){ dojo.debug(e); return json; } },
For what it's worth, my own personal preference would be to *not* have evalJson() squelch exceptions. If you squelch the expection, then in order for the calling code to check for errors it has to test to see if the return value is the same as the string that was passed in, which (a) may happen even if there was not an error, and (b) is more inconvenient and more cryptic than just wrapping the evalJson() call in a try block. So, my vote is for going back to just this:
evalJson: function(/* jsonString */ json){ // FIXME: should this accept mozilla's optional second arg? return eval("(" + json + ")"); },
fixed in [2976]