Changeset 203834 in webkit
- Timestamp:
- Jul 28, 2016 1:28:47 PM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r203817 r203834 1 2016-07-28 Mark Lam <mark.lam@apple.com> 2 3 StringView should have an explicit m_is8Bit field. 4 https://bugs.webkit.org/show_bug.cgi?id=160282 5 <rdar://problem/27327943> 6 7 Reviewed by Benjamin Poulain. 8 9 * tests/stress/string-joining-long-strings-should-not-crash.js: Added. 10 (catch): 11 1 12 2016-07-28 Csaba Osztrogonác <ossy@webkit.org> 2 13 -
trunk/Source/WTF/ChangeLog
r203670 r203834 1 2016-07-28 Mark Lam <mark.lam@apple.com> 2 3 StringView should have an explicit m_is8Bit field. 4 https://bugs.webkit.org/show_bug.cgi?id=160282 5 <rdar://problem/27327943> 6 7 Reviewed by Benjamin Poulain. 8 9 The current implementation reserves 1 bit in the 32-bit m_length field as an 10 is16Bit flag. As a result, a StringView is incapable of handling strings that 11 have a length of 32-bit in size. This results in a mismatch with the 12 expectations of String, StringImpl, and JavaScriptCore's JSString which all 13 support a 32-bit unsigned length. 14 15 This patch fixes this issue by introducing an explicit m_is8Bit field, thereby 16 allowing m_length to be a full 32-bit again. 17 18 We also introduced a clear() convenience method to set the fields of StringView 19 to empty values. Previously, we were duplicating the code for clearing those 20 fields. We now call clear() in all those places instead. 21 22 Note: in clear(), we set m_is8Bit to true because we want an empty StringView 23 to be 8-bit rather than 16-bit. This is consistent with what the empty() method 24 returns. 25 26 * wtf/text/StringView.h: 27 (WTF::StringView::setUnderlyingString): 28 (WTF::StringView::StringView): 29 (WTF::StringView::operator=): 30 (WTF::StringView::initialize): 31 (WTF::StringView::clear): 32 (WTF::StringView::empty): 33 (WTF::StringView::length): 34 (WTF::StringView::operator bool): 35 (WTF::StringView::is8Bit): 36 (WTF::StringView::substring): 37 (WTF::StringView::getCharactersWithUpconvert): 38 (WTF::StringView::toString): 39 (WTF::StringView::toAtomicString): 40 (WTF::StringView::toFloat): 41 (WTF::StringView::toInt): 42 (WTF::StringView::toIntStrict): 43 (WTF::StringView::toStringWithoutCopying): 44 (WTF::StringView::find): 45 1 46 2016-07-24 Filip Pizlo <fpizlo@apple.com> 2 47 -
trunk/Source/WTF/wtf/text/StringView.h
r203208 r203834 1 1 /* 2 * Copyright (C) 2014-201 5Apple Inc. All rights reserved.2 * Copyright (C) 2014-2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 157 157 void setUnderlyingString(const StringView&) { } 158 158 #endif 159 160 static const unsigned is16BitStringFlag = 1u << 31; 159 void clear(); 161 160 162 161 const void* m_characters { nullptr }; 163 162 unsigned m_length { 0 }; 163 bool m_is8Bit { true }; 164 164 165 165 #if CHECK_STRINGVIEW_LIFETIME … … 211 211 : m_characters(other.m_characters) 212 212 , m_length(other.m_length) 213 , m_is8Bit(other.m_is8Bit) 213 214 { 214 215 ASSERT(other.underlyingStringIsValid()); 215 216 216 other.m_characters = nullptr; 217 other.m_length = 0; 217 other.clear(); 218 218 219 219 setUnderlyingString(other); … … 224 224 : m_characters(other.m_characters) 225 225 , m_length(other.m_length) 226 , m_is8Bit(other.m_is8Bit) 226 227 { 227 228 ASSERT(other.underlyingStringIsValid()); … … 236 237 m_characters = other.m_characters; 237 238 m_length = other.m_length; 238 239 other.m_characters = nullptr; 240 other. m_length = 0;239 m_is8Bit = other.m_is8Bit; 240 241 other.clear(); 241 242 242 243 setUnderlyingString(other); … … 252 253 m_characters = other.m_characters; 253 254 m_length = other.m_length; 255 m_is8Bit = other.m_is8Bit; 254 256 255 257 setUnderlyingString(other); … … 260 262 inline void StringView::initialize(const LChar* characters, unsigned length) 261 263 { 262 // FIXME: We need a better solution here, because there is no guarantee that263 // the length here won't be too long. Maybe at least a RELEASE_ASSERT?264 ASSERT(!(length & is16BitStringFlag));265 264 m_characters = characters; 266 265 m_length = length; 266 m_is8Bit = true; 267 267 } 268 268 269 269 inline void StringView::initialize(const UChar* characters, unsigned length) 270 270 { 271 // FIXME: We need a better solution here, because there is no guarantee that272 // the length here won't be too long. Maybe at least a RELEASE_ASSERT?273 ASSERT(!(length & is16BitStringFlag));274 271 m_characters = characters; 275 m_length = is16BitStringFlag | length; 272 m_length = length; 273 m_is8Bit = false; 276 274 } 277 275 … … 311 309 setUnderlyingString(string.impl()); 312 310 if (!string.impl()) { 313 m_characters = nullptr; 314 m_length = 0; 311 clear(); 315 312 return; 316 313 } … … 320 317 } 321 318 initialize(string.characters16(), string.length()); 319 } 320 321 inline void StringView::clear() 322 { 323 m_characters = nullptr; 324 m_length = 0; 325 m_is8Bit = true; 322 326 } 323 327 … … 368 372 inline unsigned StringView::length() const 369 373 { 370 return m_length & ~is16BitStringFlag;374 return m_length; 371 375 } 372 376 … … 378 382 inline bool StringView::is8Bit() const 379 383 { 380 return !(m_length & is16BitStringFlag);384 return m_is8Bit; 381 385 } 382 386 … … 433 437 } 434 438 auto characters16 = this->characters16(); 435 unsigned length = this->length(); 436 for (unsigned i = 0; i < length; ++i) 439 for (unsigned i = 0; i < m_length; ++i) 437 440 destination[i] = characters16[i]; 438 441 } … … 456 459 if (is8Bit()) 457 460 return String(characters8(), m_length); 458 return String(characters16(), length());461 return String(characters16(), m_length); 459 462 } 460 463 … … 463 466 if (is8Bit()) 464 467 return AtomicString(characters8(), m_length); 465 return AtomicString(characters16(), length());468 return AtomicString(characters16(), m_length); 466 469 } 467 470 … … 470 473 if (is8Bit()) 471 474 return charactersToFloat(characters8(), m_length, &isValid); 472 return charactersToFloat(characters16(), length(), &isValid);475 return charactersToFloat(characters16(), m_length, &isValid); 473 476 } 474 477 … … 483 486 if (is8Bit()) 484 487 return charactersToInt(characters8(), m_length, &isValid); 485 return charactersToInt(characters16(), length(), &isValid);488 return charactersToInt(characters16(), m_length, &isValid); 486 489 } 487 490 … … 490 493 if (is8Bit()) 491 494 return charactersToIntStrict(characters8(), m_length, &isValid); 492 return charactersToIntStrict(characters16(), length(), &isValid);495 return charactersToIntStrict(characters16(), m_length, &isValid); 493 496 } 494 497 … … 497 500 if (is8Bit()) 498 501 return StringImpl::createWithoutCopying(characters8(), m_length); 499 return StringImpl::createWithoutCopying(characters16(), length());502 return StringImpl::createWithoutCopying(characters16(), m_length); 500 503 } 501 504 … … 504 507 if (is8Bit()) 505 508 return WTF::find(characters8(), m_length, character, start); 506 return WTF::find(characters16(), length(), character, start);509 return WTF::find(characters16(), m_length, character, start); 507 510 } 508 511 … … 511 514 if (is8Bit()) 512 515 return WTF::find(characters8(), m_length, matchFunction, start); 513 return WTF::find(characters16(), length(), matchFunction, start);516 return WTF::find(characters16(), m_length, matchFunction, start); 514 517 } 515 518
Note: See TracChangeset
for help on using the changeset viewer.