Changeset 10556 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Sep 16, 2005, 3:42:30 PM (20 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/identifier.h
r10325 r10556 51 51 bool isEmpty() const { return _ustring.isEmpty(); } 52 52 53 unsigned long toULong(bool *ok) const { return _ustring.toULong(ok); }54 53 uint32_t toUInt32(bool *ok) const { return _ustring.toUInt32(ok); } 55 54 uint32_t toStrictUInt32(bool *ok) const { return _ustring.toStrictUInt32(ok); } -
trunk/JavaScriptCore/kjs/internal.h
r10456 r10556 117 117 friend ValueImp *jsNumber(long); 118 118 friend ValueImp *jsNumber(unsigned long); 119 friend ValueImp *jsNumber(long long); 120 friend ValueImp *jsNumber(unsigned long long); 119 121 friend ValueImp *jsNumber(double); 120 122 friend ValueImp *jsNumber(double, bool); -
trunk/JavaScriptCore/kjs/property_slot.h
r10258 r10556 75 75 } 76 76 77 void setCustomIndex(ObjectImp *slotBase, unsigned longindex, GetValueFunc getValue)77 void setCustomIndex(ObjectImp *slotBase, unsigned index, GetValueFunc getValue) 78 78 { 79 79 assert(getValue); … … 92 92 93 93 const HashEntry *staticEntry() const { return m_data.staticEntry; } 94 unsigned longindex() const { return m_data.index; }94 unsigned index() const { return m_data.index; } 95 95 96 96 private: … … 103 103 ValueImp **valueSlot; 104 104 const HashEntry *staticEntry; 105 unsigned longindex;105 unsigned index; 106 106 } m_data; 107 107 }; -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r10456 r10556 215 215 { 216 216 RegExpObjectImp *thisObj = static_cast<RegExpObjectImp *>(slot.slotBase()); 217 unsigned longi = slot.index();217 unsigned i = slot.index(); 218 218 219 219 if (i < thisObj->lastNrSubPatterns + 1) { … … 232 232 { 233 233 bool ok; 234 unsigned long i = s.substr(1).toULong(&ok); 235 if (ok) 236 { 234 unsigned i = s.substr(1).toUInt32(&ok); 235 if (ok) { 237 236 slot.setCustomIndex(this, i, backrefGetter); 238 237 return true; -
trunk/JavaScriptCore/kjs/simple_number.h
r10512 r10556 37 37 #endif 38 38 39 #define KJS_MIN_MACRO(a, b) ((a) < (b) ? (a) : (b)) 40 39 41 namespace KJS { 40 42 … … 52 54 class SimpleNumber { 53 55 public: 54 enum { tag = 1, shift = 2, mask = (1 << shift) - 1, sign = 1L << (sizeof(long) * 8 - 1 ), max = (1L << ((sizeof(long) * 8 - 1) - shift)) - 1, min = -max - 1, imax = (1L << ((sizeof(int) * 8 - 1) - shift)) - 1, imin = -imax - 1 }; 56 enum { 57 tag = 1, 58 shift = 2, 59 mask = (1 << shift) - 1, 60 bits = KJS_MIN_MACRO(sizeof(ValueImp *) * 8 - shift, sizeof(long) * 8), 61 sign = 1UL << (bits + shift - 1), 62 umax = sign >> 1, 63 smax = static_cast<long>(umax), 64 smin = static_cast<long>(-umax - 1) 65 }; 66 67 static inline bool is(const ValueImp *imp) { return ((long)imp & mask) == tag; } 68 static inline long value(const ValueImp *imp) { return ((long)imp >> shift) | (((long)imp & sign) ? ~umax : 0); } 55 69 56 static inline bool is(const ValueImp *imp) { return ((long)imp & mask) == tag; } 57 static inline long value(const ValueImp *imp) { return ((long)imp >> shift) | (((long)imp & sign) ? ~max : 0); } 58 59 static inline bool fits(int i) { return i <= imax && i >= imin; } 60 static inline bool fits(unsigned i) { return i <= (unsigned)max; } 61 static inline bool fits(long i) { return i <= max && i >= min; } 62 static inline bool fits(unsigned long i) { return i <= (unsigned)max; } 63 static inline bool integerFits(double d) { return !(d < min || d > max); } 64 static inline bool fits(double d) { return d >= min && d <= max && d == (double)(long)d && !isNegativeZero(d); } 65 static inline ValueImp *make(long i) { return (ValueImp *)((i << shift) | tag); } 70 static inline bool fits(int i) { return i <= smax && i >= smin; } 71 static inline bool fits(unsigned i) { return i <= umax; } 72 static inline bool fits(long i) { return i <= smax && i >= smin; } 73 static inline bool fits(unsigned long i) { return i <= umax; } 74 static inline bool fits(long long i) { return i <= smax && i >= smin; } 75 static inline bool fits(unsigned long long i) { return i <= umax; } 76 static inline bool integerFits(double d) { return !(d < smin || d > smax); } 77 static inline bool fits(double d) { return d >= smin && d <= smax && d == (double)(long)d && !isNegativeZero(d); } 78 static inline ValueImp *make(long i) { return reinterpret_cast<ValueImp *>(static_cast<uintptr_t>((i << shift) | tag)); } 66 79 }; 67 80 -
trunk/JavaScriptCore/kjs/string_object.cpp
r10207 r10556 243 243 } 244 244 // Assume number part is one char exactly 245 unsigned long backrefIndex = substitutedReplacement.substr(i+1,1).toULong(&converted, false /* tolerate empty string */);245 unsigned backrefIndex = substitutedReplacement.substr(i+1,1).toUInt32(&converted, false /* tolerate empty string */); 246 246 if (converted && backrefIndex <= (unsigned)reg->subPatterns()) { 247 247 int backrefStart = (*ovector)[2*backrefIndex]; -
trunk/JavaScriptCore/kjs/ustring.cpp
r10265 r10556 489 489 UString UString::from(int i) 490 490 { 491 return from((long)i); 491 UChar buf[1 + sizeof(i) * 3]; 492 UChar *end = buf + sizeof(buf) / sizeof(UChar); 493 UChar *p = end; 494 495 if (i == 0) { 496 *--p = '0'; 497 } else if (i == INT_MIN) { 498 char minBuf[1 + sizeof(i) * 3]; 499 sprintf(minBuf, "%d", INT_MIN); 500 return UString(minBuf); 501 } else { 502 bool negative = false; 503 if (i < 0) { 504 negative = true; 505 i = -i; 506 } 507 while (i) { 508 *--p = (unsigned short)((i % 10) + '0'); 509 i /= 10; 510 } 511 if (negative) { 512 *--p = '-'; 513 } 514 } 515 516 return UString(p, end - p); 492 517 } 493 518 494 519 UString UString::from(unsigned int u) 495 520 { 496 UChar buf[ 20];497 UChar *end = buf + 20;521 UChar buf[sizeof(u) * 3]; 522 UChar *end = buf + sizeof(buf) / sizeof(UChar); 498 523 UChar *p = end; 499 524 … … 512 537 UString UString::from(long l) 513 538 { 514 UChar buf[ 20];515 UChar *end = buf + 20;539 UChar buf[1 + sizeof(l) * 3]; 540 UChar *end = buf + sizeof(buf) / sizeof(UChar); 516 541 UChar *p = end; 517 542 … … 519 544 *--p = '0'; 520 545 } else if (l == LONG_MIN) { 521 char minBuf[ 20];546 char minBuf[1 + sizeof(l) * 3]; 522 547 sprintf(minBuf, "%ld", LONG_MIN); 523 548 return UString(minBuf); … … 939 964 } 940 965 941 u nsigned long UString::toULong(bool *ok, bool tolerateEmptyString) const942 { 943 double d = toDouble( false, tolerateEmptyString);966 uint32_t UString::toUInt32(bool *ok) const 967 { 968 double d = toDouble(); 944 969 bool b = true; 945 970 946 if (isNaN(d) || d != static_cast<u nsigned long>(d)) {971 if (isNaN(d) || d != static_cast<uint32_t>(d)) { 947 972 b = false; 948 973 d = 0; … … 952 977 *ok = b; 953 978 954 return static_cast<unsigned long>(d); 955 } 956 957 unsigned long UString::toULong(bool *ok) const 958 { 959 return toULong(ok, true); 960 } 961 962 uint32_t UString::toUInt32(bool *ok) const 963 { 964 double d = toDouble(); 979 return static_cast<uint32_t>(d); 980 } 981 982 uint32_t UString::toUInt32(bool *ok, bool tolerateEmptyString) const 983 { 984 double d = toDouble(false, tolerateEmptyString); 965 985 bool b = true; 966 986 … … 1047 1067 return pos; 1048 1068 const UChar *end = data() + sz - fsz; 1049 longfsizeminusone = (fsz - 1) * sizeof(UChar);1069 int fsizeminusone = (fsz - 1) * sizeof(UChar); 1050 1070 const UChar *fdata = f.data(); 1051 1071 unsigned short fchar = fdata->uc; … … 1082 1102 if (fsz == 0) 1083 1103 return pos; 1084 longfsizeminusone = (fsz - 1) * sizeof(UChar);1104 int fsizeminusone = (fsz - 1) * sizeof(UChar); 1085 1105 const UChar *fdata = f.data(); 1086 1106 for (const UChar *c = data() + pos; c >= data(); c--) { -
trunk/JavaScriptCore/kjs/ustring.h
r10325 r10556 303 303 static UString from(unsigned int u); 304 304 /** 305 * Constructs a string from a long .306 */ 307 static UString from(long l);305 * Constructs a string from a long int. 306 */ 307 static UString from(long u); 308 308 /** 309 309 * Constructs a string from a double. … … 420 420 double toDouble(bool tolerateTrailingJunk) const; 421 421 double toDouble() const; 422 /** 423 * Attempts an conversion to an unsigned long integer. ok will be set 422 423 /** 424 * Attempts an conversion to a 32-bit integer. ok will be set 424 425 * according to the success. 425 * @param tolerateEmptyString if false, toULong will return false for *ok for an empty string. 426 */ 427 unsigned long toULong(bool *ok, bool tolerateEmptyString) const; 428 unsigned long toULong(bool *ok = 0) const; 429 426 * @param tolerateEmptyString if false, toUInt32 will return false for *ok for an empty string. 427 */ 430 428 uint32_t toUInt32(bool *ok = 0) const; 429 uint32_t toUInt32(bool *ok, bool tolerateEmptyString) const; 431 430 uint32_t toStrictUInt32(bool *ok = 0) const; 432 431 -
trunk/JavaScriptCore/kjs/value.cpp
r10510 r10556 202 202 } 203 203 204 ValueImp *jsNumber(long long i) 205 { 206 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 207 } 208 209 ValueImp *jsNumber(unsigned long long i) 210 { 211 return SimpleNumber::fits(i) ? SimpleNumber::make(i) : new NumberImp(static_cast<double>(i)); 212 } 213 204 214 ValueImp *jsNumber(double d) 205 215 { -
trunk/JavaScriptCore/kjs/value.h
r10457 r10556 190 190 ValueImp *jsNumber(long); 191 191 ValueImp *jsNumber(unsigned long); 192 ValueImp *jsNumber(long long); 193 ValueImp *jsNumber(unsigned long long); 192 194 193 195 AllocatedValueImp *jsString(const UString &); // returns empty string if passed null string
Note:
See TracChangeset
for help on using the changeset viewer.