Beispiel #1
0
        private double ConstructTimeValue(JsValue[] arguments, bool useUtc)
        {
            if (arguments.Length < 2)
            {
                throw new ArgumentOutOfRangeException("arguments", "There must be at least two arguments.");
            }

            var y     = TypeConverter.ToNumber(arguments[0]);
            var m     = (int)TypeConverter.ToInteger(arguments[1]);
            var dt    = arguments.Length > 2 ? (int)TypeConverter.ToInteger(arguments[2]) : 1;
            var h     = arguments.Length > 3 ? (int)TypeConverter.ToInteger(arguments[3]) : 0;
            var min   = arguments.Length > 4 ? (int)TypeConverter.ToInteger(arguments[4]) : 0;
            var s     = arguments.Length > 5 ? (int)TypeConverter.ToInteger(arguments[5]) : 0;
            var milli = arguments.Length > 6 ? (int)TypeConverter.ToInteger(arguments[6]) : 0;

            for (int i = 2; i < arguments.Length; i++)
            {
                if (double.IsNaN(TypeConverter.ToNumber(arguments[i])))
                {
                    return(double.NaN);
                }
            }

            if ((!double.IsNaN(y)) && (0 <= TypeConverter.ToInteger(y)) && (TypeConverter.ToInteger(y) <= 99))
            {
                y += 1900;
            }

            var finalDate = DatePrototype.MakeDate(
                DatePrototype.MakeDay(y, m, dt),
                DatePrototype.MakeTime(h, min, s, milli));

            return(TimeClip(useUtc ? finalDate : PrototypeObject.Utc(finalDate)));
        }
        public static DatePrototype CreatePrototypeObject(Engine engine, DateConstructor dateConstructor)
        {
            var obj = new DatePrototype(engine)
            {
                Prototype      = engine.Object.PrototypeObject,
                Extensible     = true,
                PrimitiveValue = double.NaN
            };

            obj.FastAddProperty("constructor", dateConstructor, true, false, true);

            return(obj);
        }
Beispiel #3
0
        public static DateConstructor CreateDateConstructor(Engine engine)
        {
            var obj = new DateConstructor(engine);

            obj.Extensible = true;

            // The value of the [[Prototype]] internal property of the Date constructor is the Function prototype object
            obj.Prototype       = engine.Function.PrototypeObject;
            obj.PrototypeObject = DatePrototype.CreatePrototypeObject(engine, obj);

            obj.FastAddProperty("length", 7, false, false, false);

            // The initial value of Date.prototype is the Date prototype object
            obj.FastAddProperty("prototype", obj.PrototypeObject, false, false, false);

            return(obj);
        }