| OLD | NEW |
| 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 6533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6544 if (static_cast<uint32_t>(indices.length()) < limit) { | 6544 if (static_cast<uint32_t>(indices.length()) < limit) { |
| 6545 indices.Add(subject_length, zone_scope.zone()); | 6545 indices.Add(subject_length, zone_scope.zone()); |
| 6546 } | 6546 } |
| 6547 | 6547 |
| 6548 // The list indices now contains the end of each part to create. | 6548 // The list indices now contains the end of each part to create. |
| 6549 | 6549 |
| 6550 // Create JSArray of substrings separated by separator. | 6550 // Create JSArray of substrings separated by separator. |
| 6551 int part_count = indices.length(); | 6551 int part_count = indices.length(); |
| 6552 | 6552 |
| 6553 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); | 6553 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); |
| 6554 MaybeObject* maybe_result = result->EnsureCanContainHeapObjectElements(); | 6554 JSObject::EnsureCanContainHeapObjectElements(result); |
| 6555 if (maybe_result->IsFailure()) return maybe_result; | |
| 6556 result->set_length(Smi::FromInt(part_count)); | 6555 result->set_length(Smi::FromInt(part_count)); |
| 6557 | 6556 |
| 6558 ASSERT(result->HasFastObjectElements()); | 6557 ASSERT(result->HasFastObjectElements()); |
| 6559 | 6558 |
| 6560 if (part_count == 1 && indices.at(0) == subject_length) { | 6559 if (part_count == 1 && indices.at(0) == subject_length) { |
| 6561 FixedArray::cast(result->elements())->set(0, *subject); | 6560 FixedArray::cast(result->elements())->set(0, *subject); |
| 6562 return *result; | 6561 return *result; |
| 6563 } | 6562 } |
| 6564 | 6563 |
| 6565 Handle<FixedArray> elements(FixedArray::cast(result->elements())); | 6564 Handle<FixedArray> elements(FixedArray::cast(result->elements())); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6938 String* string = String::cast(element); | 6937 String* string = String::cast(element); |
| 6939 int element_length = string->length(); | 6938 int element_length = string->length(); |
| 6940 String::WriteToFlat(string, sink + position, 0, element_length); | 6939 String::WriteToFlat(string, sink + position, 0, element_length); |
| 6941 position += element_length; | 6940 position += element_length; |
| 6942 } | 6941 } |
| 6943 } | 6942 } |
| 6944 } | 6943 } |
| 6945 | 6944 |
| 6946 | 6945 |
| 6947 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) { | 6946 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat) { |
| 6948 SealHandleScope shs(isolate); | 6947 HandleScope scope(isolate); |
| 6949 ASSERT(args.length() == 3); | 6948 ASSERT(args.length() == 3); |
| 6950 CONVERT_ARG_CHECKED(JSArray, array, 0); | 6949 CONVERT_ARG_HANDLE_CHECKED(JSArray, array, 0); |
| 6951 if (!args[1]->IsSmi()) { | 6950 if (!args[1]->IsSmi()) { |
| 6952 isolate->context()->mark_out_of_memory(); | 6951 isolate->context()->mark_out_of_memory(); |
| 6953 return Failure::OutOfMemoryException(0x14); | 6952 return Failure::OutOfMemoryException(0x14); |
| 6954 } | 6953 } |
| 6955 int array_length = args.smi_at(1); | 6954 int array_length = args.smi_at(1); |
| 6956 CONVERT_ARG_CHECKED(String, special, 2); | 6955 CONVERT_ARG_HANDLE_CHECKED(String, special, 2); |
| 6957 | 6956 |
| 6958 // This assumption is used by the slice encoding in one or two smis. | 6957 // This assumption is used by the slice encoding in one or two smis. |
| 6959 ASSERT(Smi::kMaxValue >= String::kMaxLength); | 6958 ASSERT(Smi::kMaxValue >= String::kMaxLength); |
| 6960 | 6959 |
| 6961 MaybeObject* maybe_result = array->EnsureCanContainHeapObjectElements(); | 6960 JSObject::EnsureCanContainHeapObjectElements(array); |
| 6962 if (maybe_result->IsFailure()) return maybe_result; | |
| 6963 | 6961 |
| 6964 int special_length = special->length(); | 6962 int special_length = special->length(); |
| 6965 if (!array->HasFastObjectElements()) { | 6963 if (!array->HasFastObjectElements()) { |
| 6966 return isolate->Throw(isolate->heap()->illegal_argument_string()); | 6964 return isolate->Throw(isolate->heap()->illegal_argument_string()); |
| 6967 } | 6965 } |
| 6968 FixedArray* fixed_array = FixedArray::cast(array->elements()); | 6966 FixedArray* fixed_array = FixedArray::cast(array->elements()); |
| 6969 if (fixed_array->length() < array_length) { | 6967 if (fixed_array->length() < array_length) { |
| 6970 array_length = fixed_array->length(); | 6968 array_length = fixed_array->length(); |
| 6971 } | 6969 } |
| 6972 | 6970 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7034 | 7032 |
| 7035 int length = position; | 7033 int length = position; |
| 7036 Object* object; | 7034 Object* object; |
| 7037 | 7035 |
| 7038 if (one_byte) { | 7036 if (one_byte) { |
| 7039 { MaybeObject* maybe_object = | 7037 { MaybeObject* maybe_object = |
| 7040 isolate->heap()->AllocateRawOneByteString(length); | 7038 isolate->heap()->AllocateRawOneByteString(length); |
| 7041 if (!maybe_object->ToObject(&object)) return maybe_object; | 7039 if (!maybe_object->ToObject(&object)) return maybe_object; |
| 7042 } | 7040 } |
| 7043 SeqOneByteString* answer = SeqOneByteString::cast(object); | 7041 SeqOneByteString* answer = SeqOneByteString::cast(object); |
| 7044 StringBuilderConcatHelper(special, | 7042 StringBuilderConcatHelper(*special, |
| 7045 answer->GetChars(), | 7043 answer->GetChars(), |
| 7046 fixed_array, | 7044 fixed_array, |
| 7047 array_length); | 7045 array_length); |
| 7048 return answer; | 7046 return answer; |
| 7049 } else { | 7047 } else { |
| 7050 { MaybeObject* maybe_object = | 7048 { MaybeObject* maybe_object = |
| 7051 isolate->heap()->AllocateRawTwoByteString(length); | 7049 isolate->heap()->AllocateRawTwoByteString(length); |
| 7052 if (!maybe_object->ToObject(&object)) return maybe_object; | 7050 if (!maybe_object->ToObject(&object)) return maybe_object; |
| 7053 } | 7051 } |
| 7054 SeqTwoByteString* answer = SeqTwoByteString::cast(object); | 7052 SeqTwoByteString* answer = SeqTwoByteString::cast(object); |
| 7055 StringBuilderConcatHelper(special, | 7053 StringBuilderConcatHelper(*special, |
| 7056 answer->GetChars(), | 7054 answer->GetChars(), |
| 7057 fixed_array, | 7055 fixed_array, |
| 7058 array_length); | 7056 array_length); |
| 7059 return answer; | 7057 return answer; |
| 7060 } | 7058 } |
| 7061 } | 7059 } |
| 7062 | 7060 |
| 7063 | 7061 |
| 7064 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderJoin) { | 7062 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderJoin) { |
| 7065 SealHandleScope shs(isolate); | 7063 SealHandleScope shs(isolate); |
| (...skipping 2338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9404 | 9402 |
| 9405 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateParseString) { | 9403 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateParseString) { |
| 9406 HandleScope scope(isolate); | 9404 HandleScope scope(isolate); |
| 9407 ASSERT(args.length() == 2); | 9405 ASSERT(args.length() == 2); |
| 9408 | 9406 |
| 9409 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); | 9407 CONVERT_ARG_HANDLE_CHECKED(String, str, 0); |
| 9410 FlattenString(str); | 9408 FlattenString(str); |
| 9411 | 9409 |
| 9412 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); | 9410 CONVERT_ARG_HANDLE_CHECKED(JSArray, output, 1); |
| 9413 | 9411 |
| 9414 MaybeObject* maybe_result_array = | 9412 JSObject::EnsureCanContainHeapObjectElements(output); |
| 9415 output->EnsureCanContainHeapObjectElements(); | |
| 9416 if (maybe_result_array->IsFailure()) return maybe_result_array; | |
| 9417 RUNTIME_ASSERT(output->HasFastObjectElements()); | 9413 RUNTIME_ASSERT(output->HasFastObjectElements()); |
| 9418 | 9414 |
| 9419 DisallowHeapAllocation no_gc; | 9415 DisallowHeapAllocation no_gc; |
| 9420 | 9416 |
| 9421 FixedArray* output_array = FixedArray::cast(output->elements()); | 9417 FixedArray* output_array = FixedArray::cast(output->elements()); |
| 9422 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); | 9418 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); |
| 9423 bool result; | 9419 bool result; |
| 9424 String::FlatContent str_content = str->GetFlatContent(); | 9420 String::FlatContent str_content = str->GetFlatContent(); |
| 9425 if (str_content.IsAscii()) { | 9421 if (str_content.IsAscii()) { |
| 9426 result = DateParser::Parse(str_content.ToOneByteVector(), | 9422 result = DateParser::Parse(str_content.ToOneByteVector(), |
| (...skipping 5232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14659 // Handle last resort GC and make sure to allow future allocations | 14655 // Handle last resort GC and make sure to allow future allocations |
| 14660 // to grow the heap without causing GCs (if possible). | 14656 // to grow the heap without causing GCs (if possible). |
| 14661 isolate->counters()->gc_last_resort_from_js()->Increment(); | 14657 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 14662 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 14658 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 14663 "Runtime::PerformGC"); | 14659 "Runtime::PerformGC"); |
| 14664 } | 14660 } |
| 14665 } | 14661 } |
| 14666 | 14662 |
| 14667 | 14663 |
| 14668 } } // namespace v8::internal | 14664 } } // namespace v8::internal |
| OLD | NEW |