MaybeObject* Heap::AllocateOneByteInternalizedString(Vector<const uint8_t> str,
uint32_t hash_field) {
- if (str.length() > SeqOneByteString::kMaxLength) {
+ if (str.length() > String::kMaxLength) {
return Failure::OutOfMemoryException(0x2);
}
// Compute map and object size.
MaybeObject* Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str,
uint32_t hash_field) {
- if (str.length() > SeqTwoByteString::kMaxLength) {
+ if (str.length() > String::kMaxLength) {
return Failure::OutOfMemoryException(0x3);
}
// Compute map and object size.
int size;
Map* map;
+ if (chars > String::kMaxLength) {
+ return Failure::OutOfMemoryException(0x9);
+ }
if (is_one_byte) {
- if (chars > SeqOneByteString::kMaxLength) {
- return Failure::OutOfMemoryException(0x9);
- }
map = ascii_internalized_string_map();
size = SeqOneByteString::SizeFor(chars);
} else {
- if (chars > SeqTwoByteString::kMaxLength) {
- return Failure::OutOfMemoryException(0xa);
- }
map = internalized_string_map();
size = SeqTwoByteString::SizeFor(chars);
}
MaybeObject* Heap::AllocateRawOneByteString(int length,
PretenureFlag pretenure) {
- if (length < 0 || length > SeqOneByteString::kMaxLength) {
+ if (length < 0 || length > String::kMaxLength) {
return Failure::OutOfMemoryException(0xb);
}
int size = SeqOneByteString::SizeFor(length);
MaybeObject* Heap::AllocateRawTwoByteString(int length,
PretenureFlag pretenure) {
- if (length < 0 || length > SeqTwoByteString::kMaxLength) {
+ if (length < 0 || length > String::kMaxLength) {
return Failure::OutOfMemoryException(0xc);
}
int size = SeqTwoByteString::SizeFor(length);
HValue* HGraphBuilder::BuildAddStringLengths(HValue* left_length,
HValue* right_length) {
- // Compute the combined string length. If the result is larger than the max
- // supported string length, we bailout to the runtime. This is done implicitly
- // when converting the result back to a smi in case the max string length
- // equals the max smi value. Otherwise, for platforms with 32-bit smis, we do
+ // Compute the combined string length and check against max string length.
HValue* length = AddUncasted<HAdd>(left_length, right_length);
- STATIC_ASSERT(String::kMaxLength <= Smi::kMaxValue);
- if (String::kMaxLength != Smi::kMaxValue) {
- IfBuilder if_nooverflow(this);
- if_nooverflow.If<HCompareNumericAndBranch>(
- length, Add<HConstant>(String::kMaxLength), Token::LTE);
- if_nooverflow.Then();
- if_nooverflow.ElseDeopt("String length exceeds limit");
- }
+ IfBuilder if_nooverflow(this);
+ if_nooverflow.If<HCompareNumericAndBranch>(
+ length, Add<HConstant>(String::kMaxLength), Token::LTE);
+ if_nooverflow.Then();
+ if_nooverflow.ElseDeopt("String length exceeds limit");
return length;
}
static const int kEmptyStringHash = kIsNotArrayIndexMask;
// Maximal string length.
- static const int kMaxLength = (1 << (32 - 2)) - 1;
+ static const int kMaxLength = (1 << 28) - 16;
// Max length for computing hash. For strings longer than this limit the
// string length is used as the hash value.
// Maximal memory usage for a single sequential ASCII string.
static const int kMaxSize = 512 * MB - 1;
- // Maximal length of a single sequential ASCII string.
- // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
- static const int kMaxLength = (kMaxSize - kHeaderSize);
+ STATIC_CHECK((kMaxSize - kHeaderSize) >= String::kMaxLength);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString);
// Maximal memory usage for a single sequential two-byte string.
static const int kMaxSize = 512 * MB - 1;
- // Maximal length of a single sequential two-byte string.
- // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
- static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t);
+ STATIC_CHECK(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >=
+ String::kMaxLength);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
// Find total length of join result.
int string_length = 0;
bool is_ascii = separator->IsOneByteRepresentation();
- int max_string_length;
- if (is_ascii) {
- max_string_length = SeqOneByteString::kMaxLength;
- } else {
- max_string_length = SeqTwoByteString::kMaxLength;
- }
bool overflow = false;
CONVERT_NUMBER_CHECKED(int, elements_length,
Int32, elements_array->length());
int length = string->length();
if (is_ascii && !string->IsOneByteRepresentation()) {
is_ascii = false;
- max_string_length = SeqTwoByteString::kMaxLength;
}
- if (length > max_string_length ||
- max_string_length - length < string_length) {
+ if (length > String::kMaxLength ||
+ String::kMaxLength - length < string_length) {
overflow = true;
break;
}
if (!overflow && separator_length > 0) {
if (array_length <= 0x7fffffffu) {
int separator_count = static_cast<int>(array_length) - 1;
- int remaining_length = max_string_length - string_length;
+ int remaining_length = String::kMaxLength - string_length;
if ((remaining_length / separator_length) >= separator_count) {
string_length += separator_length * (array_length - 1);
} else {