| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/conversions-inl.h" | 8 #include "src/conversions-inl.h" |
| 9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 727 |
| 728 if (static_cast<uint32_t>(indices.length()) < limit) { | 728 if (static_cast<uint32_t>(indices.length()) < limit) { |
| 729 indices.Add(subject_length, zone_scope.zone()); | 729 indices.Add(subject_length, zone_scope.zone()); |
| 730 } | 730 } |
| 731 | 731 |
| 732 // The list indices now contains the end of each part to create. | 732 // The list indices now contains the end of each part to create. |
| 733 | 733 |
| 734 // Create JSArray of substrings separated by separator. | 734 // Create JSArray of substrings separated by separator. |
| 735 int part_count = indices.length(); | 735 int part_count = indices.length(); |
| 736 | 736 |
| 737 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); | 737 Handle<JSArray> result = |
| 738 JSObject::EnsureCanContainHeapObjectElements(result); | 738 isolate->factory()->NewJSArray(FAST_ELEMENTS, part_count, part_count, |
| 739 result->set_length(Smi::FromInt(part_count)); | 739 INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
| 740 | 740 |
| 741 DCHECK(result->HasFastObjectElements()); | 741 DCHECK(result->HasFastObjectElements()); |
| 742 | 742 |
| 743 Handle<FixedArray> elements(FixedArray::cast(result->elements())); | 743 Handle<FixedArray> elements(FixedArray::cast(result->elements())); |
| 744 | 744 |
| 745 if (part_count == 1 && indices.at(0) == subject_length) { | 745 if (part_count == 1 && indices.at(0) == subject_length) { |
| 746 elements->set(0, *subject); | 746 elements->set(0, *subject); |
| 747 } else { | 747 } else { |
| 748 int part_start = 0; | 748 int part_start = 0; |
| 749 for (int i = 0; i < part_count; i++) { | 749 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < part_count, i++, { |
| 750 HandleScope local_loop_handle(isolate); | |
| 751 int part_end = indices.at(i); | 750 int part_end = indices.at(i); |
| 752 Handle<String> substring = | 751 Handle<String> substring = |
| 753 isolate->factory()->NewProperSubString(subject, part_start, part_end); | 752 isolate->factory()->NewProperSubString(subject, part_start, part_end); |
| 754 elements->set(i, *substring); | 753 elements->set(i, *substring); |
| 755 part_start = part_end + pattern_length; | 754 part_start = part_end + pattern_length; |
| 756 } | 755 }); |
| 757 } | 756 } |
| 758 | 757 |
| 759 if (limit == 0xffffffffu) { | 758 if (limit == 0xffffffffu) { |
| 760 if (result->HasFastObjectElements()) { | 759 if (result->HasFastObjectElements()) { |
| 761 RegExpResultsCache::Enter(isolate, subject, pattern, elements, | 760 RegExpResultsCache::Enter(isolate, subject, pattern, elements, |
| 762 isolate->factory()->empty_fixed_array(), | 761 isolate->factory()->empty_fixed_array(), |
| 763 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS); | 762 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS); |
| 764 } | 763 } |
| 765 } | 764 } |
| 766 | 765 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 | 1021 |
| 1023 | 1022 |
| 1024 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1023 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
| 1025 SealHandleScope shs(isolate); | 1024 SealHandleScope shs(isolate); |
| 1026 DCHECK(args.length() == 1); | 1025 DCHECK(args.length() == 1); |
| 1027 CONVERT_ARG_CHECKED(Object, obj, 0); | 1026 CONVERT_ARG_CHECKED(Object, obj, 0); |
| 1028 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1027 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
| 1029 } | 1028 } |
| 1030 } // namespace internal | 1029 } // namespace internal |
| 1031 } // namespace v8 | 1030 } // namespace v8 |
| OLD | NEW |