PDA

View Full Version : [FIXED][3.0] Eval usage



lightglitch
15 Apr 2009, 3:29 PM
I'm wondering why do you still (in version 3) use the eval function is several parts of the code instead of using always the same function to parse JSON.

For example in the JSONReader:


readResponse : function(response) {
var json = response.responseText;
var o = eval("("+json+")");
if(!o) {
throw {message: "JsonReader.read: Json object not found"};
}
return o;
}
Why don't you just use:


var o = Ext.decode("("+json+")");

stever
15 Apr 2009, 4:03 PM
Yeah, when I mentioned it before (http://www.extjs.com/forum/showthread.php?t=64980) I forgot to mention readResponse as well as read...

evant
15 Apr 2009, 4:05 PM
Mostly just an oversight, it doesn't really affect much, but it would be nice to fix up.

lightglitch
15 Apr 2009, 4:18 PM
Yeah, when I mentioned it before (http://www.extjs.com/forum/showthread.php?t=64980) I forgot to mention readResponse as well as read...

I missed your thread, but I just give that as an example.

If you search for eval in ext-all-debug.js it's used in much more places and if the Ext.decode already takes in account the browser support for JSON, should be used everywhere.


Mostly just an oversight, it doesn't really affect much, but it would be nice to fix up.

Agree.

evant
16 Apr 2009, 5:04 AM
In a lot of places we still need to use eval(), the only outstanding place where it should use decode() is in the JsonReader, which I've just committed.