Changeset 65295 in webkit for trunk/JavaScriptCore/runtime
- Timestamp:
- Aug 12, 2010, 8:58:37 PM (15 years ago)
- Location:
- trunk/JavaScriptCore/runtime
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/Arguments.cpp
r65177 r65295 158 158 { 159 159 bool isArrayIndex; 160 unsigned i = propertyName.toArrayIndex(&isArrayIndex);160 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 161 161 if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) { 162 162 if (i < d->numParameters) { … … 183 183 { 184 184 bool isArrayIndex; 185 unsigned i = propertyName.toArrayIndex(&isArrayIndex);185 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 186 186 if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) { 187 187 if (i < d->numParameters) { … … 234 234 { 235 235 bool isArrayIndex; 236 unsigned i = propertyName.toArrayIndex(&isArrayIndex);236 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 237 237 if (isArrayIndex && i < d->numArguments && (!d->deletedArguments || !d->deletedArguments[i])) { 238 238 if (i < d->numParameters) … … 277 277 { 278 278 bool isArrayIndex; 279 unsigned i = propertyName.toArrayIndex(&isArrayIndex);279 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 280 280 if (isArrayIndex && i < d->numArguments) { 281 281 if (!d->deletedArguments) { -
trunk/JavaScriptCore/runtime/DateConversion.cpp
r56560 r65295 57 57 if (date == exec->globalData().cachedDateString) 58 58 return exec->globalData().cachedDateStringValue; 59 double value = parseDateFromNullTerminatedCharacters(exec, date. UTF8String().data());59 double value = parseDateFromNullTerminatedCharacters(exec, date.utf8().data()); 60 60 exec->globalData().cachedDateString = date; 61 61 exec->globalData().cachedDateStringValue = value; -
trunk/JavaScriptCore/runtime/Identifier.h
r65177 r65295 45 45 Identifier(JSGlobalData* globalData, const UString& s) : m_string(add(globalData, s.impl())) { } 46 46 47 // Special constructor for cases where we overwrite an object in place.48 Identifier(PlacementNewAdoptType) : m_string(PlacementNewAdopt) { }49 50 47 const UString& ustring() const { return m_string; } 51 48 StringImpl* impl() const { return m_string.impl(); } … … 69 66 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return m_string.toUInt32(ok, tolerateEmptyString); }; 70 67 uint32_t toStrictUInt32(bool* ok) const { return m_string.toStrictUInt32(ok); } 71 unsigned toArrayIndex(bool* ok) const { return m_string.toArrayIndex(ok); }72 68 double toDouble() const { return m_string.toDouble(); } 73 69 -
trunk/JavaScriptCore/runtime/JSArray.cpp
r64937 r65295 274 274 275 275 bool isArrayIndex; 276 unsigned i = propertyName.toArrayIndex(&isArrayIndex);276 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 277 277 if (isArrayIndex) 278 278 return JSArray::getOwnPropertySlot(exec, i, slot); … … 291 291 292 292 bool isArrayIndex; 293 unsigned i = propertyName.toArrayIndex(&isArrayIndex);293 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 294 294 if (isArrayIndex) { 295 295 if (i >= storage->m_length) … … 318 318 { 319 319 bool isArrayIndex; 320 unsigned i = propertyName.toArrayIndex(&isArrayIndex);320 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 321 321 if (isArrayIndex) { 322 322 put(exec, i, value); … … 476 476 { 477 477 bool isArrayIndex; 478 unsigned i = propertyName.toArrayIndex(&isArrayIndex);478 unsigned i = toArrayIndex(propertyName.ustring(), &isArrayIndex); 479 479 if (isArrayIndex) 480 480 return deleteProperty(exec, i); -
trunk/JavaScriptCore/runtime/JSArray.h
r65146 r65295 262 262 } 263 263 } 264 264 265 // Rule from ECMA 15.2 about what an array index is. 266 // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1. 267 inline unsigned toArrayIndex(const UString& string, bool* ok) 268 { 269 unsigned i = string.toStrictUInt32(ok); 270 if (ok && i >= 0xFFFFFFFFU) 271 *ok = false; 272 return i; 273 } 274 265 275 } // namespace JSC 266 276 -
trunk/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r65177 r65295 54 54 { 55 55 UString str = exec->argument(0).toString(exec); 56 CString cstr = str. UTF8String(true);56 CString cstr = str.utf8(true); 57 57 if (!cstr.data()) 58 58 return throwError(exec, createURIError(exec, "String contained an illegal UTF-16 sequence.")); … … 266 266 if (number >= mantissaOverflowLowerBound) { 267 267 if (radix == 10) 268 number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition). UTF8String().data(), 0);268 number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition).utf8().data(), 0); 269 269 else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32) 270 number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition). UTF8String().data(), p - firstDigitPosition, radix);270 number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).utf8().data(), p - firstDigitPosition, radix); 271 271 } 272 272 … … 454 454 EncodedJSValue JSC_HOST_CALL globalFuncJSCPrint(ExecState* exec) 455 455 { 456 CString string = exec->argument(0).toString(exec). UTF8String();456 CString string = exec->argument(0).toString(exec).utf8(); 457 457 puts(string.data()); 458 458 return JSValue::encode(jsUndefined()); -
trunk/JavaScriptCore/runtime/JSString.h
r65177 r65295 192 192 { 193 193 ASSERT(!m_value.isNull()); 194 Heap::heap(this)->reportExtraMemoryCost(value. cost());194 Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost()); 195 195 } 196 196 … … 309 309 m_other.m_finalizerCallback = finalizer; 310 310 m_other.m_finalizerContext = context; 311 Heap::heap(this)->reportExtraMemoryCost(value. cost());311 Heap::heap(this)->reportExtraMemoryCost(value.impl()->cost()); 312 312 } 313 313 -
trunk/JavaScriptCore/runtime/UString.cpp
r65289 r65295 258 258 } 259 259 260 // FIXME: If tolerateTrailingJunk is true, then we want to tolerate junk261 // after the number, even if it contains invalid UTF-16 sequences. So we262 // shouldn't use the UTF8String function, which returns null when it263 // encounters invalid UTF-16. Further, we have no need to convert the264 // non-ASCII characters to UTF-8, so the UTF8String does quite a bit of265 // unnecessary work.266 267 // FIXME: The space skipping code below skips only ASCII spaces, but callers268 // need to skip all StrWhiteSpace. The isStrWhiteSpace function does the269 // right thing but requires UChar, not char, for its argument.270 271 260 const UChar* data = this->characters(); 272 261 const UChar* end = data + size; … … 595 584 } 596 585 597 CString UString::UTF8String(bool strict) const 598 { 599 // Allocate a buffer big enough to hold all the characters. 600 const unsigned len = length(); 601 Vector<char, 1024> buffer(len * 3); 602 603 // Convert to runs of 8-bit characters. 604 char* p = buffer.data(); 605 const UChar* d = reinterpret_cast<const UChar*>(&characters()[0]); 606 ConversionResult result = convertUTF16ToUTF8(&d, d + len, &p, p + buffer.size(), strict); 607 if (result != conversionOK) 586 // Helper to write a three-byte UTF-8 code point to the buffer, caller must check room is available. 587 static inline void putUTF8Triple(char*& buffer, UChar ch) 588 { 589 ASSERT(ch >= 0x0800); 590 *buffer++ = static_cast<char>(((ch >> 12) & 0x0F) | 0xE0); 591 *buffer++ = static_cast<char>(((ch >> 6) & 0x3F) | 0x80); 592 *buffer++ = static_cast<char>((ch & 0x3F) | 0x80); 593 } 594 595 CString UString::utf8(bool strict) const 596 { 597 unsigned length = this->length(); 598 const UChar* characters = this->characters(); 599 600 // Allocate a buffer big enough to hold all the characters 601 // (an individual UTF-16 UChar can only expand to 3 UTF-8 bytes). 602 // Optimization ideas, if we find this function is hot: 603 // * We could speculatively create a CStringBuffer to contain 'length' 604 // characters, and resize if necessary (i.e. if the buffer contains 605 // non-ascii characters). (Alternatively, scan the buffer first for 606 // ascii characters, so we know this will be sufficient). 607 // * We could allocate a CStringBuffer with an appropriate size to 608 // have a good chance of being able to write the string into the 609 // buffer without reallocing (say, 1.5 x length). 610 Vector<char, 1024> bufferVector(length * 3); 611 612 char* buffer = bufferVector.data(); 613 ConversionResult result = convertUTF16ToUTF8(&characters, characters + length, &buffer, buffer + bufferVector.size(), strict); 614 ASSERT(result != targetExhausted); // (length * 3) should be sufficient for any conversion 615 616 if (result == sourceIllegal) // Only produced from strict conversion. 608 617 return CString(); 609 618 610 return CString(buffer.data(), p - buffer.data()); 619 // If a high surrogate is left unconverted, treat it the same was as an unpaired high surrogate 620 // would have been handled in the middle of a string with non-strict conversion - which is to say, 621 // simply encode it to UTF-8. 622 if (result == sourceExhausted) { 623 // This should be one unpaired high surrogate. 624 ASSERT((characters + 1) == (this->characters() + length)); 625 ASSERT((*characters >= 0xD800) && (*characters <= 0xDBFF)); 626 // There should be room left, since one UChar hasn't been converted. 627 ASSERT((buffer + 3) <= (buffer + bufferVector.size())); 628 putUTF8Triple(buffer, *characters); 629 } 630 631 return CString(bufferVector.data(), buffer - bufferVector.data()); 611 632 } 612 633 -
trunk/JavaScriptCore/runtime/UString.h
r65289 r65295 39 39 namespace JSC { 40 40 41 using WTF::PlacementNewAdoptType;42 using WTF::PlacementNewAdopt;43 44 41 class UString { 45 42 public: … … 64 61 UString(RefPtr<StringImpl> impl) : m_impl(impl) { } 65 62 63 // Inline the destructor. 64 ALWAYS_INLINE ~UString() { } 65 66 66 void swap(UString& o) { m_impl.swap(o.m_impl); } 67 67 … … 69 69 static UString adopt(Vector<UChar, inlineCapacity>& vector) { return StringImpl::adopt(vector); } 70 70 71 static UString number(int); 72 static UString number(long long); 73 static UString number(unsigned); 74 static UString number(long); 75 static UString number(double); 76 77 // NOTE: This method should only be used for *debugging* purposes as it 78 // is neither Unicode safe nor free from side effects nor thread-safe. 79 char* ascii() const; 80 81 /** 82 * Convert the string to UTF-8, assuming it is UTF-16 encoded. 83 * In non-strict mode, this function is tolerant of badly formed UTF-16, it 84 * can create UTF-8 strings that are invalid because they have characters in 85 * the range U+D800-U+DDFF, U+FFFE, or U+FFFF, but the UTF-8 string is 86 * guaranteed to be otherwise valid. 87 * In strict mode, error is returned as null CString. 88 */ 89 CString UTF8String(bool strict = false) const; 71 bool isNull() const { return !m_impl; } 72 bool isEmpty() const { return !m_impl || !m_impl->length(); } 73 74 StringImpl* impl() const { return m_impl.get(); } 90 75 91 76 unsigned length() const … … 103 88 } 104 89 90 CString utf8(bool strict = false) const; 91 105 92 UChar operator[](unsigned index) const 106 93 { … … 110 97 } 111 98 99 static UString number(int); 100 static UString number(unsigned); 101 static UString number(long); 102 static UString number(long long); 103 static UString number(double); 104 105 106 112 107 double toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const; 113 108 double toDouble(bool tolerateTrailingJunk) const; … … 117 112 uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const; 118 113 uint32_t toStrictUInt32(bool* ok = 0) const; 119 120 unsigned toArrayIndex(bool* ok = 0) const;121 114 122 115 static const unsigned NotFound = 0xFFFFFFFFu; … … 128 121 UString substr(unsigned pos = 0, unsigned len = 0xFFFFFFFF) const; 129 122 130 bool isNull() const { return !m_impl; } 131 bool isEmpty() const { return !m_impl || !m_impl->length(); } 132 133 StringImpl* impl() const { return m_impl.get(); } 134 135 size_t cost() const 136 { 137 if (!m_impl) 138 return 0; 139 return m_impl->cost(); 140 } 141 142 ALWAYS_INLINE ~UString() { } 123 // NOTE: This method should only be used for *debugging* purposes as it 124 // is neither Unicode safe nor free from side effects nor thread-safe. 125 char* ascii() const; 126 143 127 private: 144 128 RefPtr<StringImpl> m_impl; … … 218 202 } 219 203 220 // Rule from ECMA 15.2 about what an array index is.221 // Must exactly match string form of an unsigned integer, and be less than 2^32 - 1.222 inline unsigned UString::toArrayIndex(bool* ok) const223 {224 unsigned i = toStrictUInt32(ok);225 if (ok && i >= 0xFFFFFFFFU)226 *ok = false;227 return i;228 }229 230 204 // We'd rather not do shared substring append for small strings, since 231 205 // this runs too much risk of a tiny initial string holding down a
Note:
See TracChangeset
for help on using the changeset viewer.