productive mode results "undefinded" "NaN"

39 views
Skip to first unread message

Jepse

unread,
Jul 3, 2012, 4:40:05 AM7/3/12
to google-we...@googlegroups.com
Hi there,

i'm using a simple JSNI Function:

        public static native boolean evalBoolean(String arg) /*-{
            return eval(arg);
        }-*/;
   
        public static native double evalCalculation(String arg) /*-{
            return eval(arg);
        }-*/;   

in development mode everything works fine. when i compile the project it results"undefined" and "NaN" values...

Any ideas?

Joseph Lust

unread,
Jul 3, 2012, 9:24:45 PM7/3/12
to google-we...@googlegroups.com
Please consider not using eval(). It is the source of a great many bugs and opens up many security holes.

For example, now you must be sure that your string being evaluated does not have any variable name conflicts with GWT. Since the GWT compiler minimizes variable names and methods to single letters, using "N" or "n" in your evaluated string will lead to seemingly random behaviors. This is possibly exactly the source of your errors.


Sincerely,
Joseph

Jepse

unread,
Jul 4, 2012, 4:28:46 AM7/4/12
to google-we...@googlegroups.com
I heard about that. for now, itts my only soloution to parse a simple formular. Or should i compose a JSNI like the following:


        public static native boolean evalBoolean(String arg) /*-{
            var i = arg;
            return i;
        }-*/;

Joseph Lust

unread,
Jul 4, 2012, 9:02:19 AM7/4/12
to google-we...@googlegroups.com
That will just try to convert a String to a boolean which will either be coerced to 1 (if not null or 0) or perhaps throw an error.

You say that your formulae are simple. Perhaps you can write a simple tokenizer/lexer.


Joe
Reply all
Reply to author
Forward
0 new messages