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

Side by Side Diff: src/factory.cc

Issue 210143002: Revert "No longer OOM on invalid string length." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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);
415 if (is_one_byte) { 414 if (is_one_byte) {
416 Handle<SeqOneByteString> result = NewRawOneByteString(length); 415 Handle<SeqOneByteString> result = NewRawOneByteString(length);
417 DisallowHeapAllocation no_gc; 416 DisallowHeapAllocation no_gc;
418 uint8_t* dest = result->GetChars(); 417 uint8_t* dest = result->GetChars();
419 // Copy left part. 418 // Copy left part.
420 const uint8_t* src = left->IsExternalString() 419 const uint8_t* src = left->IsExternalString()
421 ? Handle<ExternalAsciiString>::cast(left)->GetChars() 420 ? Handle<ExternalAsciiString>::cast(left)->GetChars()
422 : Handle<SeqOneByteString>::cast(left)->GetChars(); 421 : Handle<SeqOneByteString>::cast(left)->GetChars();
423 for (int i = 0; i < left_length; i++) *dest++ = src[i]; 422 for (int i = 0; i < left_length; i++) *dest++ = src[i];
424 // Copy right part. 423 // Copy right part.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 // dictionary. Check whether we already have the string in the string 489 // dictionary. Check whether we already have the string in the string
491 // table to prevent creation of many unnecessary strings. 490 // table to prevent creation of many unnecessary strings.
492 uint16_t c1 = str->Get(begin); 491 uint16_t c1 = str->Get(begin);
493 uint16_t c2 = str->Get(begin + 1); 492 uint16_t c2 = str->Get(begin + 1);
494 return MakeOrFindTwoCharacterString(isolate(), c1, c2); 493 return MakeOrFindTwoCharacterString(isolate(), c1, c2);
495 } 494 }
496 495
497 if (!FLAG_string_slices || length < SlicedString::kMinLength) { 496 if (!FLAG_string_slices || length < SlicedString::kMinLength) {
498 if (str->IsOneByteRepresentation()) { 497 if (str->IsOneByteRepresentation()) {
499 Handle<SeqOneByteString> result = NewRawOneByteString(length); 498 Handle<SeqOneByteString> result = NewRawOneByteString(length);
500 ASSERT(!result.is_null());
501 uint8_t* dest = result->GetChars(); 499 uint8_t* dest = result->GetChars();
502 DisallowHeapAllocation no_gc; 500 DisallowHeapAllocation no_gc;
503 String::WriteToFlat(*str, dest, begin, end); 501 String::WriteToFlat(*str, dest, begin, end);
504 return result; 502 return result;
505 } else { 503 } else {
506 Handle<SeqTwoByteString> result = NewRawTwoByteString(length); 504 Handle<SeqTwoByteString> result = NewRawTwoByteString(length);
507 ASSERT(!result.is_null());
508 uc16* dest = result->GetChars(); 505 uc16* dest = result->GetChars();
509 DisallowHeapAllocation no_gc; 506 DisallowHeapAllocation no_gc;
510 String::WriteToFlat(*str, dest, begin, end); 507 String::WriteToFlat(*str, dest, begin, end);
511 return result; 508 return result;
512 } 509 }
513 } 510 }
514 511
515 int offset = begin; 512 int offset = begin;
516 513
517 while (str->IsConsString()) { 514 while (str->IsConsString()) {
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 return Handle<Object>::null(); 2034 return Handle<Object>::null();
2038 } 2035 }
2039 2036
2040 2037
2041 Handle<Object> Factory::ToBoolean(bool value) { 2038 Handle<Object> Factory::ToBoolean(bool value) {
2042 return value ? true_value() : false_value(); 2039 return value ? true_value() : false_value();
2043 } 2040 }
2044 2041
2045 2042
2046 } } // namespace v8::internal 2043 } } // 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