Inheritance: BinaryOp
Esempio n. 1
0
 // *** VS58565 - JSEE: Remove all uses of IDebugObject::GetManagedObject from the code ***
 // JSEE does a funceval to this method to compare if to value types are equal.
 public static new bool Equals(Object v1, Object v2){
   Equality e = new Equality((int)JSToken.Equal);
   return e.EvaluateEquality(v1, v2);
 }
Esempio n. 2
0
        AST EqExpr(AST parent, bool in_for_init)
        {
            AST pn = RelExpr (parent, in_for_init);
            ArrayList tokens = new ArrayList ();
            for (;;) {
                int tt = ts.PeekToken ();
                tokens.Add (tt);
                if (tt == Token.EQ || tt == Token.NE) {
                    foreach (int token in tokens)
                        decompiler.AddToken (token);
                    tokens.Clear ();

                    ts.GetToken ();
                    pn = new Equality (parent, pn, RelExpr (parent, in_for_init), ToJSToken (tt),
                           new Location (ts.SourceName, ts.LineNumber));
                    continue;
                } else if (tt == Token.SHEQ || tt == Token.SHNE) {
                    foreach (int token in tokens)
                        decompiler.AddToken (token);
                    tokens.Clear ();

                    ts.GetToken ();
                    pn = new StrictEquality (parent, pn, RelExpr (parent, in_for_init), ToJSToken (tt), new Location (ts.SourceName, ts.LineNumber));
                    continue;
                }
                break;
            }
            return pn;
        }
        private bool EvaluateEquality(Object v1, Object v2, bool checkForDebuggerObjects)
        {
            if (v1 is String && v2 is String)
            {
                return(v1.Equals(v2));
            }
            if (v1 is Int32 && v2 is Int32)
            {
                return(((int)v1) == (int)v2);
            }
            if (v1 is Double && v2 is Double)
            {
                return(((double)v1) == (double)v2);
            }
            if ((v2 == null || v2 is DBNull || v2 is Missing) && !checkForDebuggerObjects)
            {
                return(v1 == null || v1 is DBNull || v1 is Missing);
            }
            IConvertible ic1 = Convert.GetIConvertible(v1);
            IConvertible ic2 = Convert.GetIConvertible(v2);
            TypeCode     t1  = Convert.GetTypeCode(v1, ic1);
            TypeCode     t2  = Convert.GetTypeCode(v2, ic2);

            switch (t1)
            {
            case TypeCode.Empty:
            case TypeCode.DBNull:
                break;

            case TypeCode.Object:
                switch (t2)
                {
                case TypeCode.Empty:
                case TypeCode.DBNull:
                    break;

                default:
                    MethodInfo oper = this.GetOperator(v1.GetType(), v2.GetType());
                    if (oper != null)
                    {
                        bool result = (bool)oper.Invoke(null, (BindingFlags)0, JSBinder.ob, new Object[] { v1, v2 }, null);
                        if (this.operatorTok == JSToken.NotEqual)
                        {
                            return(!result);
                        }
                        return(result);
                    }
                    break;
                }
                break;

            default:
                switch (t2)
                {
                case TypeCode.Object:
                    MethodInfo oper = this.GetOperator(v1.GetType(), v2.GetType());
                    if (oper != null)
                    {
                        bool result = (bool)oper.Invoke(null, (BindingFlags)0, JSBinder.ob, new Object[] { v1, v2 }, null);
                        if (this.operatorTok == JSToken.NotEqual)
                        {
                            return(!result);
                        }
                        return(result);
                    }
                    break;
                }
                break;
            }
            return(Equality.JScriptEquals(v1, v2, ic1, ic2, t1, t2, checkForDebuggerObjects));
        }
        private static bool JScriptEquals(Object v1, Object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2, bool checkForDebuggerObjects)
        {
            if (StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, t1, t2, checkForDebuggerObjects))
            {
                return(true);
            }
            if (t2 == TypeCode.Boolean)
            {
                v2  = ic2.ToBoolean(null) ? 1 : 0;
                ic2 = Convert.GetIConvertible(v2);
                return(Equality.JScriptEquals(v1, v2, ic1, ic2, t1, TypeCode.Int32, false));
            }
            switch (t1)
            {
            case TypeCode.Empty: return(t2 == TypeCode.Empty || t2 == TypeCode.DBNull || (t2 == TypeCode.Object && v2 is Missing));

            case TypeCode.Object:
                switch (t2)
                {
                case TypeCode.Empty:
                case TypeCode.DBNull:
                    return(v1 is Missing);

                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                case TypeCode.String:
                    IConvertible pvic1 = ic1;
                    Object       pv1   = Convert.ToPrimitive(v1, PreferredType.Either, ref pvic1);
                    if (pvic1 != null && pv1 != v1)
                    {
                        return(Equality.JScriptEquals(pv1, v2, pvic1, ic2, pvic1.GetTypeCode(), t2, false));
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(false);

            case TypeCode.DBNull: return(t2 == TypeCode.DBNull || t2 == TypeCode.Empty || (t2 == TypeCode.Object && v2 is Missing));

            case TypeCode.Boolean:
                v1  = ic1.ToBoolean(null) ? 1 : 0;
                ic1 = Convert.GetIConvertible(v1);
                return(Equality.JScriptEquals(v1, v2, ic1, ic2, TypeCode.Int32, t2, false));

            case TypeCode.Char:
            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
            case TypeCode.UInt32:
            case TypeCode.Int64:
            case TypeCode.UInt64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                if (t2 == TypeCode.Object)
                {
                    IConvertible pvic2 = ic2;
                    Object       pv2   = Convert.ToPrimitive(v2, PreferredType.Either, ref pvic2);
                    if (pvic2 != null && pv2 != v2)
                    {
                        return(Equality.JScriptEquals(v1, pv2, ic1, pvic2, t1, pvic2.GetTypeCode(), false));
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (t2 == TypeCode.String)
                {
                    if (v1 is Enum)
                    {
                        return(Convert.ToString(v1).Equals(ic2.ToString(null)));
                    }
                    v2  = Convert.ToNumber(v2, ic2);
                    ic2 = Convert.GetIConvertible(v2);
                    return(StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, t1, TypeCode.Double, false));
                }
                return(false);

            case TypeCode.DateTime:
                if (t2 == TypeCode.Object)
                {
                    IConvertible pvic2 = ic2;
                    Object       pv2   = Convert.ToPrimitive(v2, PreferredType.Either, ref pvic2);
                    if (pv2 != null && pv2 != v2)
                    {
                        return(StrictEquality.JScriptStrictEquals(v1, pv2, ic1, pvic2, t1, pvic2.GetTypeCode(), false));
                    }
                }
                return(false);

            case TypeCode.String:
                switch (t2)
                {
                case TypeCode.Object: {
                    IConvertible pvic2 = ic2;
                    Object       pv2   = Convert.ToPrimitive(v2, PreferredType.Either, ref pvic2);
                    if (pvic2 != null && pv2 != v2)
                    {
                        return(Equality.JScriptEquals(v1, pv2, ic1, pvic2, t1, pvic2.GetTypeCode(), false));
                    }
                    else
                    {
                        return(false);
                    }
                }

                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                    if (v2 is Enum)
                    {
                        return(Convert.ToString(v2).Equals(ic1.ToString(null)));
                    }
                    v1  = Convert.ToNumber(v1, ic1);
                    ic1 = Convert.GetIConvertible(v1);
                    return(StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, TypeCode.Double, t2, false));
                }
                return(false);
            }
            return(false);
        }
        // *** VS58565 - JSEE: Remove all uses of IDebugObject::GetManagedObject from the code ***
        // JSEE does a funceval to this method to compare if to value types are equal.
        public static new bool Equals(Object v1, Object v2)
        {
            Equality e = new Equality((int)JSToken.Equal);

            return(e.EvaluateEquality(v1, v2));
        }
 public static bool Equals(object v1, object v2)
 {
     Equality equality = new Equality(0x35);
     return equality.EvaluateEquality(v1, v2);
 }