| Differences between
and this patch
- a/Source/JavaScriptCore/ChangeLog +14 lines
Lines 1-3 a/Source/JavaScriptCore/ChangeLog_sec1
1
2012-04-08  Patrick Gansterer  <paroga@webkit.org>
2
3
        [WIN] Use GetDateFormat and GetTimeFormat instead of strftime
4
        https://bugs.webkit.org/show_bug.cgi?id=83436
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        The MS CRT implementation of strftime calls the same two functions.
9
        Using them directly avoids the overhead of parsing the format string and removes
10
        the dependency on strftime() for WinCE where this function does not exist.
11
12
        * runtime/DatePrototype.cpp:
13
        (JSC::formatLocaleDate):
14
1
2012-04-06  Benjamin Poulain  <bpoulain@apple.com>
15
2012-04-06  Benjamin Poulain  <bpoulain@apple.com>
2
16
3
        Do not abuse ArrayStorage's m_length for testing array consistency
17
        Do not abuse ArrayStorage's m_length for testing array consistency
- a/Source/JavaScriptCore/runtime/DatePrototype.cpp -13 / +42 lines
Lines 66-75 a/Source/JavaScriptCore/runtime/DatePrototype.cpp_sec1
66
#include <unicode/udat.h>
66
#include <unicode/udat.h>
67
#endif
67
#endif
68
68
69
#if OS(WINCE) && !PLATFORM(QT)
70
extern "C" size_t strftime(char * const s, const size_t maxsize, const char * const format, const struct tm * const t); //provided by libce
71
#endif
72
73
using namespace WTF;
69
using namespace WTF;
74
70
75
namespace JSC {
71
namespace JSC {
Lines 223-244 static JSCell* formatLocaleDate(ExecState* exec, DateInstance* dateObject, doubl a/Source/JavaScriptCore/runtime/DatePrototype.cpp_sec2
223
219
224
static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, LocaleDateTimeFormat format)
220
static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, LocaleDateTimeFormat format)
225
{
221
{
222
#if OS(WINDOWS)
223
    SYSTEMTIME systemTime;
224
    memset(&systemTime, 0, sizeof(systemTime));
225
    systemTime.wYear = gdt.year + 1900;
226
    systemTime.wMonth = gdt.month + 1;
227
    systemTime.wDay = gdt.monthDay;
228
    systemTime.wDayOfWeek = gdt.weekDay;
229
    systemTime.wHour = gdt.hour;
230
    systemTime.wMinute = gdt.minute;
231
    systemTime.wSecond = gdt.second;
232
233
    UChar buffer[128];
234
    size_t length = 0;
235
236
    if (format == LocaleDate)
237
        length = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, buffer, WTF_ARRAY_LENGTH(buffer));
238
    else if (format == LocaleTime)
239
        length = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, buffer, WTF_ARRAY_LENGTH(buffer));
240
    else if (format == LocaleDateAndTime) {
241
        length = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, buffer, WTF_ARRAY_LENGTH(buffer));
242
        if (0 < length && length < WTF_ARRAY_LENGTH(buffer)) {
243
            buffer[length - 1] = ' ';
244
            length += GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systemTime, 0, buffer + length, WTF_ARRAY_LENGTH(buffer) - length);
245
        }
246
    } else
247
        ASSERT_NOT_REACHED();
248
249
    //  Remove terminating null character.
250
    if (length > 0)
251
        length--;
252
253
    return jsNontrivialString(exec, UString(buffer, length));
254
255
#else // OS(WINDOWS)
256
226
#if HAVE(LANGINFO_H)
257
#if HAVE(LANGINFO_H)
227
    static const nl_item formats[] = { D_T_FMT, D_FMT, T_FMT };
258
    static const nl_item formats[] = { D_T_FMT, D_FMT, T_FMT };
228
#elif (OS(WINCE) && !PLATFORM(QT))
229
     // strftime() does not support '#' on WinCE
230
    static const char* const formatStrings[] = { "%c", "%x", "%X" };
231
#else
259
#else
232
    static const char* const formatStrings[] = { "%#c", "%#x", "%X" };
260
    static const char* const formatStrings[] = { "%#c", "%#x", "%X" };
233
#endif
261
#endif
234
 
262
235
    // Offset year if needed
263
    // Offset year if needed
236
    struct tm localTM = gdt;
264
    struct tm localTM = gdt;
237
    int year = gdt.year + 1900;
265
    int year = gdt.year + 1900;
238
    bool yearNeedsOffset = year < 1900 || year > 2038;
266
    bool yearNeedsOffset = year < 1900 || year > 2038;
239
    if (yearNeedsOffset)
267
    if (yearNeedsOffset)
240
        localTM.tm_year = equivalentYearForDST(year) - 1900;
268
        localTM.tm_year = equivalentYearForDST(year) - 1900;
241
 
269
242
#if HAVE(LANGINFO_H)
270
#if HAVE(LANGINFO_H)
243
    // We do not allow strftime to generate dates with 2-digits years,
271
    // We do not allow strftime to generate dates with 2-digits years,
244
    // both to avoid ambiguity, and a crash in strncpy, for years that
272
    // both to avoid ambiguity, and a crash in strncpy, for years that
Lines 259-277 static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, L a/Source/JavaScriptCore/runtime/DatePrototype.cpp_sec3
259
#else
287
#else
260
    size_t ret = strftime(timebuffer, bufsize, formatStrings[format], &localTM);
288
    size_t ret = strftime(timebuffer, bufsize, formatStrings[format], &localTM);
261
#endif
289
#endif
262
 
290
263
    if (ret == 0)
291
    if (ret == 0)
264
        return jsEmptyString(exec);
292
        return jsEmptyString(exec);
265
 
293
266
    // Copy original into the buffer
294
    // Copy original into the buffer
267
    if (yearNeedsOffset && format != LocaleTime) {
295
    if (yearNeedsOffset && format != LocaleTime) {
268
        static const int yearLen = 5;   // FIXME will be a problem in the year 10,000
296
        static const int yearLen = 5;   // FIXME will be a problem in the year 10,000
269
        char yearString[yearLen];
297
        char yearString[yearLen];
270
 
298
271
        snprintf(yearString, yearLen, "%d", localTM.tm_year + 1900);
299
        snprintf(yearString, yearLen, "%d", localTM.tm_year + 1900);
272
        char* yearLocation = strstr(timebuffer, yearString);
300
        char* yearLocation = strstr(timebuffer, yearString);
273
        snprintf(yearString, yearLen, "%d", year);
301
        snprintf(yearString, yearLen, "%d", year);
274
 
302
275
        strncpy(yearLocation, yearString, yearLen - 1);
303
        strncpy(yearLocation, yearString, yearLen - 1);
276
    }
304
    }
277
305
Lines 296-301 static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, L a/Source/JavaScriptCore/runtime/DatePrototype.cpp_sec4
296
#endif
324
#endif
297
325
298
    return jsNontrivialString(exec, timebuffer);
326
    return jsNontrivialString(exec, timebuffer);
327
#endif // OS(WINDOWS)
299
}
328
}
300
329
301
static JSCell* formatLocaleDate(ExecState* exec, DateInstance* dateObject, double, LocaleDateTimeFormat format)
330
static JSCell* formatLocaleDate(ExecState* exec, DateInstance* dateObject, double, LocaleDateTimeFormat format)

Return to Bug 83436