コード例 #1
0
        public static SObject IsFinite(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
            {
                return(processor.Undefined);
            }

            var parameterAsNumber = parameters[0] as SNumber;
            var dbl = parameterAsNumber?.Value ?? parameters[0].ToNumber(processor).Value;

            return(processor.CreateBool(!(double.IsNaN(dbl) || double.IsInfinity(dbl))));
        }
コード例 #2
0
 public static SObject ToPrimitive(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
 {
     if (parameters.Length == 0)
     {
         return(processor.Undefined);
     }
     if (parameters[0] is SString)
     {
         return(processor.CreateString(((SString)parameters[0]).Value));
     }
     if (parameters[0] is SNumber)
     {
         return(processor.CreateNumber(((SNumber)parameters[0]).Value));
     }
     if (parameters[0] is SBool)
     {
         return(processor.CreateBool(((SBool)parameters[0]).Value));
     }
     return(parameters[0]); // returns the input object, if no conversion was conducted.
 }
コード例 #3
0
        public static SObject IsNaN(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length == 0)
            {
                return(processor.Undefined);
            }

            double dbl;

            if (parameters[0] is SNumber)
            {
                dbl = ((SNumber)parameters[0]).Value;
            }
            else
            {
                dbl = parameters[0].ToNumber(processor).Value;
            }

            return(processor.CreateBool(double.IsNaN(dbl)));
        }