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

Side by Side Diff: src/factory.cc

Issue 207613005: No longer OOM on invalid string length. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + addressed nits 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
« no previous file with comments | « src/debug.cc ('k') | src/heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string, 282 Handle<String> Factory::NewStringFromTwoByte(Vector<const uc16> string,
283 PretenureFlag pretenure) { 283 PretenureFlag pretenure) {
284 CALL_HEAP_FUNCTION( 284 CALL_HEAP_FUNCTION(
285 isolate(), 285 isolate(),
286 isolate()->heap()->AllocateStringFromTwoByte(string, pretenure), 286 isolate()->heap()->AllocateStringFromTwoByte(string, pretenure),
287 String); 287 String);
288 } 288 }
289 289
290 290
291 Handle<SeqOneByteString> Factory::NewRawOneByteString(int length, 291 Handle<SeqOneByteString> Factory::NewRawOneByteString(int length,
292 PretenureFlag pretenure) { 292 PretenureFlag pretenure) {
293 CALL_HEAP_FUNCTION( 293 CALL_HEAP_FUNCTION(
294 isolate(), 294 isolate(),
295 isolate()->heap()->AllocateRawOneByteString(length, pretenure), 295 isolate()->heap()->AllocateRawOneByteString(length, pretenure),
296 SeqOneByteString); 296 SeqOneByteString);
297 } 297 }
298 298
299 299
300 Handle<SeqTwoByteString> Factory::NewRawTwoByteString(int length, 300 Handle<SeqTwoByteString> Factory::NewRawTwoByteString(int length,
301 PretenureFlag pretenure) { 301 PretenureFlag pretenure) {
302 CALL_HEAP_FUNCTION( 302 CALL_HEAP_FUNCTION(
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 404 }
405 } 405 }
406 406
407 // If the resulting string is small make a flat string. 407 // If the resulting string is small make a flat string.
408 if (length < ConsString::kMinLength) { 408 if (length < ConsString::kMinLength) {
409 // Note that neither of the two inputs can be a slice because: 409 // Note that neither of the two inputs can be a slice because:
410 STATIC_ASSERT(ConsString::kMinLength <= SlicedString::kMinLength); 410 STATIC_ASSERT(ConsString::kMinLength <= SlicedString::kMinLength);
411 ASSERT(left->IsFlat()); 411 ASSERT(left->IsFlat());
412 ASSERT(right->IsFlat()); 412 ASSERT(right->IsFlat());
413 413
414 STATIC_ASSERT(ConsString::kMinLength <= String::kMaxLength);
414 if (is_one_byte) { 415 if (is_one_byte) {
415 Handle<SeqOneByteString> result = NewRawOneByteString(length); 416 Handle<SeqOneByteString> result = NewRawOneByteString(length);
416 DisallowHeapAllocation no_gc; 417 DisallowHeapAllocation no_gc;
417 uint8_t* dest = result->GetChars(); 418 uint8_t* dest = result->GetChars();
418 // Copy left part. 419 // Copy left part.
419 const uint8_t* src = left->IsExternalString() 420 const uint8_t* src = left->IsExternalString()
420 ? Handle<ExternalAsciiString>::cast(left)->GetChars() 421 ? Handle<ExternalAsciiString>::cast(left)->GetChars()
421 : Handle<SeqOneByteString>::cast(left)->GetChars(); 422 : Handle<SeqOneByteString>::cast(left)->GetChars();
422 for (int i = 0; i < left_length; i++) *dest++ = src[i]; 423 for (int i = 0; i < left_length; i++) *dest++ = src[i];
423 // Copy right part. 424 // Copy right part.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 // dictionary. Check whether we already have the string in the string 490 // dictionary. Check whether we already have the string in the string
490 // table to prevent creation of many unnecessary strings. 491 // table to prevent creation of many unnecessary strings.
491 uint16_t c1 = str->Get(begin); 492 uint16_t c1 = str->Get(begin);
492 uint16_t c2 = str->Get(begin + 1); 493 uint16_t c2 = str->Get(begin + 1);
493 return MakeOrFindTwoCharacterString(isolate(), c1, c2); 494 return MakeOrFindTwoCharacterString(isolate(), c1, c2);
494 } 495 }
495 496
496 if (!FLAG_string_slices || length < SlicedString::kMinLength) { 497 if (!FLAG_string_slices || length < SlicedString::kMinLength) {
497 if (str->IsOneByteRepresentation()) { 498 if (str->IsOneByteRepresentation()) {
498 Handle<SeqOneByteString> result = NewRawOneByteString(length); 499 Handle<SeqOneByteString> result = NewRawOneByteString(length);
500 ASSERT(!result.is_null());
499 uint8_t* dest = result->GetChars(); 501 uint8_t* dest = result->GetChars();
500 DisallowHeapAllocation no_gc; 502 DisallowHeapAllocation no_gc;
501 String::WriteToFlat(*str, dest, begin, end); 503 String::WriteToFlat(*str, dest, begin, end);
502 return result; 504 return result;
503 } else { 505 } else {
504 Handle<SeqTwoByteString> result = NewRawTwoByteString(length); 506 Handle<SeqTwoByteString> result = NewRawTwoByteString(length);
507 ASSERT(!result.is_null());
505 uc16* dest = result->GetChars(); 508 uc16* dest = result->GetChars();
506 DisallowHeapAllocation no_gc; 509 DisallowHeapAllocation no_gc;
507 String::WriteToFlat(*str, dest, begin, end); 510 String::WriteToFlat(*str, dest, begin, end);
508 return result; 511 return result;
509 } 512 }
510 } 513 }
511 514
512 int offset = begin; 515 int offset = begin;
513 516
514 while (str->IsConsString()) { 517 while (str->IsConsString()) {
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 return Handle<Object>::null(); 2037 return Handle<Object>::null();
2035 } 2038 }
2036 2039
2037 2040
2038 Handle<Object> Factory::ToBoolean(bool value) { 2041 Handle<Object> Factory::ToBoolean(bool value) {
2039 return value ? true_value() : false_value(); 2042 return value ? true_value() : false_value();
2040 } 2043 }
2041 2044
2042 2045
2043 } } // namespace v8::internal 2046 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.cc ('k') | src/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698