Changeset 70425 in webkit


Ignore:
Timestamp:
Oct 24, 2010 4:20:06 PM (13 years ago)
Author:
Patrick Gansterer
Message:

2010-10-24 Patrick Gansterer <Patrick Gansterer>

Reviewed by David Kilzer.

Add WTF_ARRAY_LENGTH macro to WTF
https://bugs.webkit.org/show_bug.cgi?id=32828

Unify the different implementations and usages.

  • interpreter/Interpreter.cpp: (JSC::Interpreter::privateExecute):
  • runtime/DatePrototype.cpp: (JSC::formatLocaleDate):
  • runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::reset):
  • runtime/JSONObject.cpp: (JSC::Stringifier::appendQuotedString): (JSC::Stringifier::toJSON): (JSC::Stringifier::appendStringifiedValue):
  • runtime/UString.cpp: (JSC::UString::number):
  • wtf/DateMath.cpp: (WTF::parseDateFromNullTerminatedCharacters):
  • wtf/StdLibExtras.h:
Location:
trunk/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r70421 r70425  
     12010-10-24  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Reviewed by David Kilzer.
     4
     5        Add WTF_ARRAY_LENGTH macro to WTF
     6        https://bugs.webkit.org/show_bug.cgi?id=32828
     7
     8        Unify the different implementations and usages.
     9
     10        * interpreter/Interpreter.cpp:
     11        (JSC::Interpreter::privateExecute):
     12        * runtime/DatePrototype.cpp:
     13        (JSC::formatLocaleDate):
     14        * runtime/JSGlobalObject.cpp:
     15        (JSC::JSGlobalObject::reset):
     16        * runtime/JSONObject.cpp:
     17        (JSC::Stringifier::appendQuotedString):
     18        (JSC::Stringifier::toJSON):
     19        (JSC::Stringifier::appendStringifiedValue):
     20        * runtime/UString.cpp:
     21        (JSC::UString::number):
     22        * wtf/DateMath.cpp:
     23        (WTF::parseDateFromNullTerminatedCharacters):
     24        * wtf/StdLibExtras.h:
     25
    1262010-10-24  Dirk Schulze  <krit@webkit.org>
    227
  • trunk/JavaScriptCore/interpreter/Interpreter.cpp

    r70406 r70425  
    14381438            #define LIST_OPCODE_LABEL(id, length) &&id,
    14391439                static Opcode labels[] = { FOR_EACH_OPCODE_ID(LIST_OPCODE_LABEL) };
    1440                 for (size_t i = 0; i < sizeof(labels) / sizeof(Opcode); ++i)
     1440                for (size_t i = 0; i < WTF_ARRAY_LENGTH(labels); ++i)
    14411441                    m_opcodeTable[i] = labels[i];
    14421442            #undef LIST_OPCODE_LABEL
  • trunk/JavaScriptCore/runtime/DatePrototype.cpp

    r67826 r70425  
    183183    // That's not great error handling, but it just won't happen so it doesn't matter.
    184184    UChar buffer[200];
    185     const size_t bufferLength = sizeof(buffer) / sizeof(buffer[0]);
     185    const size_t bufferLength = WTF_ARRAY_LENGTH(buffer);
    186186    size_t length = CFStringGetLength(string);
    187187    ASSERT(length <= bufferLength);
  • trunk/JavaScriptCore/runtime/JSGlobalObject.cpp

    r70406 r70425  
    308308    };
    309309
    310     addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
     310    addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
    311311
    312312    // Set global functions.
  • trunk/JavaScriptCore/runtime/JSONObject.cpp

    r69683 r70425  
    330330                UChar ch = data[i];
    331331                UChar hex[] = { '\\', 'u', hexDigits[(ch >> 12) & 0xF], hexDigits[(ch >> 8) & 0xF], hexDigits[(ch >> 4) & 0xF], hexDigits[ch & 0xF] };
    332                 builder.append(hex, sizeof(hex) / sizeof(UChar));
     332                builder.append(hex, WTF_ARRAY_LENGTH(hex));
    333333                break;
    334334        }
     
    358358
    359359    JSValue list[] = { propertyName.value(m_exec) };
    360     ArgList args(list, sizeof(list) / sizeof(JSValue));
     360    ArgList args(list, WTF_ARRAY_LENGTH(list));
    361361    return call(m_exec, object, callType, callData, value, args);
    362362}
     
    372372    if (m_replacerCallType != CallTypeNone) {
    373373        JSValue list[] = { propertyName.value(m_exec), value };
    374         ArgList args(list, sizeof(list) / sizeof(JSValue));
     374        ArgList args(list, WTF_ARRAY_LENGTH(list));
    375375        value = call(m_exec, m_replacer, m_replacerCallType, m_replacerCallData, holder, args);
    376376        if (m_exec->hadException())
  • trunk/JavaScriptCore/runtime/UString.cpp

    r66245 r70425  
    9191{
    9292    UChar buf[1 + sizeof(i) * 3];
    93     UChar* end = buf + sizeof(buf) / sizeof(UChar);
     93    UChar* end = buf + WTF_ARRAY_LENGTH(buf);
    9494    UChar* p = end;
    9595
     
    120120{
    121121    UChar buf[1 + sizeof(i) * 3];
    122     UChar* end = buf + sizeof(buf) / sizeof(UChar);
     122    UChar* end = buf + WTF_ARRAY_LENGTH(buf);
    123123    UChar* p = end;
    124124
     
    153153{
    154154    UChar buf[sizeof(u) * 3];
    155     UChar* end = buf + sizeof(buf) / sizeof(UChar);
     155    UChar* end = buf + WTF_ARRAY_LENGTH(buf);
    156156    UChar* p = end;
    157157
     
    171171{
    172172    UChar buf[1 + sizeof(l) * 3];
    173     UChar* end = buf + sizeof(buf) / sizeof(UChar);
     173    UChar* end = buf + WTF_ARRAY_LENGTH(buf);
    174174    UChar* p = end;
    175175
  • trunk/JavaScriptCore/wtf/DateMath.cpp

    r70076 r70425  
    951951            haveTZ = true;
    952952        } else {
    953             for (int i = 0; i < int(sizeof(known_zones) / sizeof(KnownZone)); i++) {
     953            for (size_t i = 0; i < WTF_ARRAY_LENGTH(known_zones); ++i) {
    954954                if (0 == strncasecmp(dateString, known_zones[i].tzName, strlen(known_zones[i].tzName))) {
    955955                    offset = known_zones[i].tzOffset;
  • trunk/JavaScriptCore/wtf/StdLibExtras.h

    r70419 r70425  
    111111}
    112112
     113// Macro that returns a compile time constant with the length of an array, but gives an error if passed a non-array.
     114template<typename T, size_t Size> char (&ArrayLengthHelperFunction(T (&)[Size]))[Size];
     115#define WTF_ARRAY_LENGTH(array) sizeof(::WTF::ArrayLengthHelperFunction(array))
     116
    113117} // namespace WTF
    114118
Note: See TracChangeset for help on using the changeset viewer.