static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState* exec) { double doubleArguments[7] = { exec->argument(0).toNumber(exec), exec->argument(1).toNumber(exec), exec->argument(2).toNumber(exec), exec->argument(3).toNumber(exec), exec->argument(4).toNumber(exec), exec->argument(5).toNumber(exec), exec->argument(6).toNumber(exec) }; int n = exec->argumentCount(); if (isnan(doubleArguments[0]) || isnan(doubleArguments[1]) || (n >= 3 && isnan(doubleArguments[2])) || (n >= 4 && isnan(doubleArguments[3])) || (n >= 5 && isnan(doubleArguments[4])) || (n >= 6 && isnan(doubleArguments[5])) || (n >= 7 && isnan(doubleArguments[6]))) return JSValue::encode(jsNaN()); GregorianDateTime t; int year = JSC::toInt32(doubleArguments[0]); t.setYear((year >= 0 && year <= 99) ? (year + 1900) : year); t.setMonth(JSC::toInt32(doubleArguments[1])); t.setMonthDay((n >= 3) ? JSC::toInt32(doubleArguments[2]) : 1); t.setHour(JSC::toInt32(doubleArguments[3])); t.setMinute(JSC::toInt32(doubleArguments[4])); t.setSecond(JSC::toInt32(doubleArguments[5])); double ms = (n >= 7) ? doubleArguments[6] : 0; return JSValue::encode(jsNumber(timeClip(gregorianDateTimeToMS(exec, t, ms, true)))); }
JSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { if (!thisValue.isObject(&DateInstance::info)) return throwError(exec, TypeError); DateInstance* thisDateObj = asDateInstance(thisValue); double milli = timeClip(args.at(0).toNumber(exec)); JSValue result = jsNumber(exec, milli); thisDateObj->setInternalValue(result); return result; }
EncodedJSValue JSC_HOST_CALL dateProtoFuncSetTime(ExecState* exec) { JSValue thisValue = exec->thisValue(); if (!thisValue.inherits(DateInstance::info())) return throwVMTypeError(exec); DateInstance* thisDateObj = asDateInstance(thisValue); double milli = timeClip(exec->argument(0).toNumber(exec)); JSValue result = jsNumber(milli); thisDateObj->setInternalValue(exec->vm(), result); return JSValue::encode(result); }
// ECMA 15.9.3 JSObject* constructDate(ExecState* exec, const ArgList& args) { int numArgs = args.size(); double value; if (numArgs == 0) // new Date() ECMA 15.9.3.3 value = getCurrentUTCTime(); else if (numArgs == 1) { if (args.at(exec, 0)->isObject(&DateInstance::info)) value = asDateInstance(args.at(exec, 0))->internalNumber(); else { JSValue* primitive = args.at(exec, 0)->toPrimitive(exec); if (primitive->isString()) value = parseDate(primitive->getString()); else value = primitive->toNumber(exec); } } else { if (isnan(args.at(exec, 0)->toNumber(exec)) || isnan(args.at(exec, 1)->toNumber(exec)) || (numArgs >= 3 && isnan(args.at(exec, 2)->toNumber(exec))) || (numArgs >= 4 && isnan(args.at(exec, 3)->toNumber(exec))) || (numArgs >= 5 && isnan(args.at(exec, 4)->toNumber(exec))) || (numArgs >= 6 && isnan(args.at(exec, 5)->toNumber(exec))) || (numArgs >= 7 && isnan(args.at(exec, 6)->toNumber(exec)))) value = NaN; else { GregorianDateTime t; int year = args.at(exec, 0)->toInt32(exec); t.year = (year >= 0 && year <= 99) ? year : year - 1900; t.month = args.at(exec, 1)->toInt32(exec); t.monthDay = (numArgs >= 3) ? args.at(exec, 2)->toInt32(exec) : 1; t.hour = args.at(exec, 3)->toInt32(exec); t.minute = args.at(exec, 4)->toInt32(exec); t.second = args.at(exec, 5)->toInt32(exec); t.isDST = -1; double ms = (numArgs >= 7) ? args.at(exec, 6)->toNumber(exec) : 0; value = gregorianDateTimeToMS(t, ms, false); } } DateInstance* result = new (exec) DateInstance(exec->lexicalGlobalObject()->dateStructure()); result->setInternalValue(jsNumber(exec, timeClip(value))); return result; }
static AJValue JSC_HOST_CALL dateUTC(ExecState* exec, AJObject*, AJValue, const ArgList& args) { int n = args.size(); if (isnan(args.at(0).toNumber(exec)) || isnan(args.at(1).toNumber(exec)) || (n >= 3 && isnan(args.at(2).toNumber(exec))) || (n >= 4 && isnan(args.at(3).toNumber(exec))) || (n >= 5 && isnan(args.at(4).toNumber(exec))) || (n >= 6 && isnan(args.at(5).toNumber(exec))) || (n >= 7 && isnan(args.at(6).toNumber(exec)))) return jsNaN(exec); GregorianDateTime t; int year = args.at(0).toInt32(exec); t.year = (year >= 0 && year <= 99) ? year : year - 1900; t.month = args.at(1).toInt32(exec); t.monthDay = (n >= 3) ? args.at(2).toInt32(exec) : 1; t.hour = args.at(3).toInt32(exec); t.minute = args.at(4).toInt32(exec); t.second = args.at(5).toInt32(exec); double ms = (n >= 7) ? args.at(6).toNumber(exec) : 0; return jsNumber(exec, timeClip(gregorianDateTimeToMS(exec, t, ms, true))); }
EncodedJSValue JSC_HOST_CALL dateUTC(ExecState* exec) { double ms = millisecondsFromComponents(exec, ArgList(exec), WTF::UTCTime); return JSValue::encode(jsNumber(timeClip(ms))); }
void DateInstance::finishCreation(VM& vm, double time) { Base::finishCreation(vm); ASSERT(inherits(vm, info())); setInternalValue(vm, jsNumber(timeClip(time))); }
DateInstance::DateInstance(ExecState* exec, Structure* structure, double time) : JSWrapperObject(exec->globalData(), structure) { ASSERT(inherits(&s_info)); setInternalValue(exec->globalData(), jsNumber(timeClip(time))); }
DateInstance::DateInstance(TiExcState* exec, double time) : JSWrapperObject(exec->lexicalGlobalObject()->dateStructure()) { setInternalValue(jsNumber(exec, timeClip(time))); }
DateInstance::DateInstance(TiExcState* exec, NonNullPassRefPtr<Structure> structure, double time) : JSWrapperObject(structure) { setInternalValue(jsNumber(exec, timeClip(time))); }