Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#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 + ")");
},

Change History (2)

comment:1 Changed 14 years ago by alex

Resolution: fixed
Status: newclosed

fixed in [2976]

comment:2 Changed 12 years ago by (none)

Milestone: 0.3release

Milestone 0.3release deleted

Note: See TracTickets for help on using tickets.