shithub: libmujs

Download patch

ref: d11c71072e86425f98c24a45be8af9aacbe0ff08
parent: d3a99000e0d502eeb659631c661fe4dccd24a452
author: Tor Andersson <[email protected]>
date: Wed Feb 3 12:07:28 EST 2021

Bug 703458: Handle NaN in Date accessors.

--- a/jsdate.c
+++ b/jsdate.c
@@ -491,103 +491,154 @@
 static void Dp_getFullYear(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, YearFromTime(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, YearFromTime(LocalTime(t)));
 }
 
 static void Dp_getMonth(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, MonthFromTime(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, MonthFromTime(LocalTime(t)));
 }
 
 static void Dp_getDate(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, DateFromTime(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, DateFromTime(LocalTime(t)));
 }
 
 static void Dp_getDay(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, WeekDay(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, WeekDay(LocalTime(t)));
 }
 
 static void Dp_getHours(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, HourFromTime(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, HourFromTime(LocalTime(t)));
 }
 
 static void Dp_getMinutes(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, MinFromTime(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, MinFromTime(LocalTime(t)));
 }
 
 static void Dp_getSeconds(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, SecFromTime(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, SecFromTime(LocalTime(t)));
 }
 
 static void Dp_getMilliseconds(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, msFromTime(LocalTime(t)));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, msFromTime(LocalTime(t)));
 }
 
 static void Dp_getUTCFullYear(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, YearFromTime(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, YearFromTime(t));
 }
 
 static void Dp_getUTCMonth(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, MonthFromTime(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, MonthFromTime(t));
 }
 
 static void Dp_getUTCDate(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, DateFromTime(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, DateFromTime(t));
 }
 
 static void Dp_getUTCDay(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, WeekDay(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, WeekDay(t));
 }
 
 static void Dp_getUTCHours(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, HourFromTime(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, HourFromTime(t));
 }
 
 static void Dp_getUTCMinutes(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, MinFromTime(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, MinFromTime(t));
 }
 
 static void Dp_getUTCSeconds(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, SecFromTime(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, SecFromTime(t));
 }
 
 static void Dp_getUTCMilliseconds(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, msFromTime(t));
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, msFromTime(t));
 }
 
 static void Dp_getTimezoneOffset(js_State *J)
 {
 	double t = js_todate(J, 0);
-	js_pushnumber(J, (t - LocalTime(t)) / msPerMinute);
+	if (isnan(t))
+		js_pushnumber(J, NAN);
+	else
+		js_pushnumber(J, (t - LocalTime(t)) / msPerMinute);
 }
 
 static void Dp_setTime(js_State *J)