summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/runtime/DateConstructor.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/runtime/DateConstructor.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/JavaScriptCore/runtime/DateConstructor.cpp')
-rw-r--r--Source/JavaScriptCore/runtime/DateConstructor.cpp180
1 files changed, 94 insertions, 86 deletions
diff --git a/Source/JavaScriptCore/runtime/DateConstructor.cpp b/Source/JavaScriptCore/runtime/DateConstructor.cpp
index 7cbea6407..9c257e598 100644
--- a/Source/JavaScriptCore/runtime/DateConstructor.cpp
+++ b/Source/JavaScriptCore/runtime/DateConstructor.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2008, 2011, 2016 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -29,15 +29,15 @@
#include "JSFunction.h"
#include "JSGlobalObject.h"
#include "JSString.h"
-#include "JSStringBuilder.h"
#include "ObjectPrototype.h"
-#include "Operations.h"
+#include "JSCInlines.h"
#include <math.h>
#include <time.h>
#include <wtf/MathExtras.h>
-#if OS(WINCE)
-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)
@@ -52,9 +52,8 @@ 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 dateUTC(ExecState*);
}
@@ -62,7 +61,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
@@ -72,6 +71,28 @@ const ClassInfo DateConstructor::s_info = { "Function", &InternalFunction::s_inf
@end
*/
+#if ENABLE(WEB_REPLAY)
+static double deterministicCurrentTime(JSGlobalObject* globalObject)
+{
+ double currentTime = jsCurrentTime();
+ InputCursor& cursor = globalObject->inputCursor();
+ if (cursor.isCapturing())
+ cursor.appendInput<GetCurrentTime>(currentTime);
+
+ if (cursor.isReplaying()) {
+ if (GetCurrentTime* input = cursor.fetchInput<GetCurrentTime>())
+ 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);
DateConstructor::DateConstructor(VM& vm, Structure* structure)
@@ -81,82 +102,88 @@ DateConstructor::DateConstructor(VM& vm, Structure* structure)
void DateConstructor::finishCreation(VM& vm, DatePrototype* datePrototype)
{
- Base::finishCreation(vm, datePrototype->classInfo()->className);
+ Base::finishCreation(vm, "Date");
putDirectWithoutTransition(vm, vm.propertyNames->prototype, datePrototype, DontEnum | DontDelete | ReadOnly);
putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(7), ReadOnly | DontEnum | DontDelete);
}
-bool DateConstructor::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot &slot)
+static double millisecondsFromComponents(ExecState* exec, const ArgList& args, WTF::TimeType timeType)
{
- return getStaticFunctionSlot<InternalFunction>(exec, ExecState::dateConstructorTable(exec->vm()), jsCast<DateConstructor*>(object), propertyName, slot);
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ double doubleArguments[7];
+ for (int i = 0; i < 7; i++) {
+ doubleArguments[i] = args.at(i).toNumber(exec);
+ RETURN_IF_EXCEPTION(scope, 0);
+ }
+
+ int numArgs = args.size();
+
+ 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))))
+ return PNaN;
+
+ 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((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;
+ return gregorianDateTimeToMS(vm, t, ms, timeType);
}
// ECMA 15.9.3
-JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, const ArgList& args)
+JSObject* constructDate(ExecState* exec, JSGlobalObject* globalObject, JSValue newTarget, const ArgList& args)
{
VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(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::info()))
+ if (args.at(0).inherits(vm, DateInstance::info()))
value = asDateInstance(args.at(0))->internalNumber();
else {
JSValue primitive = args.at(0).toPrimitive(exec);
+ RETURN_IF_EXCEPTION(scope, nullptr);
if (primitive.isString())
- value = parseDate(vm, primitive.getString(exec));
+ value = parseDate(vm, asString(primitive)->value(exec));
else
value = primitive.toNumber(exec);
}
- } else {
- double doubleArguments[7] = {
- args.at(0).toNumber(exec),
- args.at(1).toNumber(exec),
- args.at(2).toNumber(exec),
- args.at(3).toNumber(exec),
- args.at(4).toNumber(exec),
- args.at(5).toNumber(exec),
- args.at(6).toNumber(exec)
- };
- 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.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(vm, t, ms, WTF::LocalTime);
- }
- }
+ } else
+ value = millisecondsFromComponents(exec, args, WTF::LocalTime);
+ RETURN_IF_EXCEPTION(scope, nullptr);
+
+ Structure* dateStructure = InternalFunction::createSubclassStructure(exec, newTarget, globalObject->dateStructure());
+ RETURN_IF_EXCEPTION(scope, nullptr);
- return DateInstance::create(vm, globalObject->dateStructure(), value);
+ return DateInstance::create(vm, dateStructure, value);
}
static EncodedJSValue JSC_HOST_CALL constructWithDateConstructor(ExecState* exec)
{
ArgList args(exec);
- return JSValue::encode(constructDate(exec, asInternalFunction(exec->callee())->globalObject(), args));
+ return JSValue::encode(constructDate(exec, asInternalFunction(exec->jsCallee())->globalObject(), exec->newTarget(), args));
}
ConstructType DateConstructor::getConstructData(JSCell*, ConstructData& constructData)
{
constructData.native.function = constructWithDateConstructor;
- return ConstructTypeHost;
+ return ConstructType::Host;
}
// ECMA 15.9.2
@@ -171,50 +198,31 @@ static EncodedJSValue JSC_HOST_CALL callDate(ExecState* exec)
CallType DateConstructor::getCallData(JSCell*, CallData& callData)
{
callData.native.function = callDate;
- return CallTypeHost;
+ return CallType::Host;
}
-static EncodedJSValue JSC_HOST_CALL dateParse(ExecState* exec)
+EncodedJSValue JSC_HOST_CALL dateParse(ExecState* exec)
{
- return JSValue::encode(jsNumber(parseDate(exec->vm(), exec->argument(0).toString(exec)->value(exec))));
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ String dateStr = exec->argument(0).toWTFString(exec);
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ return JSValue::encode(jsNumber(parseDate(vm, dateStr)));
}
-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),
- 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 (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.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->vm(), t, ms, WTF::UTCTime))));
+ double ms = millisecondsFromComponents(exec, ArgList(exec), WTF::UTCTime);
+ return JSValue::encode(jsNumber(timeClip(ms)));
}
} // namespace JSC