Problem with operators

Nov 3, 2010 at 8:24 PM

Hi, I found an odd behavior, which I think is a bug:

if you compare 2 strings, like in

alert('dd' > 'cc');

the result is False, and not True as it appears in a browser (I tried Firefox).


There is another possible problem with CLR DateTime type: it cannot be used in e.g. a comparison operator, as the cast to Double will fail for a DateTime type.

var dt = new Date();

alert (clrdt > dt);

where clrdt is an injected CLR object of type DateTime. The alert will fail with exception " Invalid cast from 'DateTime' to 'Double' "

Nov 10, 2010 at 5:20 PM

About the date comparison, I fixed the problem by modifying the ToNumber() method in JsClr:

        public override double ToNumber()
            if (value == null)
                return 0;
            // FIX: manage correctly the cast for CLR datetime type
            if (value is IConvertible)
                if (value is DateTime)
                    return JsDate.DateToDouble((DateTime)value);
                return Convert.ToDouble(value);
            return double.NaN;

Nov 10, 2010 at 5:28 PM

I would rather go further and add support for other clr objects by using a switch/case on the TypeCode. Thus we would handle bool, int, ... all comparisions against native js object. Could you try to make it ? Why not creating a fork for that, I would push your changes to the repository then. If you an also create some little tests ;)


Nov 16, 2010 at 2:03 PM

Hi Sebastien, peeking in the code, it is clear you'are right. We need to improve the BinaryExpression visitor. I'll try to implement the fixes (maybe a fork is too much, I may send you the code, but it's not that the problem).

The problem is that I must deliver a first version for my product and I need to "quick" fix date comparison. But after this delivery I should have some time to improve the BinaryExpr visitor and the tests.

Thanks to you for sharing us Jint!


PS: regarding dates, I've found another bug, I'll open a new discussion for that.

Nov 16, 2010 at 5:25 PM

I have just pushed the correction for this behavior on the source repository.

Please try it.