X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/6fe7ccc865dc7d7541b93c5bcaf6368d2c98a174..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/runtime/DateConstructor.cpp?ds=sidebyside diff --git a/runtime/DateConstructor.cpp b/runtime/DateConstructor.cpp index 66f0bae..d6329fd 100644 --- a/runtime/DateConstructor.cpp +++ b/runtime/DateConstructor.cpp @@ -29,14 +29,15 @@ #include "JSFunction.h" #include "JSGlobalObject.h" #include "JSString.h" -#include "JSStringBuilder.h" #include "ObjectPrototype.h" +#include "JSCInlines.h" #include #include #include -#if OS(WINCE) && !PLATFORM(QT) -extern "C" time_t time(time_t* timer); // Provided by libce. +#if ENABLE(WEB_REPLAY) +#include "InputCursor.h" +#include "JSReplayInputs.h" #endif #if HAVE(SYS_TIME_H) @@ -51,9 +52,9 @@ using namespace WTF; namespace JSC { -static EncodedJSValue JSC_HOST_CALL dateParse(ExecState*); -static EncodedJSValue JSC_HOST_CALL dateNow(ExecState*); -static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState*); +EncodedJSValue JSC_HOST_CALL dateParse(ExecState*); +EncodedJSValue JSC_HOST_CALL dateNow(ExecState*); +EncodedJSValue JSC_HOST_CALL dateUTC(ExecState*); } @@ -61,7 +62,7 @@ static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState*); namespace JSC { -const ClassInfo DateConstructor::s_info = { "Function", &InternalFunction::s_info, 0, ExecState::dateConstructorTable, CREATE_METHOD_TABLE(DateConstructor) }; +const ClassInfo DateConstructor::s_info = { "Function", &InternalFunction::s_info, &dateConstructorTable, CREATE_METHOD_TABLE(DateConstructor) }; /* Source for DateConstructor.lut.h @begin dateConstructorTable @@ -71,47 +72,64 @@ const ClassInfo DateConstructor::s_info = { "Function", &InternalFunction::s_inf @end */ -ASSERT_CLASS_FITS_IN_CELL(DateConstructor); -ASSERT_HAS_TRIVIAL_DESTRUCTOR(DateConstructor); - -DateConstructor::DateConstructor(JSGlobalObject* globalObject, Structure* structure) - : InternalFunction(globalObject, structure) +#if ENABLE(WEB_REPLAY) +static double deterministicCurrentTime(JSGlobalObject* globalObject) { + double currentTime = jsCurrentTime(); + InputCursor& cursor = globalObject->inputCursor(); + if (cursor.isCapturing()) + cursor.appendInput(currentTime); + + if (cursor.isReplaying()) { + if (GetCurrentTime* input = cursor.fetchInput()) + currentTime = input->currentTime(); + } + return currentTime; } +#endif + +#if ENABLE(WEB_REPLAY) +#define NORMAL_OR_DETERMINISTIC_FUNCTION(a, b) (b) +#else +#define NORMAL_OR_DETERMINISTIC_FUNCTION(a, b) (a) +#endif + +STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(DateConstructor); -void DateConstructor::finishCreation(ExecState* exec, DatePrototype* datePrototype) +DateConstructor::DateConstructor(VM& vm, Structure* structure) + : InternalFunction(vm, structure) { - Base::finishCreation(exec->globalData(), Identifier(exec, datePrototype->classInfo()->className)); - putDirectWithoutTransition(exec->globalData(), exec->propertyNames().prototype, datePrototype, DontEnum | DontDelete | ReadOnly); - putDirectWithoutTransition(exec->globalData(), exec->propertyNames().length, jsNumber(7), ReadOnly | DontEnum | DontDelete); } -bool DateConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot &slot) +void DateConstructor::finishCreation(VM& vm, DatePrototype* datePrototype) { - return getStaticFunctionSlot(exec, ExecState::dateConstructorTable(exec), jsCast(cell), propertyName, slot); + Base::finishCreation(vm, datePrototype->classInfo()->className); + putDirectWithoutTransition(vm, vm.propertyNames->prototype, datePrototype, DontEnum | DontDelete | ReadOnly); + putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(7), ReadOnly | DontEnum | DontDelete); } -bool DateConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +bool DateConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot) { - return getStaticFunctionDescriptor(exec, ExecState::dateConstructorTable(exec), jsCast(object), propertyName, descriptor); + return getStaticFunctionSlot(exec, dateConstructorTable, jsCast(object), propertyName, slot); } // ECMA 15.9.3 JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args) { + VM& vm = exec->vm(); int numArgs = args.size(); double value; if (numArgs == 0) // new Date() ECMA 15.9.3.3 - value = jsCurrentTime(); + value = NORMAL_OR_DETERMINISTIC_FUNCTION(jsCurrentTime(), deterministicCurrentTime(globalObject)); else if (numArgs == 1) { - if (args.at(0).inherits(&DateInstance::s_info)) + if (args.at(0).inherits(DateInstance::info())) value = asDateInstance(args.at(0))->internalNumber(); else { JSValue primitive = args.at(0).toPrimitive(exec); if (primitive.isString()) - value = parseDate(exec, primitive.getString(exec)); + value = parseDate(vm, primitive.getString(exec)); else value = primitive.toNumber(exec); } @@ -125,30 +143,30 @@ JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, const Arg args.at(5).toNumber(exec), args.at(6).toNumber(exec) }; - if (!isfinite(doubleArguments[0]) - || !isfinite(doubleArguments[1]) - || (numArgs >= 3 && !isfinite(doubleArguments[2])) - || (numArgs >= 4 && !isfinite(doubleArguments[3])) - || (numArgs >= 5 && !isfinite(doubleArguments[4])) - || (numArgs >= 6 && !isfinite(doubleArguments[5])) - || (numArgs >= 7 && !isfinite(doubleArguments[6]))) - value = std::numeric_limits::quiet_NaN(); + if ((!std::isfinite(doubleArguments[0]) || (doubleArguments[0] > INT_MAX) || (doubleArguments[0] < INT_MIN)) + || (!std::isfinite(doubleArguments[1]) || (doubleArguments[1] > INT_MAX) || (doubleArguments[1] < INT_MIN)) + || (numArgs >= 3 && (!std::isfinite(doubleArguments[2]) || (doubleArguments[2] > INT_MAX) || (doubleArguments[2] < INT_MIN))) + || (numArgs >= 4 && (!std::isfinite(doubleArguments[3]) || (doubleArguments[3] > INT_MAX) || (doubleArguments[3] < INT_MIN))) + || (numArgs >= 5 && (!std::isfinite(doubleArguments[4]) || (doubleArguments[4] > INT_MAX) || (doubleArguments[4] < INT_MIN))) + || (numArgs >= 6 && (!std::isfinite(doubleArguments[5]) || (doubleArguments[5] > INT_MAX) || (doubleArguments[5] < INT_MIN))) + || (numArgs >= 7 && (!std::isfinite(doubleArguments[6]) || (doubleArguments[6] > INT_MAX) || (doubleArguments[6] < INT_MIN)))) + value = PNaN; 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); + value = gregorianDateTimeToMS(vm, t, ms, WTF::LocalTime); } } - return DateInstance::create(exec, globalObject->dateStructure(), value); + return DateInstance::create(vm, globalObject->dateStructure(), value); } static EncodedJSValue JSC_HOST_CALL constructWithDateConstructor(ExecState* exec) @@ -166,13 +184,10 @@ ConstructType DateConstructor::getConstructData(JSCell*, ConstructData& construc // ECMA 15.9.2 static EncodedJSValue JSC_HOST_CALL callDate(ExecState* exec) { + VM& vm = exec->vm(); GregorianDateTime ts; - msToGregorianDateTime(exec, currentTimeMS(), false, ts); - DateConversionBuffer date; - DateConversionBuffer time; - formatDate(ts, date); - formatTime(ts, time); - return JSValue::encode(jsMakeNontrivialString(exec, date, " ", time)); + msToGregorianDateTime(vm, currentTimeMS(), WTF::LocalTime, ts); + return JSValue::encode(jsNontrivialString(&vm, formatDateTime(ts, DateTimeFormatDateAndTime, false))); } CallType DateConstructor::getCallData(JSCell*, CallData& callData) @@ -181,17 +196,21 @@ CallType DateConstructor::getCallData(JSCell*, CallData& callData) return CallTypeHost; } -static EncodedJSValue JSC_HOST_CALL dateParse(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateParse(ExecState* exec) { - return JSValue::encode(jsNumber(parseDate(exec, exec->argument(0).toString(exec)->value(exec)))); + return JSValue::encode(jsNumber(parseDate(exec->vm(), exec->argument(0).toString(exec)->value(exec)))); } -static EncodedJSValue JSC_HOST_CALL dateNow(ExecState*) +EncodedJSValue JSC_HOST_CALL dateNow(ExecState* exec) { - return JSValue::encode(jsNumber(jsCurrentTime())); +#if !ENABLE(WEB_REPLAY) + UNUSED_PARAM(exec); +#endif + + return JSValue::encode(jsNumber(NORMAL_OR_DETERMINISTIC_FUNCTION(jsCurrentTime(), deterministicCurrentTime(exec->lexicalGlobalObject())))); } -static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState* exec) +EncodedJSValue JSC_HOST_CALL dateUTC(ExecState* exec) { double doubleArguments[7] = { exec->argument(0).toNumber(exec), @@ -203,25 +222,25 @@ static EncodedJSValue JSC_HOST_CALL dateUTC(ExecState* 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]))) + if ((std::isnan(doubleArguments[0]) || (doubleArguments[0] > INT_MAX) || (doubleArguments[0] < INT_MIN)) + || (std::isnan(doubleArguments[1]) || (doubleArguments[1] > INT_MAX) || (doubleArguments[1] < INT_MIN)) + || (n >= 3 && (std::isnan(doubleArguments[2]) || (doubleArguments[2] > INT_MAX) || (doubleArguments[2] < INT_MIN))) + || (n >= 4 && (std::isnan(doubleArguments[3]) || (doubleArguments[3] > INT_MAX) || (doubleArguments[3] < INT_MIN))) + || (n >= 5 && (std::isnan(doubleArguments[4]) || (doubleArguments[4] > INT_MAX) || (doubleArguments[4] < INT_MIN))) + || (n >= 6 && (std::isnan(doubleArguments[5]) || (doubleArguments[5] > INT_MAX) || (doubleArguments[5] < INT_MIN))) + || (n >= 7 && (std::isnan(doubleArguments[6]) || (doubleArguments[6] > INT_MAX) || (doubleArguments[6] < INT_MIN)))) 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)))); + return JSValue::encode(jsNumber(timeClip(gregorianDateTimeToMS(exec->vm(), t, ms, WTF::UTCTime)))); } } // namespace JSC