aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4dateobject.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-09-07 12:43:55 +0200
committerLars Knoll <lars.knoll@qt.io>2018-09-07 12:42:52 +0000
commit1e600a94302aa1f6b5f3a639929c496f7215e386 (patch)
tree18cb876aec3c16935306562900a3e7ac0d80e4fd /src/qml/jsruntime/qv4dateobject.cpp
parent22023717774ca94b88e2b83756889b98e93aa9e3 (diff)
Fix Date.Utc()
Change-Id: Iefba82adbf8f7b944079d165054e9dfe4461ac77 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4dateobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4dateobject.cpp59
1 files changed, 43 insertions, 16 deletions
diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp
index 7335dd1ba0..93ca4f5442 100644
--- a/src/qml/jsruntime/qv4dateobject.cpp
+++ b/src/qml/jsruntime/qv4dateobject.cpp
@@ -253,6 +253,12 @@ static inline double WeekDay(double t)
static inline double MakeTime(double hour, double min, double sec, double ms)
{
+ if (!qIsFinite(hour) || !qIsFinite(min) || !qIsFinite(sec) || !qIsFinite(ms))
+ return qQNaN();
+ hour = Primitive::toInteger(hour);
+ min = Primitive::toInteger(min);
+ sec = Primitive::toInteger(sec);
+ ms = Primitive::toInteger(ms);
return ((hour * MinutesPerHour + min) * SecondsPerMinute + sec) * msPerSecond + ms;
}
@@ -278,6 +284,12 @@ static inline double DayFromMonth(double month, double leap)
static double MakeDay(double year, double month, double day)
{
+ if (!qIsFinite(year) || !qIsFinite(month) || !qIsFinite(day))
+ return qQNaN();
+ year = Primitive::toInteger(year);
+ month = Primitive::toInteger(month);
+ day = Primitive::toInteger(day);
+
year += ::floor(month / 12.0);
month = ::fmod(month, 12.0);
@@ -879,24 +891,39 @@ ReturnedValue DatePrototype::method_parse(const FunctionObject *f, const Value *
return Encode(ParseString(argv[0].toQString(), f->engine()->localTZA));
}
-ReturnedValue DatePrototype::method_UTC(const FunctionObject *, const Value *, const Value *argv, int argc)
+ReturnedValue DatePrototype::method_UTC(const FunctionObject *f, const Value *, const Value *argv, int argc)
{
const int numArgs = argc;
- if (numArgs >= 2) {
- double year = argv[0].toNumber();
- double month = argv[1].toNumber();
- double day = numArgs >= 3 ? argv[2].toNumber() : 1;
- double hours = numArgs >= 4 ? argv[3].toNumber() : 0;
- double mins = numArgs >= 5 ? argv[4].toNumber() : 0;
- double secs = numArgs >= 6 ? argv[5].toNumber() : 0;
- double ms = numArgs >= 7 ? argv[6].toNumber() : 0;
- if (year >= 0 && year <= 99)
- year += 1900;
- double t = MakeDate(MakeDay(year, month, day),
- MakeTime(hours, mins, secs, ms));
- return Encode(TimeClip(t));
- }
- RETURN_UNDEFINED();
+ if (numArgs < 1)
+ return Encode(qQNaN());
+ ExecutionEngine *e = f->engine();
+ double year = argv[0].toNumber();
+ if (e->hasException)
+ return Encode::undefined();
+ double month = numArgs >= 2 ? argv[1].toNumber() : 0;
+ if (e->hasException)
+ return Encode::undefined();
+ double day = numArgs >= 3 ? argv[2].toNumber() : 1;
+ if (e->hasException)
+ return Encode::undefined();
+ double hours = numArgs >= 4 ? argv[3].toNumber() : 0;
+ if (e->hasException)
+ return Encode::undefined();
+ double mins = numArgs >= 5 ? argv[4].toNumber() : 0;
+ if (e->hasException)
+ return Encode::undefined();
+ double secs = numArgs >= 6 ? argv[5].toNumber() : 0;
+ if (e->hasException)
+ return Encode::undefined();
+ double ms = numArgs >= 7 ? argv[6].toNumber() : 0;
+ if (e->hasException)
+ return Encode::undefined();
+ double iyear = Primitive::toInteger(year);
+ if (!qIsNaN(year) && iyear >= 0 && iyear <= 99)
+ year = 1900 + iyear;
+ double t = MakeDate(MakeDay(year, month, day),
+ MakeTime(hours, mins, secs, ms));
+ return Encode(TimeClip(t));
}
ReturnedValue DatePrototype::method_now(const FunctionObject *, const Value *, const Value *, int)