new Date(NaN)

Harri Porten porten at froglogic.com
Thu Nov 20 23:02:40 CET 2003


Hi,

last time I checked the Date implementation was different in
JavaScriptCore. Not sure whether the attached patch is required. In kjs it
fixes all Date getter functions to return NaN if the date value is NaN
itself.

Harri.
-------------- next part --------------
Index: ChangeLog
===================================================================
RCS file: /home/kde/kdelibs/kjs/ChangeLog,v
retrieving revision 1.31
diff -u -3 -p -r1.31 ChangeLog
--- ChangeLog	18 Nov 2003 09:36:50 -0000	1.31
+++ ChangeLog	20 Nov 2003 20:57:44 -0000
@@ -1,3 +1,8 @@
+2003-11-20  Harri Porten  <porten at kde.org>
+
+	* date_object.cpp: return NaN in getter functions if the time
+	value is NaN itself.
+
 2003-11-18  Harri Porten  <porten at kde.org>
 
 	* reference_list.cpp: patch by Maciej that initializes
Index: date_object.cpp
===================================================================
RCS file: /home/kde/kdelibs/kjs/date_object.cpp,v
retrieving revision 1.74
diff -u -3 -p -r1.74 date_object.cpp
--- date_object.cpp	27 Oct 2003 00:59:07 -0000	1.74
+++ date_object.cpp	20 Nov 2003 20:57:45 -0000
@@ -179,6 +179,12 @@ Value DateProtoFuncImp::call(ExecState *
     oldlocale = setlocale(LC_ALL, NULL);
   Value v = thisObj.internalValue();
   double milli = v.toNumber(exec);
+  // special case: time value is NaN
+  if (isNaN(milli) && (id == GetYear || id == GetFullYear || id == GetMonth ||
+                       id == GetDate || id == GetDay || id == GetHours ||
+                       id == GetMinutes || id == GetSeconds ||
+                       id == GetMilliSeconds || id == GetTimezoneOffset))
+    return Number(NaN);
   time_t tv = (time_t) floor(milli / 1000.0);
   int ms = int(milli - tv * 1000.0);
 


More information about the Khtml-devel mailing list