#include "DateConversion.h"
#include "DateInstance.h"
#include "DatePrototype.h"
+#include "JSDateMath.h"
#include "JSFunction.h"
#include "JSGlobalObject.h"
#include "JSString.h"
#include "JSStringBuilder.h"
#include "ObjectPrototype.h"
+#include "Operations.h"
#include <math.h>
#include <time.h>
-#include <wtf/DateMath.h>
#include <wtf/MathExtras.h>
#if OS(WINCE) && !PLATFORM(QT)
namespace JSC {
-const ClassInfo DateConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::dateConstructorTable };
+const ClassInfo DateConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::dateConstructorTable, CREATE_METHOD_TABLE(DateConstructor) };
/* Source for DateConstructor.lut.h
@begin dateConstructorTable
@end
*/
-ASSERT_CLASS_FITS_IN_CELL(DateConstructor);
+ASSERT_HAS_TRIVIAL_DESTRUCTOR(DateConstructor);
-DateConstructor::DateConstructor(ExecState* exec, JSGlobalObject* globalObject, Structure* structure, DatePrototype* datePrototype)
- : InternalFunction(&exec->globalData(), globalObject, structure, Identifier(exec, datePrototype->classInfo()->className))
+DateConstructor::DateConstructor(JSGlobalObject* globalObject, Structure* structure)
+ : InternalFunction(globalObject, structure)
{
- putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, datePrototype, DontEnum | DontDelete | ReadOnly);
- putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(7), ReadOnly | DontEnum | DontDelete);
}
-bool DateConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
+void DateConstructor::finishCreation(ExecState* exec, DatePrototype* datePrototype)
{
- return getStaticFunctionSlot<InternalFunction>(exec, ExecState::dateConstructorTable(exec), this, propertyName, slot);
+ Base::finishCreation(exec->vm(), datePrototype->classInfo()->className);
+ putDirectWithoutTransition(exec->vm(), exec->propertyNames().prototype, datePrototype, DontEnum | DontDelete | ReadOnly);
+ putDirectWithoutTransition(exec->vm(), exec->propertyNames().length, jsNumber(7), ReadOnly | DontEnum | DontDelete);
}
-bool DateConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
+bool DateConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
{
- return getStaticFunctionDescriptor<InternalFunction>(exec, ExecState::dateConstructorTable(exec), this, propertyName, descriptor);
+ return getStaticFunctionSlot<InternalFunction>(exec, ExecState::dateConstructorTable(exec), jsCast<DateConstructor*>(cell), propertyName, slot);
+}
+
+bool DateConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)
+{
+ return getStaticFunctionDescriptor<InternalFunction>(exec, ExecState::dateConstructorTable(exec), jsCast<DateConstructor*>(object), propertyName, descriptor);
}
// ECMA 15.9.3
args.at(5).toNumber(exec),
args.at(6).toNumber(exec)
};
- if (isnan(doubleArguments[0])
- || isnan(doubleArguments[1])
- || (numArgs >= 3 && isnan(doubleArguments[2]))
- || (numArgs >= 4 && isnan(doubleArguments[3]))
- || (numArgs >= 5 && isnan(doubleArguments[4]))
- || (numArgs >= 6 && isnan(doubleArguments[5]))
- || (numArgs >= 7 && isnan(doubleArguments[6])))
- value = NaN;
+ if (!std::isfinite(doubleArguments[0])
+ || !std::isfinite(doubleArguments[1])
+ || (numArgs >= 3 && !std::isfinite(doubleArguments[2]))
+ || (numArgs >= 4 && !std::isfinite(doubleArguments[3]))
+ || (numArgs >= 5 && !std::isfinite(doubleArguments[4]))
+ || (numArgs >= 6 && !std::isfinite(doubleArguments[5]))
+ || (numArgs >= 7 && !std::isfinite(doubleArguments[6])))
+ value = QNaN;
else {
GregorianDateTime t;
int year = JSC::toInt32(doubleArguments[0]);
- t.year = (year >= 0 && year <= 99) ? year : year - 1900;
- t.month = JSC::toInt32(doubleArguments[1]);
- t.monthDay = (numArgs >= 3) ? JSC::toInt32(doubleArguments[2]) : 1;
- t.hour = JSC::toInt32(doubleArguments[3]);
- t.minute = JSC::toInt32(doubleArguments[4]);
- t.second = JSC::toInt32(doubleArguments[5]);
- t.isDST = -1;
+ t.setYear((year >= 0 && year <= 99) ? (year + 1900) : year);
+ t.setMonth(JSC::toInt32(doubleArguments[1]));
+ t.setMonthDay((numArgs >= 3) ? JSC::toInt32(doubleArguments[2]) : 1);
+ t.setHour(JSC::toInt32(doubleArguments[3]));
+ t.setMinute(JSC::toInt32(doubleArguments[4]));
+ t.setSecond(JSC::toInt32(doubleArguments[5]));
+ t.setIsDST(-1);
double ms = (numArgs >= 7) ? doubleArguments[6] : 0;
value = gregorianDateTimeToMS(exec, t, ms, false);
}
}
- return new (exec) DateInstance(exec, globalObject->dateStructure(), value);
+ return DateInstance::create(exec, globalObject->dateStructure(), value);
}
static EncodedJSValue JSC_HOST_CALL constructWithDateConstructor(ExecState* exec)
return JSValue::encode(constructDate(exec, asInternalFunction(exec->callee())->globalObject(), args));
}
-ConstructType DateConstructor::getConstructData(ConstructData& constructData)
+ConstructType DateConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
constructData.native.function = constructWithDateConstructor;
return ConstructTypeHost;
// ECMA 15.9.2
static EncodedJSValue JSC_HOST_CALL callDate(ExecState* exec)
{
- time_t localTime = time(0);
- tm localTM;
- getLocalTime(&localTime, &localTM);
- GregorianDateTime ts(exec, localTM);
- DateConversionBuffer date;
- DateConversionBuffer time;
- formatDate(ts, date);
- formatTime(ts, time);
- return JSValue::encode(jsMakeNontrivialString(exec, date, " ", time));
+ GregorianDateTime ts;
+ msToGregorianDateTime(exec, currentTimeMS(), false, ts);
+ return JSValue::encode(jsNontrivialString(exec, formatDateTime(ts, DateTimeFormatDateAndTime, false)));
}
-CallType DateConstructor::getCallData(CallData& callData)
+CallType DateConstructor::getCallData(JSCell*, CallData& callData)
{
callData.native.function = callDate;
return CallTypeHost;
static EncodedJSValue JSC_HOST_CALL dateParse(ExecState* exec)
{
- return JSValue::encode(jsNumber(parseDate(exec, exec->argument(0).toString(exec))));
+ return JSValue::encode(jsNumber(parseDate(exec, exec->argument(0).toString(exec)->value(exec))));
}
static EncodedJSValue JSC_HOST_CALL dateNow(ExecState*)
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])))
+ if (std::isnan(doubleArguments[0])
+ || std::isnan(doubleArguments[1])
+ || (n >= 3 && std::isnan(doubleArguments[2]))
+ || (n >= 4 && std::isnan(doubleArguments[3]))
+ || (n >= 5 && std::isnan(doubleArguments[4]))
+ || (n >= 6 && std::isnan(doubleArguments[5]))
+ || (n >= 7 && std::isnan(doubleArguments[6])))
return JSValue::encode(jsNaN());
GregorianDateTime t;
int year = JSC::toInt32(doubleArguments[0]);
- t.year = (year >= 0 && year <= 99) ? year : year - 1900;
- t.month = JSC::toInt32(doubleArguments[1]);
- t.monthDay = (n >= 3) ? JSC::toInt32(doubleArguments[2]) : 1;
- t.hour = JSC::toInt32(doubleArguments[3]);
- t.minute = JSC::toInt32(doubleArguments[4]);
- t.second = JSC::toInt32(doubleArguments[5]);
+ 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))));
}