summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-08-19 19:17:47 +0300
committerLinus Groh <mail@linusgroh.de>2021-08-19 19:15:00 +0100
commitee608f58eebcfa5e3f78be0ffbfc9475999026b3 (patch)
treea34fbb6b9c9ade8f7c997371a17f80ac6a0c2db7
parent95bc8e46411b10edb62739178b51d57b1ed2064d (diff)
downloadserenity-ee608f58eebcfa5e3f78be0ffbfc9475999026b3.zip
LibJS: Add type range checks to the Date make_day AO
As the specification says "but if this is not possible (because some argument is out of range), return NaN."
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp
index 1e1950c7df..b51808dd99 100644
--- a/Userland/Libraries/LibJS/Runtime/Date.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Date.cpp
@@ -339,9 +339,11 @@ Value make_day(GlobalObject& global_object, Value year, Value month, Value date)
// NOTE: This calculation has no side-effects and is unused, so we omit it
// 8. Find a finite time value t such that YearFromTime(t) is ym and MonthFromTime(t) is mn and DateFromTime(t) is 1𝔽; but if this is not possible (because some argument is out of range), return NaN.
- auto t = Core::DateTime::create(y, m + 1, 0).timestamp() * 1000;
+ if (!AK::is_within_range<int>(y) || !AK::is_within_range<int>(m + 1))
+ return js_nan();
+ auto t = Core::DateTime::create(static_cast<int>(y), static_cast<int>(m + 1), 0).timestamp() * 1000;
// 9. Return Day(t) + dt - 1𝔽.
- return Value(day(t) + dt - 1);
+ return Value(day(static_cast<double>(t)) + dt - 1);
}
// 21.4.1.13 MakeDate ( day, time ), https://tc39.es/ecma262/#sec-makedate