Short circuit problem

Oct 15, 2010 at 4:28 PM

Hi, another "boss test" issue:


if (x==NUL || y==NULL || x==undefined || y==undefined || x<0 || y<0) return perp;

Jint gives no error related to the wrong "NUL" writing for the first condition: perhaps, I thought, it makes a short circuit evaluation of the boolean condition.

I think it's not correct, what do you think about?

Thank you


Oct 20, 2010 at 3:26 PM

If x and y and NUL are not initialized beore the test, as null == undefined, then they are all equal in the sense of '=='. Just try it in a browser to verify.

You can also allow the Option.Strict which will prevent you from using undeclared varialbes, and limiting the possibility of such issues.

Oct 21, 2010 at 2:37 PM

This is the complete script:

var foo = 0;
var x = undefined;
var y = 2;

if (x==NUL || y==NULL || x==undefined || y==undefined || x<0 || y<0)
  foo = 1;
  foo = 2;

alert(foo.toString()); //added for browsers

These are browsers behaviours:

Firefox (with firebug): reports two "NUL is not defined" errors and doesn't show the alert popup;

IE8: reports one "Error: 'NUL' is not defined", proposes to debug the script and completes it when pressing Continue showing the alert popup with "1" as result;

Chrome: reports one "Uncaught ReferenceError: NUL is not defined" and doesn't show the alert popup;

I don't know if and which of them follows Ecmascript 3 or 5 with or without strict mode, but I couldn't manage to achieve the behaviour you said above (prevent from using undeclared variables) even if using Ecmascript 5 and Strict mode in Options.

Actually I'm calling something like

jintEngine = new JintEngine(Jint.Options.Strict | Jint.Options.Ecmascript5);

[...] (jintEngine.Run and so on)

but no exception is thrown at all and the script is executed with "1" as result. Can you see something wrong?

Thank you again


Oct 21, 2010 at 3:42 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.