aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4dateobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2015-01-15 21:54:12 +0100
committerLars Knoll <lars.knoll@digia.com>2015-01-23 12:30:38 +0100
commitef6b4938b9ec309d5faf0c966cb2b58f3de2ca77 (patch)
tree3d946ad66defb1ec5c60a50e16b6e7883ec33862 /src/qml/jsruntime/qv4dateobject.cpp
parent3dbf4e9a6979802fff55e2f5e6aa54a14280e128 (diff)
Cleanups
Simplify some code in BooleanObject Simplify access to call arguments and thisObject Change-Id: I2f8e844019bc587385608beb02f05b15f827535c Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4dateobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 423c36963f..d11118ee88 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -755,7 +755,7 @@ void DatePrototype::init(ExecutionEngine *engine, Object *ctor)
double DatePrototype::getThisDate(ExecutionContext *ctx)
{
- if (DateObject *thisObject = ctx->d()->callData->thisObject.asDateObject())
+ if (DateObject *thisObject = ctx->thisObject().asDateObject())
return thisObject->date().asDouble();
else {
ctx->engine()->throwTypeError();
@@ -765,22 +765,22 @@ double DatePrototype::getThisDate(ExecutionContext *ctx)
ReturnedValue DatePrototype::method_parse(CallContext *ctx)
{
- if (!ctx->d()->callData->argc)
+ if (!ctx->argc())
return Encode(qSNaN());
- return Encode(ParseString(ctx->d()->callData->args[0].toQString()));
+ return Encode(ParseString(ctx->args()[0].toQString()));
}
ReturnedValue DatePrototype::method_UTC(CallContext *ctx)
{
- const int numArgs = ctx->d()->callData->argc;
+ const int numArgs = ctx->argc();
if (numArgs >= 2) {
- double year = ctx->d()->callData->args[0].toNumber();
- double month = ctx->d()->callData->args[1].toNumber();
- double day = numArgs >= 3 ? ctx->d()->callData->args[2].toNumber() : 1;
- double hours = numArgs >= 4 ? ctx->d()->callData->args[3].toNumber() : 0;
- double mins = numArgs >= 5 ? ctx->d()->callData->args[4].toNumber() : 0;
- double secs = numArgs >= 6 ? ctx->d()->callData->args[5].toNumber() : 0;
- double ms = numArgs >= 7 ? ctx->d()->callData->args[6].toNumber() : 0;
+ double year = ctx->args()[0].toNumber();
+ double month = ctx->args()[1].toNumber();
+ double day = numArgs >= 3 ? ctx->args()[2].toNumber() : 1;
+ double hours = numArgs >= 4 ? ctx->args()[3].toNumber() : 0;
+ double mins = numArgs >= 5 ? ctx->args()[4].toNumber() : 0;
+ double secs = numArgs >= 6 ? ctx->args()[5].toNumber() : 0;
+ double ms = numArgs >= 7 ? ctx->args()[6].toNumber() : 0;
if (year >= 0 && year <= 99)
year += 1900;
double t = MakeDate(MakeDay(year, month, day),
@@ -992,11 +992,11 @@ ReturnedValue DatePrototype::method_getTimezoneOffset(CallContext *ctx)
ReturnedValue DatePrototype::method_setTime(CallContext *ctx)
{
Scope scope(ctx);
- Scoped<DateObject> self(scope, ctx->d()->callData->thisObject);
+ Scoped<DateObject> self(scope, ctx->thisObject());
if (!self)
return ctx->engine()->throwTypeError();
- double t = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
+ double t = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
self->date().setDouble(TimeClip(t));
return self->date().asReturnedValue();
}
@@ -1004,37 +1004,37 @@ ReturnedValue DatePrototype::method_setTime(CallContext *ctx)
ReturnedValue DatePrototype::method_setMilliseconds(CallContext *ctx)
{
Scope scope(ctx);
- Scoped<DateObject> self(scope, ctx->d()->callData->thisObject);
+ Scoped<DateObject> self(scope, ctx->thisObject());
if (!self)
return ctx->engine()->throwTypeError();
double t = LocalTime(self->date().asDouble());
- double ms = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
+ double ms = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
self->date().setDouble(TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms)))));
return self->date().asReturnedValue();
}
ReturnedValue DatePrototype::method_setUTCMilliseconds(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
- double ms = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
+ double ms = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
self->date().setDouble(TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms))));
return self->date().asReturnedValue();
}
ReturnedValue DatePrototype::method_setSeconds(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = LocalTime(self->date().asDouble());
- double sec = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double ms = (ctx->d()->callData->argc < 2) ? msFromTime(t) : ctx->d()->callData->args[1].toNumber();
+ double sec = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double ms = (ctx->argc() < 2) ? msFromTime(t) : ctx->args()[1].toNumber();
t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms))));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1042,13 +1042,13 @@ ReturnedValue DatePrototype::method_setSeconds(CallContext *ctx)
ReturnedValue DatePrototype::method_setUTCSeconds(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
- double sec = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double ms = (ctx->d()->callData->argc < 2) ? msFromTime(t) : ctx->d()->callData->args[1].toNumber();
+ double sec = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double ms = (ctx->argc() < 2) ? msFromTime(t) : ctx->args()[1].toNumber();
t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), MinFromTime(t), sec, ms)));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1056,14 +1056,14 @@ ReturnedValue DatePrototype::method_setUTCSeconds(CallContext *ctx)
ReturnedValue DatePrototype::method_setMinutes(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = LocalTime(self->date().asDouble());
- double min = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double sec = (ctx->d()->callData->argc < 2) ? SecFromTime(t) : ctx->d()->callData->args[1].toNumber();
- double ms = (ctx->d()->callData->argc < 3) ? msFromTime(t) : ctx->d()->callData->args[2].toNumber();
+ double min = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double sec = (ctx->argc() < 2) ? SecFromTime(t) : ctx->args()[1].toNumber();
+ double ms = (ctx->argc() < 3) ? msFromTime(t) : ctx->args()[2].toNumber();
t = TimeClip(UTC(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms))));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1071,14 +1071,14 @@ ReturnedValue DatePrototype::method_setMinutes(CallContext *ctx)
ReturnedValue DatePrototype::method_setUTCMinutes(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
- double min = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double sec = (ctx->d()->callData->argc < 2) ? SecFromTime(t) : ctx->d()->callData->args[1].toNumber();
- double ms = (ctx->d()->callData->argc < 3) ? msFromTime(t) : ctx->d()->callData->args[2].toNumber();
+ double min = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double sec = (ctx->argc() < 2) ? SecFromTime(t) : ctx->args()[1].toNumber();
+ double ms = (ctx->argc() < 3) ? msFromTime(t) : ctx->args()[2].toNumber();
t = TimeClip(MakeDate(Day(t), MakeTime(HourFromTime(t), min, sec, ms)));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1086,15 +1086,15 @@ ReturnedValue DatePrototype::method_setUTCMinutes(CallContext *ctx)
ReturnedValue DatePrototype::method_setHours(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = LocalTime(self->date().asDouble());
- double hour = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double min = (ctx->d()->callData->argc < 2) ? MinFromTime(t) : ctx->d()->callData->args[1].toNumber();
- double sec = (ctx->d()->callData->argc < 3) ? SecFromTime(t) : ctx->d()->callData->args[2].toNumber();
- double ms = (ctx->d()->callData->argc < 4) ? msFromTime(t) : ctx->d()->callData->args[3].toNumber();
+ double hour = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double min = (ctx->argc() < 2) ? MinFromTime(t) : ctx->args()[1].toNumber();
+ double sec = (ctx->argc() < 3) ? SecFromTime(t) : ctx->args()[2].toNumber();
+ double ms = (ctx->argc() < 4) ? msFromTime(t) : ctx->args()[3].toNumber();
t = TimeClip(UTC(MakeDate(Day(t), MakeTime(hour, min, sec, ms))));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1102,15 +1102,15 @@ ReturnedValue DatePrototype::method_setHours(CallContext *ctx)
ReturnedValue DatePrototype::method_setUTCHours(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
- double hour = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double min = (ctx->d()->callData->argc < 2) ? MinFromTime(t) : ctx->d()->callData->args[1].toNumber();
- double sec = (ctx->d()->callData->argc < 3) ? SecFromTime(t) : ctx->d()->callData->args[2].toNumber();
- double ms = (ctx->d()->callData->argc < 4) ? msFromTime(t) : ctx->d()->callData->args[3].toNumber();
+ double hour = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double min = (ctx->argc() < 2) ? MinFromTime(t) : ctx->args()[1].toNumber();
+ double sec = (ctx->argc() < 3) ? SecFromTime(t) : ctx->args()[2].toNumber();
+ double ms = (ctx->argc() < 4) ? msFromTime(t) : ctx->args()[3].toNumber();
t = TimeClip(MakeDate(Day(t), MakeTime(hour, min, sec, ms)));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1118,12 +1118,12 @@ ReturnedValue DatePrototype::method_setUTCHours(CallContext *ctx)
ReturnedValue DatePrototype::method_setDate(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = LocalTime(self->date().asDouble());
- double date = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
+ double date = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t))));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1131,12 +1131,12 @@ ReturnedValue DatePrototype::method_setDate(CallContext *ctx)
ReturnedValue DatePrototype::method_setUTCDate(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
- double date = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
+ double date = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
t = TimeClip(MakeDate(MakeDay(YearFromTime(t), MonthFromTime(t), date), TimeWithinDay(t)));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1144,13 +1144,13 @@ ReturnedValue DatePrototype::method_setUTCDate(CallContext *ctx)
ReturnedValue DatePrototype::method_setMonth(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = LocalTime(self->date().asDouble());
- double month = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double date = (ctx->d()->callData->argc < 2) ? DateFromTime(t) : ctx->d()->callData->args[1].toNumber();
+ double month = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double date = (ctx->argc() < 2) ? DateFromTime(t) : ctx->args()[1].toNumber();
t = TimeClip(UTC(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t))));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1158,13 +1158,13 @@ ReturnedValue DatePrototype::method_setMonth(CallContext *ctx)
ReturnedValue DatePrototype::method_setUTCMonth(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
- double month = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double date = (ctx->d()->callData->argc < 2) ? DateFromTime(t) : ctx->d()->callData->args[1].toNumber();
+ double month = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double date = (ctx->argc() < 2) ? DateFromTime(t) : ctx->args()[1].toNumber();
t = TimeClip(MakeDate(MakeDay(YearFromTime(t), month, date), TimeWithinDay(t)));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1172,7 +1172,7 @@ ReturnedValue DatePrototype::method_setUTCMonth(CallContext *ctx)
ReturnedValue DatePrototype::method_setYear(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
@@ -1181,7 +1181,7 @@ ReturnedValue DatePrototype::method_setYear(CallContext *ctx)
t = 0;
else
t = LocalTime(t);
- double year = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
+ double year = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
double r;
if (std::isnan(year)) {
r = qSNaN();
@@ -1198,14 +1198,14 @@ ReturnedValue DatePrototype::method_setYear(CallContext *ctx)
ReturnedValue DatePrototype::method_setUTCFullYear(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
- double year = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double month = (ctx->d()->callData->argc < 2) ? MonthFromTime(t) : ctx->d()->callData->args[1].toNumber();
- double date = (ctx->d()->callData->argc < 3) ? DateFromTime(t) : ctx->d()->callData->args[2].toNumber();
+ double year = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double month = (ctx->argc() < 2) ? MonthFromTime(t) : ctx->args()[1].toNumber();
+ double date = (ctx->argc() < 3) ? DateFromTime(t) : ctx->args()[2].toNumber();
t = TimeClip(MakeDate(MakeDay(year, month, date), TimeWithinDay(t)));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1213,16 +1213,16 @@ ReturnedValue DatePrototype::method_setUTCFullYear(CallContext *ctx)
ReturnedValue DatePrototype::method_setFullYear(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = LocalTime(self->date().asDouble());
if (std::isnan(t))
t = 0;
- double year = ctx->d()->callData->argc ? ctx->d()->callData->args[0].toNumber() : qSNaN();
- double month = (ctx->d()->callData->argc < 2) ? MonthFromTime(t) : ctx->d()->callData->args[1].toNumber();
- double date = (ctx->d()->callData->argc < 3) ? DateFromTime(t) : ctx->d()->callData->args[2].toNumber();
+ double year = ctx->argc() ? ctx->args()[0].toNumber() : qSNaN();
+ double month = (ctx->argc() < 2) ? MonthFromTime(t) : ctx->args()[1].toNumber();
+ double date = (ctx->argc() < 3) ? DateFromTime(t) : ctx->args()[2].toNumber();
t = TimeClip(UTC(MakeDate(MakeDay(year, month, date), TimeWithinDay(t))));
self->date().setDouble(t);
return self->date().asReturnedValue();
@@ -1230,7 +1230,7 @@ ReturnedValue DatePrototype::method_setFullYear(CallContext *ctx)
ReturnedValue DatePrototype::method_toUTCString(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
@@ -1253,13 +1253,13 @@ static void addZeroPrefixedInt(QString &str, int num, int nDigits)
ReturnedValue DatePrototype::method_toISOString(CallContext *ctx)
{
- DateObject *self = ctx->d()->callData->thisObject.asDateObject();
+ DateObject *self = ctx->thisObject().asDateObject();
if (!self)
return ctx->engine()->throwTypeError();
double t = self->date().asDouble();
if (!std::isfinite(t))
- return ctx->engine()->throwRangeError(ctx->d()->callData->thisObject);
+ return ctx->engine()->throwRangeError(ctx->thisObject());
QString result;
int year = (int)YearFromTime(t);
@@ -1292,7 +1292,7 @@ ReturnedValue DatePrototype::method_toISOString(CallContext *ctx)
ReturnedValue DatePrototype::method_toJSON(CallContext *ctx)
{
Scope scope(ctx);
- ScopedValue O(scope, RuntimeHelpers::toObject(scope.engine, ctx->d()->callData->thisObject));
+ ScopedValue O(scope, RuntimeHelpers::toObject(scope.engine, ctx->thisObject()));
ScopedValue tv(scope, RuntimeHelpers::toPrimitive(O, NUMBER_HINT));
if (tv->isNumber() && !std::isfinite(tv->toNumber()))
@@ -1306,7 +1306,7 @@ ReturnedValue DatePrototype::method_toJSON(CallContext *ctx)
return ctx->engine()->throwTypeError();
ScopedCallData callData(scope);
- callData->thisObject = ctx->d()->callData->thisObject;
+ callData->thisObject = ctx->thisObject();
return toIso->call(callData);
}