[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:20:38 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 343f9b306af5652908fef5e9b0ae97f9980359b3
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Dec 24 00:37:30 2003 +0000

            Reviewed by John (concept, not code, which is just the old code coming back).
    
            - fixed 3518092: REGRESSION (100-119): getting NaN instead of HH:MM times
    
            * kjs/date_object.cpp: Added back our CF-based implementations of gmtime, localtime,
            mktime, timegm, and time, because mktime, at least, won't handle a year of 0.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5850 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 5d52839..eff89dc 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,12 @@
+2003-12-23  Darin Adler  <darin at apple.com>
+
+        Reviewed by John (concept, not code, which is just the old code coming back).
+
+        - fixed 3518092: REGRESSION (100-119): getting NaN instead of HH:MM times
+
+        * kjs/date_object.cpp: Added back our CF-based implementations of gmtime, localtime,
+        mktime, timegm, and time, because mktime, at least, won't handle a year of 0.
+
 2003-12-19  Richard Williamson   <rjw at apple.com>
 
 	Fixed 3515597.  When an error occurs we need
diff --git a/JavaScriptCore/kjs/date_object.cpp b/JavaScriptCore/kjs/date_object.cpp
index 305f768..1d254fe 100644
--- a/JavaScriptCore/kjs/date_object.cpp
+++ b/JavaScriptCore/kjs/date_object.cpp
@@ -62,20 +62,126 @@ const time_t invalidDate = -1;
 
 #if APPLE_CHANGES
 
-// Since lots of the time call implementions on OS X hit the disk to get at the localtime file,
-// we substitute our own implementation that uses Core Foundation.
+// Originally, we wrote our own implementation that uses Core Foundation because of a performance problem in Mac OS X 10.2.
+// But we need to keep using this rather than the standard library functions because this handles a larger range of dates.
 
 #include <CoreFoundation/CoreFoundation.h>
 #include <CoreServices/CoreServices.h>
 
 using KJS::UString;
 
+#define gmtime(x) gmtimeUsingCF(x)
+#define localtime(x) localtimeUsingCF(x)
+#define mktime(x) mktimeUsingCF(x)
+#define timegm(x) timegmUsingCF(x)
+#define time(x) timeUsingCF(x)
+
 #define ctime(x) NotAllowedToCallThis()
 #define strftime(a, b, c, d) NotAllowedToCallThis()
 
 static const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
 static const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
     
+static struct tm *tmUsingCF(time_t clock, CFTimeZoneRef timeZone)
+{
+    static struct tm result;
+    static char timeZoneCString[128];
+    
+    CFAbsoluteTime absoluteTime = clock - kCFAbsoluteTimeIntervalSince1970;
+    CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(absoluteTime, timeZone);
+
+    CFStringRef abbreviation = CFTimeZoneCopyAbbreviation(timeZone, absoluteTime);
+    CFStringGetCString(abbreviation, timeZoneCString, sizeof(timeZoneCString), kCFStringEncodingASCII);
+    CFRelease(abbreviation);
+
+    result.tm_sec = (int)date.second;
+    result.tm_min = date.minute;
+    result.tm_hour = date.hour;
+    result.tm_mday = date.day;
+    result.tm_mon = date.month - 1;
+    result.tm_year = date.year - 1900;
+    result.tm_wday = CFAbsoluteTimeGetDayOfWeek(absoluteTime, timeZone) % 7;
+    result.tm_yday = CFAbsoluteTimeGetDayOfYear(absoluteTime, timeZone) - 1;
+    result.tm_isdst = CFTimeZoneIsDaylightSavingTime(timeZone, absoluteTime);
+    result.tm_gmtoff = (int)CFTimeZoneGetSecondsFromGMT(timeZone, absoluteTime);
+    result.tm_zone = timeZoneCString;
+    
+    return &result;
+}
+
+static CFTimeZoneRef UTCTimeZone()
+{
+    static CFTimeZoneRef zone = CFTimeZoneCreateWithTimeIntervalFromGMT(NULL, 0.0);
+    return zone;
+}
+
+static CFTimeZoneRef CopyLocalTimeZone()
+{
+    CFTimeZoneRef zone = CFTimeZoneCopyDefault();
+    if (zone) {
+        return zone;
+    }
+    zone = UTCTimeZone();
+    CFRetain(zone);
+    return zone;
+}
+
+static struct tm *gmtimeUsingCF(const time_t *clock)
+{
+    return tmUsingCF(*clock, UTCTimeZone());
+}
+
+static struct tm *localtimeUsingCF(const time_t *clock)
+{
+    CFTimeZoneRef timeZone = CopyLocalTimeZone();
+    struct tm *result = tmUsingCF(*clock, timeZone);
+    CFRelease(timeZone);
+    return result;
+}
+
+static time_t timetUsingCF(struct tm *tm, CFTimeZoneRef timeZone)
+{
+    CFGregorianDate date;
+    date.second = tm->tm_sec;
+    date.minute = tm->tm_min;
+    date.hour = tm->tm_hour;
+    date.day = tm->tm_mday;
+    date.month = tm->tm_mon + 1;
+    date.year = tm->tm_year + 1900;
+
+    // CFGregorianDateGetAbsoluteTime will go nuts if the year is too large or small,
+    // so we pick an arbitrary cutoff.
+    if (date.year < -2500 || date.year > 2500) {
+        return invalidDate;
+    }
+
+    CFAbsoluteTime absoluteTime = CFGregorianDateGetAbsoluteTime(date, timeZone);
+
+    return (time_t)(absoluteTime + kCFAbsoluteTimeIntervalSince1970);
+}
+
+static time_t mktimeUsingCF(struct tm *tm)
+{
+    CFTimeZoneRef timeZone = CopyLocalTimeZone();
+    time_t result = timetUsingCF(tm, timeZone);
+    CFRelease(timeZone);
+    return result;
+}
+
+static time_t timegmUsingCF(struct tm *tm)
+{
+    return timetUsingCF(tm, UTCTimeZone());
+}
+
+static time_t timeUsingCF(time_t *clock)
+{
+    time_t result = (time_t)(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970);
+    if (clock) {
+        *clock = result;
+    }
+    return result;
+}
+
 static UString formatDate(struct tm &tm)
 {
     char buffer[100];

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list