Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Side by Side Diff: src/runtime.cc

Issue 196133030: Make max size and max length of strings consistent. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/hydrogen.cc ('K') | « src/objects.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 7297 matching lines...) Expand 10 before | Expand all | Expand 10 after
7308 CONVERT_NUMBER_CHECKED(uint32_t, array_length, Uint32, args[1]); 7308 CONVERT_NUMBER_CHECKED(uint32_t, array_length, Uint32, args[1]);
7309 CONVERT_ARG_CHECKED(String, separator, 2); 7309 CONVERT_ARG_CHECKED(String, separator, 2);
7310 // elements_array is fast-mode JSarray of alternating positions 7310 // elements_array is fast-mode JSarray of alternating positions
7311 // (increasing order) and strings. 7311 // (increasing order) and strings.
7312 // array_length is length of original array (used to add separators); 7312 // array_length is length of original array (used to add separators);
7313 // separator is string to put between elements. Assumed to be non-empty. 7313 // separator is string to put between elements. Assumed to be non-empty.
7314 7314
7315 // Find total length of join result. 7315 // Find total length of join result.
7316 int string_length = 0; 7316 int string_length = 0;
7317 bool is_ascii = separator->IsOneByteRepresentation(); 7317 bool is_ascii = separator->IsOneByteRepresentation();
7318 int max_string_length;
7319 if (is_ascii) {
7320 max_string_length = SeqOneByteString::kMaxLength;
7321 } else {
7322 max_string_length = SeqTwoByteString::kMaxLength;
7323 }
7324 bool overflow = false; 7318 bool overflow = false;
7325 CONVERT_NUMBER_CHECKED(int, elements_length, 7319 CONVERT_NUMBER_CHECKED(int, elements_length,
7326 Int32, elements_array->length()); 7320 Int32, elements_array->length());
7327 RUNTIME_ASSERT((elements_length & 1) == 0); // Even length. 7321 RUNTIME_ASSERT((elements_length & 1) == 0); // Even length.
7328 FixedArray* elements = FixedArray::cast(elements_array->elements()); 7322 FixedArray* elements = FixedArray::cast(elements_array->elements());
7329 for (int i = 0; i < elements_length; i += 2) { 7323 for (int i = 0; i < elements_length; i += 2) {
7330 RUNTIME_ASSERT(elements->get(i)->IsNumber()); 7324 RUNTIME_ASSERT(elements->get(i)->IsNumber());
7331 RUNTIME_ASSERT(elements->get(i + 1)->IsString()); 7325 RUNTIME_ASSERT(elements->get(i + 1)->IsString());
7332 String* string = String::cast(elements->get(i + 1)); 7326 String* string = String::cast(elements->get(i + 1));
7333 int length = string->length(); 7327 int length = string->length();
7334 if (is_ascii && !string->IsOneByteRepresentation()) { 7328 if (is_ascii && !string->IsOneByteRepresentation()) {
7335 is_ascii = false; 7329 is_ascii = false;
7336 max_string_length = SeqTwoByteString::kMaxLength;
7337 } 7330 }
7338 if (length > max_string_length || 7331 if (length > String::kMaxLength ||
7339 max_string_length - length < string_length) { 7332 String::kMaxLength - length < string_length) {
7340 overflow = true; 7333 overflow = true;
7341 break; 7334 break;
7342 } 7335 }
7343 string_length += length; 7336 string_length += length;
7344 } 7337 }
7345 int separator_length = separator->length(); 7338 int separator_length = separator->length();
7346 if (!overflow && separator_length > 0) { 7339 if (!overflow && separator_length > 0) {
7347 if (array_length <= 0x7fffffffu) { 7340 if (array_length <= 0x7fffffffu) {
7348 int separator_count = static_cast<int>(array_length) - 1; 7341 int separator_count = static_cast<int>(array_length) - 1;
7349 int remaining_length = max_string_length - string_length; 7342 int remaining_length = String::kMaxLength - string_length;
7350 if ((remaining_length / separator_length) >= separator_count) { 7343 if ((remaining_length / separator_length) >= separator_count) {
7351 string_length += separator_length * (array_length - 1); 7344 string_length += separator_length * (array_length - 1);
7352 } else { 7345 } else {
7353 // Not room for the separators within the maximal string length. 7346 // Not room for the separators within the maximal string length.
7354 overflow = true; 7347 overflow = true;
7355 } 7348 }
7356 } else { 7349 } else {
7357 // Nonempty separator and at least 2^31-1 separators necessary 7350 // Nonempty separator and at least 2^31-1 separators necessary
7358 // means that the string is too large to create. 7351 // means that the string is too large to create.
7359 STATIC_ASSERT(String::kMaxLength < 0x7fffffff); 7352 STATIC_ASSERT(String::kMaxLength < 0x7fffffff);
(...skipping 7686 matching lines...) Expand 10 before | Expand all | Expand 10 after
15046 // Handle last resort GC and make sure to allow future allocations 15039 // Handle last resort GC and make sure to allow future allocations
15047 // to grow the heap without causing GCs (if possible). 15040 // to grow the heap without causing GCs (if possible).
15048 isolate->counters()->gc_last_resort_from_js()->Increment(); 15041 isolate->counters()->gc_last_resort_from_js()->Increment();
15049 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 15042 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
15050 "Runtime::PerformGC"); 15043 "Runtime::PerformGC");
15051 } 15044 }
15052 } 15045 }
15053 15046
15054 15047
15055 } } // namespace v8::internal 15048 } } // namespace v8::internal
OLDNEW
« src/hydrogen.cc ('K') | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698