Stack overflow comparing Dates to strings

Dec 16, 2011 at 6:32 PM

I have code which involves a comparison between a date and a string constant, any time it his this I get a stack overflow inside Jint.ExecutionVisitor.Compare(JInstance x, JInstance y).

Here is some sample source code... although there are many variations on the problem. In the code the variable "MyDate" is a javascript Date

if (MyDate == "12/12/2011") "YES" else "NO"

The problem is here at line 806 in ExecutionVisitor.cs inside JsBoolean Compare(JsInstance x, JsInstance y)

            else if (x.Type == JsInstance.TYPE_OBJECT && (y.Type == JsInstance.TYPE_STRING || y.Type == JsInstance.TYPE_NUMBER))
Recursive call -->              return Compare(x.ToPrimitive(Global), y);

In this case x is a Jint.Native.JsDate, and ToPrimitive is just going to return another JsDate, so we recurse without termination, boom!

This seems to be since JsObject.ToPrimitive ends up doing this...

switch (Convert.GetTypeCode(Value)) {


  case TypeCode.DateTime:

return global.DateClass.New((DateTime)Value);

and DateClass.New then does this:
        public JsDate New(DateTime value) {
            return new JsDate(value.ToUniversalTime(), this.PrototypeProperty);


Dec 18, 2011 at 8:01 AM

Hi, the problem is described here

Dec 19, 2011 at 12:46 PM

Thanks, given the description in the bug, I think I can come up with a local fix.