public JsBoolean Compare(JsInstance x, JsInstance y) { if (x.IsClr && y.IsClr) { return Global.BooleanClass.New(x.Value.Equals(y.Value)); } if (x.IsClr) { return Compare(x.ToPrimitive(Global), y); } if (y.IsClr) { return Compare(x, y.ToPrimitive(Global)); } if (x.Type == y.Type) { // if both are Objects but then only one is Clrs if (x == JsUndefined.Instance) { return Global.BooleanClass.True; } else if (x == JsNull.Instance) { return Global.BooleanClass.True; } else if (x.Type == JsInstance.TYPE_NUMBER) { if (x.ToNumber() == double.NaN) { return Global.BooleanClass.False; } else if (y.ToNumber() == double.NaN) { return Global.BooleanClass.False; } else if (x.ToNumber() == y.ToNumber()) { return Global.BooleanClass.True; } else { return Global.BooleanClass.False; } } else if (x.Type == JsInstance.TYPE_STRING) { return Global.BooleanClass.New(x.ToString() == y.ToString()); } else if (x.Type == JsInstance.TYPE_BOOLEAN) { return Global.BooleanClass.New(x.ToBoolean() == y.ToBoolean()); } else if (x.Type == JsInstance.TYPE_OBJECT ) { return Global.BooleanClass.New(x == y); } else { return Global.BooleanClass.New(x.Value.Equals(y.Value)); } } else if (x == JsNull.Instance && y == JsUndefined.Instance) { return Global.BooleanClass.True; } else if (x == JsUndefined.Instance && y == JsNull.Instance) { return Global.BooleanClass.True; } else if (x.Type == JsInstance.TYPE_NUMBER && y.Type == JsInstance.TYPE_STRING) { return Global.BooleanClass.New(x.ToNumber() == y.ToNumber()); } else if (x.Type == JsInstance.TYPE_STRING && y.Type == JsInstance.TYPE_NUMBER) { return Global.BooleanClass.New(x.ToNumber() == y.ToNumber()); } else if (x.Type == JsInstance.TYPE_BOOLEAN || y.Type == JsInstance.TYPE_BOOLEAN) { return Global.BooleanClass.New(x.ToNumber() == y.ToNumber()); } else if (y.Type == JsInstance.TYPE_OBJECT && (x.Type == JsInstance.TYPE_STRING || x.Type == JsInstance.TYPE_NUMBER)) { return Compare(x, y.ToPrimitive(Global)); } else if (x.Type == JsInstance.TYPE_OBJECT && (y.Type == JsInstance.TYPE_STRING || y.Type == JsInstance.TYPE_NUMBER)) { return Compare(x.ToPrimitive(Global), y); } else { return Global.BooleanClass.False; } }