Ignore:
Timestamp:
Oct 30, 2002, 12:15:02 PM (23 years ago)
Author:
darin
Message:
  • fixed 3073230 -- Alex is doing file I/O when executing JavaScript by asking for localtime

I fixed this by using Core Foundation time functions instead.

  • kjs/date_object.cpp: (tmUsingCF): Function that uses Core Foundation to get the time and then puts it into a tm struct. (gmtimeUsingCF): Function used instead of gmtime (used a macro to make the substitution). (localtimeUsingCF): Function used instead of localtime (used a macro to make the substitution).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/date_object.cpp

    r1799 r2511  
    5757
    5858#include "date_object.lut.h"
     59
     60#if APPLE_CHANGES
     61
     62// Since gmtime and localtime hit the disk, we substitute our own implementation
     63// that uses Core Foundation.
     64
     65#include <CoreFoundation/CoreFoundation.h>
     66
     67#define gmtime(x) gmtimeUsingCF(x)
     68#define localtime(x) localtimeUsingCF(x)
     69
     70struct tm *tmUsingCF(time_t tv, CFTimeZoneRef timeZone)
     71{
     72    static struct tm result;
     73    static char timeZoneCString[128];
     74   
     75    CFAbsoluteTime absoluteTime = tv - kCFAbsoluteTimeIntervalSince1970;
     76   
     77    CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(absoluteTime, timeZone);
     78   
     79    CFStringRef abbreviation = CFTimeZoneCopyAbbreviation(timeZone, absoluteTime);
     80   
     81    CFStringGetCString(abbreviation, timeZoneCString, sizeof(timeZoneCString), kCFStringEncodingASCII);
     82
     83    result.tm_sec = (int)date.second;
     84    result.tm_min = date.minute;
     85    result.tm_hour = date.hour;
     86    result.tm_mday = date.day;
     87    result.tm_mon = date.month - 1;
     88    result.tm_year = date.year - 1900;
     89    result.tm_wday = CFAbsoluteTimeGetDayOfWeek(absoluteTime, timeZone) % 7;
     90    result.tm_yday = CFAbsoluteTimeGetDayOfYear(absoluteTime, timeZone) - 1;
     91    result.tm_isdst = CFTimeZoneIsDaylightSavingTime(timeZone, absoluteTime);
     92    result.tm_gmtoff = (int)CFTimeZoneGetSecondsFromGMT(timeZone, absoluteTime);
     93    result.tm_zone = timeZoneCString;
     94   
     95    CFRelease(abbreviation);
     96   
     97    return &result;
     98}
     99
     100struct tm *gmtimeUsingCF(const time_t *tv)
     101{
     102    static CFTimeZoneRef timeZoneUTC = CFTimeZoneCreateWithName(NULL, CFSTR("UTC"), TRUE);
     103    return tmUsingCF(*tv, timeZoneUTC);
     104}
     105
     106struct tm *localtimeUsingCF(const time_t *tv)
     107{
     108    CFTimeZoneRef timeZone = CFTimeZoneCopyDefault();
     109    struct tm *result = tmUsingCF(*tv, timeZone);
     110    CFRelease(timeZone);
     111    return result;
     112}
     113
     114#endif // APPLE_CHANGES
    59115
    60116using namespace KJS;
Note: See TracChangeset for help on using the changeset viewer.