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; }
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); }
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); }
/// <summary> /// http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.3 /// </summary> /// <param name="arguments"></param> /// <returns></returns> public ObjectInstance Construct(JsValue[] arguments) { if (arguments.Length == 0) { return(Construct(DateTime.Now)); } else if (arguments.Length == 1) { var v = TypeConverter.ToPrimitive(arguments[0]); if (v.IsString()) { return(Parse(Undefined.Instance, Arguments.From(v)).AsObject()); } return(Construct(DatePrototype.TimeClip(TypeConverter.ToNumber(v)))); } else { 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(Construct(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(Construct(DatePrototype.TimeClip(DatePrototype.Utc(finalDate)))); } }