Changeset 39809 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Jan 11, 2009, 1:58:23 PM (16 years ago)
Author:
Darin Adler
Message:

2009-01-11 Darin Adler <Darin Adler>

Reviewed by Dan Bernstein.

Bug 23239: improve handling of unused arguments in JavaScriptCore
https://bugs.webkit.org/show_bug.cgi?id=23239

  • runtime/DatePrototype.cpp: Moved LocaleDateTimeFormat enum outside #if so we can use this on all platforms. Changed valueOf to share the same function with getTime, since the contents of the two are identical. Removed a FIXME since the idea isn't really specific enough or helpful enough to need to sit here in the source code. (JSC::formatLocaleDate): Changed the Mac version of this function to take the same arguments as the non-Mac version so the caller doesn't have to special-case the two platforms. Also made the formatString array be const; before the characters were, but the array was a modifiable global variable. (JSC::dateProtoFuncToLocaleString): Changed to call the new unified version of formatLocaleDate and remove the ifdef. (JSC::dateProtoFuncToLocaleDateString): Ditto. (JSC::dateProtoFuncToLocaleTimeString): Ditto.
  • runtime/JSNotAnObject.cpp: (JSC::JSNotAnObject::toObject): Use the new ASSERT_UNUSED instead of the old UNUSED_PARAM.
  • runtime/RegExp.cpp: (JSC::RegExp::RegExp): Changed to only use UNUSED_PARAM when the parameter is actually unused.
  • wtf/TCSystemAlloc.cpp: (TCMalloc_SystemRelease): Changed to only use UNUSED_PARAM when the parameter is actually unused. (TCMalloc_SystemCommit): Changed to omit the argument names instead of using UNUSED_PARAM.
Location:
trunk/JavaScriptCore/runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/DatePrototype.cpp

    r39670 r39809  
    102102static JSValuePtr dateProtoFuncToTimeString(ExecState*, JSObject*, JSValuePtr, const ArgList&);
    103103static JSValuePtr dateProtoFuncToUTCString(ExecState*, JSObject*, JSValuePtr, const ArgList&);
    104 static JSValuePtr dateProtoFuncValueOf(ExecState*, JSObject*, JSValuePtr, const ArgList&);
    105104
    106105}
     
    110109namespace JSC {
    111110
     111enum LocaleDateTimeFormat { LocaleDateAndTime, LocaleDate, LocaleTime };
     112 
    112113#if PLATFORM(MAC)
     114
     115// FIXME: Since this is superior to the strftime-based version, why limit this to PLATFORM(MAC)?
     116// Instead we should consider using this whenever PLATFORM(CF) is true.
    113117
    114118static CFDateFormatterStyle styleFromArgString(const UString& string, CFDateFormatterStyle defaultStyle)
     
    125129}
    126130
    127 static UString formatLocaleDate(ExecState* exec, double time, bool includeDate, bool includeTime, const ArgList& args)
    128 {
    129     CFDateFormatterStyle dateStyle = (includeDate ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle);
    130     CFDateFormatterStyle timeStyle = (includeTime ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle);
     131static JSCell* formatLocaleDate(ExecState* exec, DateInstance*, double timeInMilliseconds, LocaleDateTimeFormat format, const ArgList& args)
     132{
     133    CFDateFormatterStyle dateStyle = (format != LocaleTime ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle);
     134    CFDateFormatterStyle timeStyle = (format != LocaleDate ? kCFDateFormatterLongStyle : kCFDateFormatterNoStyle);
    131135
    132136    bool useCustomFormat = false;
     
    137141        useCustomFormat = true;
    138142        customFormatString = args.at(exec, 1)->toString(exec);
    139     } else if (includeDate && includeTime && !args.at(exec, 1)->isUndefined()) {
     143    } else if (format == LocaleDateAndTime && !args.at(exec, 1)->isUndefined()) {
    140144        dateStyle = styleFromArgString(arg0String, dateStyle);
    141145        timeStyle = styleFromArgString(args.at(exec, 1)->toString(exec), timeStyle);
    142     } else if (includeDate && !args.at(exec, 0)->isUndefined())
     146    } else if (format != LocaleTime && !args.at(exec, 0)->isUndefined())
    143147        dateStyle = styleFromArgString(arg0String, dateStyle);
    144     else if (includeTime && !args.at(exec, 0)->isUndefined())
     148    else if (format != LocaleDate && !args.at(exec, 0)->isUndefined())
    145149        timeStyle = styleFromArgString(arg0String, timeStyle);
    146150
     
    150154
    151155    if (useCustomFormat) {
    152         CFStringRef customFormatCFString = CFStringCreateWithCharacters(0, (UniChar *)customFormatString.data(), customFormatString.size());
     156        CFStringRef customFormatCFString = CFStringCreateWithCharacters(0, customFormatString.data(), customFormatString.size());
    153157        CFDateFormatterSetFormat(formatter, customFormatCFString);
    154158        CFRelease(customFormatCFString);
    155159    }
    156160
    157     CFStringRef string = CFDateFormatterCreateStringWithAbsoluteTime(0, formatter, time - kCFAbsoluteTimeIntervalSince1970);
     161    CFStringRef string = CFDateFormatterCreateStringWithAbsoluteTime(0, formatter, floor(timeInMilliseconds / msPerSecond) - kCFAbsoluteTimeIntervalSince1970);
    158162
    159163    CFRelease(formatter);
     
    167171    if (length > bufferLength)
    168172        length = bufferLength;
    169     CFStringGetCharacters(string, CFRangeMake(0, length), reinterpret_cast<UniChar *>(buffer));
     173    CFStringGetCharacters(string, CFRangeMake(0, length), buffer);
    170174
    171175    CFRelease(string);
    172176
    173     return UString(buffer, length);
    174 }
    175 
    176 #else
    177 
    178 enum LocaleDateTimeFormat { LocaleDateAndTime, LocaleDate, LocaleTime };
    179  
    180 static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, const LocaleDateTimeFormat format)
    181 {
    182     static const char* formatStrings[] = {"%#c", "%#x", "%X"};
     177    return jsNontrivialString(exec, UString(buffer, length));
     178}
     179
     180#else // !PLATFORM(MAC)
     181
     182static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, LocaleDateTimeFormat format)
     183{
     184    static const char* const formatStrings[] = { "%#c", "%#x", "%X" };
    183185 
    184186    // Offset year if needed
     
    212214}
    213215
    214 #endif // PLATFORM(WIN_OS)
     216static JSCell* formatLocaleDate(ExecState* exec, DateInstance* dateObject, double timeInMilliseconds, LocaleDateTimeFormat format, const ArgList&)
     217{
     218    GregorianDateTime gregorianDateTime;
     219    const bool notUTC = false;
     220    dateObject->msToGregorianDateTime(timeInMilliseconds, notUTC, gregorianDateTime);
     221    return formatLocaleDate(exec, gregorianDateTime, format);
     222}
     223
     224#endif // !PLATFORM(MAC)
    215225
    216226// Converts a list of arguments sent to a Date member function into milliseconds, updating
     
    296306
    297307/* Source for DatePrototype.lut.h
    298    FIXME: We could use templates to simplify the UTC variants.
    299308@begin dateTable
    300309  toString              dateProtoFuncToString                DontEnum|Function       0
     
    305314  toLocaleDateString    dateProtoFuncToLocaleDateString      DontEnum|Function       0
    306315  toLocaleTimeString    dateProtoFuncToLocaleTimeString      DontEnum|Function       0
    307   valueOf               dateProtoFuncValueOf                 DontEnum|Function       0
     316  valueOf               dateProtoFuncGetTime                 DontEnum|Function       0
    308317  getTime               dateProtoFuncGetTime                 DontEnum|Function       0
    309318  getFullYear           dateProtoFuncGetFullYear             DontEnum|Function       0
     
    344353@end
    345354*/
     355
    346356// ECMA 15.9.4
    347357
     
    438448        return jsNontrivialString(exec, "Invalid Date");
    439449
    440 #if PLATFORM(MAC)
    441     double secs = floor(milli / msPerSecond);
    442     return jsNontrivialString(exec, formatLocaleDate(exec, secs, true, true, args));
    443 #else
    444     UNUSED_PARAM(args);
    445 
    446     const bool utc = false;
    447 
    448     GregorianDateTime t;
    449     thisDateObj->msToGregorianDateTime(milli, utc, t);
    450     return formatLocaleDate(exec, t, LocaleDateAndTime);
    451 #endif
     450    return formatLocaleDate(exec, thisDateObj, milli, LocaleDateAndTime, args);
    452451}
    453452
     
    462461        return jsNontrivialString(exec, "Invalid Date");
    463462
    464 #if PLATFORM(MAC)
    465     double secs = floor(milli / msPerSecond);
    466     return jsNontrivialString(exec, formatLocaleDate(exec, secs, true, false, args));
    467 #else
    468     UNUSED_PARAM(args);
    469 
    470     const bool utc = false;
    471 
    472     GregorianDateTime t;
    473     thisDateObj->msToGregorianDateTime(milli, utc, t);
    474     return formatLocaleDate(exec, t, LocaleDate);
    475 #endif
     463    return formatLocaleDate(exec, thisDateObj, milli, LocaleDate, args);
    476464}
    477465
     
    486474        return jsNontrivialString(exec, "Invalid Date");
    487475
    488 #if PLATFORM(MAC)
    489     double secs = floor(milli / msPerSecond);
    490     return jsNontrivialString(exec, formatLocaleDate(exec, secs, false, true, args));
    491 #else
    492     UNUSED_PARAM(args);
    493 
    494     const bool utc = false;
    495 
    496     GregorianDateTime t;
    497     thisDateObj->msToGregorianDateTime(milli, utc, t);
    498     return formatLocaleDate(exec, t, LocaleTime);
    499 #endif
    500 }
    501 
    502 JSValuePtr dateProtoFuncValueOf(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&)
    503 {
    504     if (!thisValue->isObject(&DateInstance::info))
    505         return throwError(exec, TypeError);
    506 
    507     DateInstance* thisDateObj = asDateInstance(thisValue);
    508     double milli = thisDateObj->internalNumber();
    509     if (isnan(milli))
    510         return jsNaN(exec);
    511 
    512     return jsNumber(exec, milli);
     476    return formatLocaleDate(exec, thisDateObj, milli, LocaleTime, args);
    513477}
    514478
  • trunk/JavaScriptCore/runtime/JSNotAnObject.cpp

    r39670 r39809  
    7070JSObject* JSNotAnObject::toObject(ExecState* exec) const
    7171{
    72     UNUSED_PARAM(exec);
    73     ASSERT(exec->hadException() && exec->exception() == m_exception);
     72    ASSERT_UNUSED(exec, exec->hadException() && exec->exception() == m_exception);
    7473    return m_exception;
    7574}
  • trunk/JavaScriptCore/runtime/RegExp.cpp

    r39162 r39809  
    4545    , m_numSubpatterns(0)
    4646{
    47     UNUSED_PARAM(globalData);
    4847#if ENABLE(WREC)
    4948    m_wrecFunction = Generator::compileRegExp(globalData, pattern, &m_numSubpatterns, &m_constructionError, m_executablePool);
     
    5150        return;
    5251    // Fall through to non-WREC case.
     52#else
     53    UNUSED_PARAM(globalData);
    5354#endif
    5455    m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
     
    6970    , m_numSubpatterns(0)
    7071{
    71     UNUSED_PARAM(globalData);
    72 
    7372    // NOTE: The global flag is handled on a case-by-case basis by functions like
    7473    // String::match and RegExpObject::match.
     
    9493        return;
    9594    // Fall through to non-WREC case.
     95#else
     96    UNUSED_PARAM(globalData);
    9697#endif
    9798    m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
Note: See TracChangeset for help on using the changeset viewer.