예제 #1
0
        public static bool IsEquel(EcmaState state, EcmaValue x, EcmaValue y)
        {
            if (x.Type() == y.Type())
            {
                if (x.IsUndefined() || x.IsNull())
                {
                    return(true);
                }

                if (x.IsNumber())
                {
                    double xn = x.ToNumber(state);
                    double yn = y.ToNumber(state);

                    if (Double.IsNaN(xn) || Double.IsNaN(yn))
                    {
                        return(false);
                    }

                    if (xn == +0 && yn == -0 || xn == -0 && yn == +0)
                    {
                        return(true);
                    }
                    return(xn == yn);
                }

                if (x.IsString())
                {
                    return(x.ToString(state) == y.ToString(state));
                }

                if (x.IsBoolean())
                {
                    return(x.ToBoolean(state) == y.ToBoolean(state));
                }

                return(y.ToObject(state) == x.ToObject(state));
            }

            if (x.IsNull() && y.IsUndefined() || x.IsUndefined() && y.IsUndefined())
            {
                return(true);
            }

            if (!(x.IsNumber() || x.IsString()) && y.IsObject() || x.IsObject() && !(y.IsNumber() || y.IsString()))
            {
                return(x.ToPrimitiv(state) == y.ToPrimitiv(state));
            }
            return(x.ToNumber(state) == y.ToNumber(state));
        }
예제 #2
0
        public static EcmaValue Plus(EcmaState state, EcmaValue left, EcmaValue right)
        {
            if (left.ToPrimitiv(state) is String || right.ToPrimitiv(state) is String)
            {
                return(EcmaValue.String(left.ToString(state) + right.ToString(state)));
            }

            return(EcmaValue.Number(left.ToNumber(state) + right.ToNumber(state)));
        }
예제 #3
0
 public static EcmaValue Minus(EcmaState state, EcmaValue left, EcmaValue right)
 {
     return(EcmaValue.Number(left.ToNumber(state) - right.ToNumber(state)));
 }
예제 #4
0
 public static EcmaValue Gange(EcmaState state, EcmaValue left, EcmaValue right)
 {
     return(EcmaValue.Number(left.ToNumber(state) * right.ToNumber(state)));
 }
예제 #5
0
 public static EcmaValue Divide(EcmaState state, EcmaValue left, EcmaValue right)
 {
     return(EcmaValue.Number(left.ToNumber(state) / right.ToNumber(state)));
 }
예제 #6
0
 public static EcmaValue Remainder(EcmaState state, EcmaValue left, EcmaValue right)
 {
     return(EcmaValue.Number(left.ToNumber(state) % right.ToNumber(state)));
 }
예제 #7
0
        public static EcmaValue DoRelational(EcmaState state, EcmaValue left, EcmaValue right)
        {
            object l = left.ToPrimitiv(state);
            object r = right.ToPrimitiv(state);

            if (l is String && r is String)
            {
                string ls = l as String;
                string rs = r as String;
                if (ls.IndexOf(rs) == 0)
                {
                    return(EcmaValue.Boolean(false));
                }
                if (rs.IndexOf(ls) == 0)
                {
                    return(EcmaValue.Boolean(true));
                }
                char[] lc = ls.ToCharArray();
                char[] rc = rs.ToCharArray();

                for (int i = 0; i < Math.Min(ls.Length, rs.Length); i++)
                {
                    if (lc[i] > rc[i])
                    {
                        return(EcmaValue.Boolean(false));
                    }
                }

                return(EcmaValue.Boolean(true));
            }

            double x = left.ToNumber(state);
            double y = right.ToNumber(state);

            if (Double.IsNaN(x) || Double.IsNaN(y))
            {
                return(EcmaValue.Undefined());
            }

            if (x == y)
            {
                return(EcmaValue.Boolean(false));
            }

            if (x == -0 && y == +0 || x == +0 && y == -0)
            {
                return(EcmaValue.Boolean(false));
            }

            if (Double.IsPositiveInfinity(x) || Double.IsNegativeInfinity(y))
            {
                return(EcmaValue.Boolean(false));
            }

            if (Double.IsNegativeInfinity(x) || Double.IsPositiveInfinity(y))
            {
                return(EcmaValue.Boolean(true));
            }

            return(EcmaValue.Boolean(y > x));
        }