internal Completion Evaluate(object expression)
 {
     if (StrictEquality.JScriptStrictEquals(this.case_value.Evaluate(), expression))
     {
         return((Completion)this.statements.Evaluate());
     }
     return(null);
 }
Example #2
0
        internal static bool JScriptStrictEquals(Object v1, Object v2, bool checkForDebuggerObjects)
        {
            IConvertible ic1 = Convert.GetIConvertible(v1);
            IConvertible ic2 = Convert.GetIConvertible(v2);
            TypeCode     t1  = Convert.GetTypeCode(v1, ic1);
            TypeCode     t2  = Convert.GetTypeCode(v2, ic2);

            return(StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, t1, t2, checkForDebuggerObjects));
        }
Example #3
0
 internal Completion Evaluate(Object expression)
 {
     Debug.PreCondition(this.case_value != null);
     if (StrictEquality.JScriptStrictEquals(this.case_value.Evaluate(), expression))
     {
         return((Completion)this.statements.Evaluate());
     }
     else
     {
         return(null);
     }
 }
Example #4
0
 public override string ToString()
 {
     if (this.name != null)
     {
         return(this.name);
     }
     foreach (FieldInfo info in this.type.GetFields(BindingFlags.Public | BindingFlags.Static))
     {
         if (StrictEquality.JScriptStrictEquals(this.value, info.GetValue(null)))
         {
             return(info.Name);
         }
     }
     return(Microsoft.JScript.Convert.ToString(this.value));
 }
Example #5
0
 public override String ToString()
 {
     if (this.name != null)
     {
         return(this.name);
     }
     FieldInfo[] fields = this.type.GetFields(BindingFlags.Static | BindingFlags.Public);
     foreach (FieldInfo field in fields)
     {
         if (StrictEquality.JScriptStrictEquals(this.value, field.GetValue(null)))
         {
             return(field.Name);
         }
     }
     return(Convert.ToString(this.value));
 }
Example #6
0
        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 = Microsoft.JScript.Convert.GetIConvertible(v2);
                return(JScriptEquals(v1, v2, ic1, ic2, t1, TypeCode.Int32, false));
            }
            switch (t1)
            {
            case TypeCode.Empty:
                if ((t2 == TypeCode.Empty) || (t2 == TypeCode.DBNull))
                {
                    return(true);
                }
                if (t2 != TypeCode.Object)
                {
                    return(false);
                }
                return(v2 is Microsoft.JScript.Missing);

            case TypeCode.Object:
                switch (t2)
                {
                case TypeCode.Empty:
                case TypeCode.DBNull:
                    return(v1 is Microsoft.JScript.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 ic   = ic1;
                    object       obj2 = Microsoft.JScript.Convert.ToPrimitive(v1, PreferredType.Either, ref ic);
                    return(((ic != null) && (obj2 != v1)) && JScriptEquals(obj2, v2, ic, ic2, ic.GetTypeCode(), t2, false));
                }
                }
                break;

            case TypeCode.DBNull:
                if ((t2 == TypeCode.DBNull) || (t2 == TypeCode.Empty))
                {
                    return(true);
                }
                if (t2 != TypeCode.Object)
                {
                    return(false);
                }
                return(v2 is Microsoft.JScript.Missing);

            case TypeCode.Boolean:
                v1  = ic1.ToBoolean(null) ? 1 : 0;
                ic1 = Microsoft.JScript.Convert.GetIConvertible(v1);
                return(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)
                {
                    if (t2 != TypeCode.String)
                    {
                        return(false);
                    }
                    if (v1 is Enum)
                    {
                        return(Microsoft.JScript.Convert.ToString(v1).Equals(ic2.ToString(null)));
                    }
                    v2  = Microsoft.JScript.Convert.ToNumber(v2, ic2);
                    ic2 = Microsoft.JScript.Convert.GetIConvertible(v2);
                    return(StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, t1, TypeCode.Double, false));
                }
                IConvertible convertible2 = ic2;
                object       obj3         = Microsoft.JScript.Convert.ToPrimitive(v2, PreferredType.Either, ref convertible2);
                if ((convertible2 == null) || (obj3 == v2))
                {
                    return(false);
                }
                return(JScriptEquals(v1, obj3, ic1, convertible2, t1, convertible2.GetTypeCode(), false));
            }

            case TypeCode.DateTime:
            {
                if (t2 != TypeCode.Object)
                {
                    goto Label_0236;
                }
                IConvertible convertible3 = ic2;
                object       obj4         = Microsoft.JScript.Convert.ToPrimitive(v2, PreferredType.Either, ref convertible3);
                if ((obj4 == null) || (obj4 == v2))
                {
                    goto Label_0236;
                }
                return(StrictEquality.JScriptStrictEquals(v1, obj4, ic1, convertible3, t1, convertible3.GetTypeCode(), false));
            }

            case TypeCode.String:
                switch (t2)
                {
                case TypeCode.Object:
                {
                    IConvertible convertible4 = ic2;
                    object       obj5         = Microsoft.JScript.Convert.ToPrimitive(v2, PreferredType.Either, ref convertible4);
                    return(((convertible4 != null) && (obj5 != v2)) && JScriptEquals(v1, obj5, ic1, convertible4, t1, convertible4.GetTypeCode(), 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(Microsoft.JScript.Convert.ToString(v2).Equals(ic1.ToString(null)));
                    }
                    v1  = Microsoft.JScript.Convert.ToNumber(v1, ic1);
                    ic1 = Microsoft.JScript.Convert.GetIConvertible(v1);
                    return(StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, TypeCode.Double, t2, false));
                }
                return(false);

            default:
                return(false);
            }
            return(false);

Label_0236:
            return(false);
        }
Example #7
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;
        }
Example #8
0
 public static bool JScriptStrictEquals(Object v1, Object v2)
 {
     return(StrictEquality.JScriptStrictEquals(v1, v2, false));
 }
        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);
        }