Ejemplo n.º 1
0
        public override IDynamic Op_Equals(IDynamic other)
        {
            switch (other.TypeCode)
            {
            case LanguageTypeCode.String:
                return(this.Op_Equals(other.ConvertToNumber()));

            case LanguageTypeCode.Number:
                var lnum = (LNumber)other;
                return(Environment.CreateBoolean(!(double.IsNaN(BaseValue) || double.IsNaN(lnum.BaseValue)) && this.BaseValue == lnum.BaseValue));

            case LanguageTypeCode.Object:
                return(this.Op_Equals(other.ConvertToPrimitive(null)));

            default:
                return(Environment.False);
            }
        }
Ejemplo n.º 2
0
        public virtual IDynamic Op_Addition(IDynamic other)
        {
            var lprim = this.ConvertToPrimitive(null);
            var rprim = other.ConvertToPrimitive(null);

            if (lprim.TypeCode == LanguageTypeCode.String || rprim.TypeCode == LanguageTypeCode.String)
            {
                var lstr = (string)lprim.ConvertToString().BaseValue;
                var rstr = (string)rprim.ConvertToString().BaseValue;
                return(Environment.CreateString(lstr + rstr));
            }
            else
            {
                var lnum = (double)lprim.ConvertToNumber().BaseValue;
                var rnum = (double)rprim.ConvertToNumber().BaseValue;
                return(Environment.CreateNumber(lnum + rnum));
            }
        }
Ejemplo n.º 3
0
        private IDynamic RelationalComparison(bool leftFirst, IDynamic left, IDynamic right)
        {
            IDynamic px, py;

            if (leftFirst)
            {
                px = left.ConvertToPrimitive("Number");
                py = right.ConvertToPrimitive("Number");
            }
            else
            {
                py = right.ConvertToPrimitive("Number");
                px = left.ConvertToPrimitive("Number");
            }
            if (px.TypeCode == LanguageTypeCode.String && py.TypeCode == LanguageTypeCode.String)
            {
                string sx = (string)px.ConvertToString().BaseValue, sy = (string)py.ConvertToString().BaseValue;
                if (sx.StartsWith(sy))
                {
                    return(Environment.False);
                }
                else if (sy.StartsWith(sx))
                {
                    return(Environment.True);
                }
                else
                {
                    return(Environment.CreateBoolean(sx.CompareTo(sy) < 0));
                }
            }
            else
            {
                double nx = (double)px.ConvertToNumber().BaseValue, ny = (double)py.ConvertToNumber().BaseValue;
                if (double.IsNaN(nx) || double.IsNaN(ny))
                {
                    return(Environment.Undefined);
                }
                else if (nx != ny)
                {
                    if (double.IsPositiveInfinity(nx))
                    {
                        return(Environment.False);
                    }
                    else if (double.IsPositiveInfinity(ny))
                    {
                        return(Environment.True);
                    }
                    else if (double.IsNegativeInfinity(ny))
                    {
                        return(Environment.False);
                    }
                    else if (double.IsNegativeInfinity(nx))
                    {
                        return(Environment.True);
                    }
                    else
                    {
                        return(Environment.CreateBoolean(nx < ny));
                    }
                }
                return(Environment.False);
            }
        }
Ejemplo n.º 4
0
 private IDynamic RelationalComparison(bool leftFirst, IDynamic left, IDynamic right)
 {
     IDynamic px, py;
     if (leftFirst)
     {
         px = left.ConvertToPrimitive("Number");
         py = right.ConvertToPrimitive("Number");
     }
     else
     {
         py = right.ConvertToPrimitive("Number");
         px = left.ConvertToPrimitive("Number");
     }
     if (px.TypeCode == LanguageTypeCode.String && py.TypeCode == LanguageTypeCode.String)
     {
         string sx = (string)px.ConvertToString().BaseValue, sy = (string)py.ConvertToString().BaseValue;
         if (sx.StartsWith(sy))
         {
             return Environment.False;
         }
         else if (sy.StartsWith(sx))
         {
             return Environment.True;
         }
         else
         {
             return Environment.CreateBoolean(sx.CompareTo(sy) < 0);
         }
     }
     else
     {
         double nx = (double)px.ConvertToNumber().BaseValue, ny = (double)py.ConvertToNumber().BaseValue;
         if (double.IsNaN(nx) || double.IsNaN(ny))
         {
             return Environment.Undefined;
         }
         else if (nx != ny)
         {
             if (double.IsPositiveInfinity(nx))
             {
                 return Environment.False;
             }
             else if (double.IsPositiveInfinity(ny))
             {
                 return Environment.True;
             }
             else if (double.IsNegativeInfinity(ny))
             {
                 return Environment.False;
             }
             else if (double.IsNegativeInfinity(nx))
             {
                 return Environment.True;
             }
             else
             {
                 return Environment.CreateBoolean(nx < ny);
             }
         }
         return Environment.False;
     }
 }
Ejemplo n.º 5
0
 public virtual IDynamic Op_Addition(IDynamic other)
 {
     var lprim = this.ConvertToPrimitive(null);
     var rprim = other.ConvertToPrimitive(null);
     if (lprim.TypeCode == LanguageTypeCode.String || rprim.TypeCode == LanguageTypeCode.String)
     {
         var lstr = (string)lprim.ConvertToString().BaseValue;
         var rstr = (string)rprim.ConvertToString().BaseValue;
         return Environment.CreateString(lstr + rstr);
     }
     else
     {
         var lnum = (double)lprim.ConvertToNumber().BaseValue;
         var rnum = (double)rprim.ConvertToNumber().BaseValue;
         return Environment.CreateNumber(lnum + rnum);
     }
 }
Ejemplo n.º 6
0
 public override IDynamic Op_Equals(IDynamic other)
 {
     switch (other.TypeCode)
     {
         case LanguageTypeCode.String:
             return this.Op_Equals(other.ConvertToNumber());
         case LanguageTypeCode.Number:
             var lnum = (LNumber)other;
             return Environment.CreateBoolean(!(double.IsNaN(BaseValue) || double.IsNaN(lnum.BaseValue)) && this.BaseValue == lnum.BaseValue);
         case LanguageTypeCode.Object:
             return this.Op_Equals(other.ConvertToPrimitive(null));
         default:
             return Environment.False;
     }
 }