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 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 | 731 |
732 // Create JSArray of substrings separated by separator. | 732 // Create JSArray of substrings separated by separator. |
733 int part_count = indices.length(); | 733 int part_count = indices.length(); |
734 | 734 |
735 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); | 735 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); |
736 JSObject::EnsureCanContainHeapObjectElements(result); | 736 JSObject::EnsureCanContainHeapObjectElements(result); |
737 result->set_length(Smi::FromInt(part_count)); | 737 result->set_length(Smi::FromInt(part_count)); |
738 | 738 |
739 DCHECK(result->HasFastObjectElements()); | 739 DCHECK(result->HasFastObjectElements()); |
740 | 740 |
| 741 Handle<FixedArray> elements(FixedArray::cast(result->elements())); |
| 742 |
741 if (part_count == 1 && indices.at(0) == subject_length) { | 743 if (part_count == 1 && indices.at(0) == subject_length) { |
742 FixedArray::cast(result->elements())->set(0, *subject); | 744 elements->set(0, *subject); |
743 return *result; | 745 } else { |
744 } | 746 int part_start = 0; |
745 | 747 for (int i = 0; i < part_count; i++) { |
746 Handle<FixedArray> elements(FixedArray::cast(result->elements())); | 748 HandleScope local_loop_handle(isolate); |
747 int part_start = 0; | 749 int part_end = indices.at(i); |
748 for (int i = 0; i < part_count; i++) { | 750 Handle<String> substring = |
749 HandleScope local_loop_handle(isolate); | 751 isolate->factory()->NewProperSubString(subject, part_start, part_end); |
750 int part_end = indices.at(i); | 752 elements->set(i, *substring); |
751 Handle<String> substring = | 753 part_start = part_end + pattern_length; |
752 isolate->factory()->NewProperSubString(subject, part_start, part_end); | 754 } |
753 elements->set(i, *substring); | |
754 part_start = part_end + pattern_length; | |
755 } | 755 } |
756 | 756 |
757 if (limit == 0xffffffffu) { | 757 if (limit == 0xffffffffu) { |
758 if (result->HasFastObjectElements()) { | 758 if (result->HasFastObjectElements()) { |
759 RegExpResultsCache::Enter(isolate, subject, pattern, elements, | 759 RegExpResultsCache::Enter(isolate, subject, pattern, elements, |
760 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS); | 760 RegExpResultsCache::STRING_SPLIT_SUBSTRINGS); |
761 } | 761 } |
762 } | 762 } |
763 | 763 |
764 return *result; | 764 return *result; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 | 1179 |
1180 | 1180 |
1181 RUNTIME_FUNCTION(Runtime_IsRegExp) { | 1181 RUNTIME_FUNCTION(Runtime_IsRegExp) { |
1182 SealHandleScope shs(isolate); | 1182 SealHandleScope shs(isolate); |
1183 DCHECK(args.length() == 1); | 1183 DCHECK(args.length() == 1); |
1184 CONVERT_ARG_CHECKED(Object, obj, 0); | 1184 CONVERT_ARG_CHECKED(Object, obj, 0); |
1185 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); | 1185 return isolate->heap()->ToBoolean(obj->IsJSRegExp()); |
1186 } | 1186 } |
1187 } // namespace internal | 1187 } // namespace internal |
1188 } // namespace v8 | 1188 } // namespace v8 |
OLD | NEW |