| 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 3580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3591 template<typename ResultSeqString> | 3591 template<typename ResultSeqString> |
| 3592 MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString( | 3592 MUST_USE_RESULT static MaybeObject* StringReplaceGlobalAtomRegExpWithString( |
| 3593 Isolate* isolate, | 3593 Isolate* isolate, |
| 3594 Handle<String> subject, | 3594 Handle<String> subject, |
| 3595 Handle<JSRegExp> pattern_regexp, | 3595 Handle<JSRegExp> pattern_regexp, |
| 3596 Handle<String> replacement, | 3596 Handle<String> replacement, |
| 3597 Handle<JSArray> last_match_info) { | 3597 Handle<JSArray> last_match_info) { |
| 3598 ASSERT(subject->IsFlat()); | 3598 ASSERT(subject->IsFlat()); |
| 3599 ASSERT(replacement->IsFlat()); | 3599 ASSERT(replacement->IsFlat()); |
| 3600 | 3600 |
| 3601 Zone zone(isolate); | 3601 ZoneScope zone_scope(isolate->runtime_zone()); |
| 3602 ZoneList<int> indices(8, &zone); | 3602 ZoneList<int> indices(8, zone_scope.zone()); |
| 3603 ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); | 3603 ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag()); |
| 3604 String* pattern = | 3604 String* pattern = |
| 3605 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); | 3605 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); |
| 3606 int subject_len = subject->length(); | 3606 int subject_len = subject->length(); |
| 3607 int pattern_len = pattern->length(); | 3607 int pattern_len = pattern->length(); |
| 3608 int replacement_len = replacement->length(); | 3608 int replacement_len = replacement->length(); |
| 3609 | 3609 |
| 3610 FindStringIndicesDispatch( | 3610 FindStringIndicesDispatch( |
| 3611 isolate, *subject, pattern, &indices, 0xffffffff, &zone); | 3611 isolate, *subject, pattern, &indices, 0xffffffff, zone_scope.zone()); |
| 3612 | 3612 |
| 3613 int matches = indices.length(); | 3613 int matches = indices.length(); |
| 3614 if (matches == 0) return *subject; | 3614 if (matches == 0) return *subject; |
| 3615 | 3615 |
| 3616 // Detect integer overflow. | 3616 // Detect integer overflow. |
| 3617 int64_t result_len_64 = | 3617 int64_t result_len_64 = |
| 3618 (static_cast<int64_t>(replacement_len) - | 3618 (static_cast<int64_t>(replacement_len) - |
| 3619 static_cast<int64_t>(pattern_len)) * | 3619 static_cast<int64_t>(pattern_len)) * |
| 3620 static_cast<int64_t>(matches) + | 3620 static_cast<int64_t>(matches) + |
| 3621 static_cast<int64_t>(subject_len); | 3621 static_cast<int64_t>(subject_len); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3677 Handle<JSRegExp> regexp, | 3677 Handle<JSRegExp> regexp, |
| 3678 Handle<String> replacement, | 3678 Handle<String> replacement, |
| 3679 Handle<JSArray> last_match_info) { | 3679 Handle<JSArray> last_match_info) { |
| 3680 ASSERT(subject->IsFlat()); | 3680 ASSERT(subject->IsFlat()); |
| 3681 ASSERT(replacement->IsFlat()); | 3681 ASSERT(replacement->IsFlat()); |
| 3682 | 3682 |
| 3683 int capture_count = regexp->CaptureCount(); | 3683 int capture_count = regexp->CaptureCount(); |
| 3684 int subject_length = subject->length(); | 3684 int subject_length = subject->length(); |
| 3685 | 3685 |
| 3686 // CompiledReplacement uses zone allocation. | 3686 // CompiledReplacement uses zone allocation. |
| 3687 Zone zone(isolate); | 3687 ZoneScope zone_scope(isolate->runtime_zone()); |
| 3688 CompiledReplacement compiled_replacement(&zone); | 3688 CompiledReplacement compiled_replacement(zone_scope.zone()); |
| 3689 bool simple_replace = compiled_replacement.Compile(replacement, | 3689 bool simple_replace = compiled_replacement.Compile(replacement, |
| 3690 capture_count, | 3690 capture_count, |
| 3691 subject_length); | 3691 subject_length); |
| 3692 | 3692 |
| 3693 // Shortcut for simple non-regexp global replacements | 3693 // Shortcut for simple non-regexp global replacements |
| 3694 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { | 3694 if (regexp->TypeTag() == JSRegExp::ATOM && simple_replace) { |
| 3695 if (subject->HasOnlyOneByteChars() && | 3695 if (subject->HasOnlyOneByteChars() && |
| 3696 replacement->HasOnlyOneByteChars()) { | 3696 replacement->HasOnlyOneByteChars()) { |
| 3697 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( | 3697 return StringReplaceGlobalAtomRegExpWithString<SeqOneByteString>( |
| 3698 isolate, subject, regexp, replacement, last_match_info); | 3698 isolate, subject, regexp, replacement, last_match_info); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4211 | 4211 |
| 4212 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); | 4212 CONVERT_ARG_HANDLE_CHECKED(String, subject, 0); |
| 4213 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); | 4213 CONVERT_ARG_HANDLE_CHECKED(JSRegExp, regexp, 1); |
| 4214 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); | 4214 CONVERT_ARG_HANDLE_CHECKED(JSArray, regexp_info, 2); |
| 4215 | 4215 |
| 4216 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); | 4216 RegExpImpl::GlobalCache global_cache(regexp, subject, true, isolate); |
| 4217 if (global_cache.HasException()) return Failure::Exception(); | 4217 if (global_cache.HasException()) return Failure::Exception(); |
| 4218 | 4218 |
| 4219 int capture_count = regexp->CaptureCount(); | 4219 int capture_count = regexp->CaptureCount(); |
| 4220 | 4220 |
| 4221 Zone zone(isolate); | 4221 ZoneScope zone_scope(isolate->runtime_zone()); |
| 4222 ZoneList<int> offsets(8, &zone); | 4222 ZoneList<int> offsets(8, zone_scope.zone()); |
| 4223 | 4223 |
| 4224 while (true) { | 4224 while (true) { |
| 4225 int32_t* match = global_cache.FetchNext(); | 4225 int32_t* match = global_cache.FetchNext(); |
| 4226 if (match == NULL) break; | 4226 if (match == NULL) break; |
| 4227 offsets.Add(match[0], &zone); // start | 4227 offsets.Add(match[0], zone_scope.zone()); // start |
| 4228 offsets.Add(match[1], &zone); // end | 4228 offsets.Add(match[1], zone_scope.zone()); // end |
| 4229 } | 4229 } |
| 4230 | 4230 |
| 4231 if (global_cache.HasException()) return Failure::Exception(); | 4231 if (global_cache.HasException()) return Failure::Exception(); |
| 4232 | 4232 |
| 4233 if (offsets.length() == 0) { | 4233 if (offsets.length() == 0) { |
| 4234 // Not a single match. | 4234 // Not a single match. |
| 4235 return isolate->heap()->null_value(); | 4235 return isolate->heap()->null_value(); |
| 4236 } | 4236 } |
| 4237 | 4237 |
| 4238 RegExpImpl::SetLastMatchInfo(regexp_info, | 4238 RegExpImpl::SetLastMatchInfo(regexp_info, |
| (...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6303 } | 6303 } |
| 6304 | 6304 |
| 6305 // The limit can be very large (0xffffffffu), but since the pattern | 6305 // The limit can be very large (0xffffffffu), but since the pattern |
| 6306 // isn't empty, we can never create more parts than ~half the length | 6306 // isn't empty, we can never create more parts than ~half the length |
| 6307 // of the subject. | 6307 // of the subject. |
| 6308 | 6308 |
| 6309 if (!subject->IsFlat()) FlattenString(subject); | 6309 if (!subject->IsFlat()) FlattenString(subject); |
| 6310 | 6310 |
| 6311 static const int kMaxInitialListCapacity = 16; | 6311 static const int kMaxInitialListCapacity = 16; |
| 6312 | 6312 |
| 6313 Zone zone(isolate); | 6313 ZoneScope zone_scope(isolate->runtime_zone()); |
| 6314 | 6314 |
| 6315 // Find (up to limit) indices of separator and end-of-string in subject | 6315 // Find (up to limit) indices of separator and end-of-string in subject |
| 6316 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); | 6316 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); |
| 6317 ZoneList<int> indices(initial_capacity, &zone); | 6317 ZoneList<int> indices(initial_capacity, zone_scope.zone()); |
| 6318 if (!pattern->IsFlat()) FlattenString(pattern); | 6318 if (!pattern->IsFlat()) FlattenString(pattern); |
| 6319 | 6319 |
| 6320 FindStringIndicesDispatch(isolate, *subject, *pattern, | 6320 FindStringIndicesDispatch(isolate, *subject, *pattern, |
| 6321 &indices, limit, &zone); | 6321 &indices, limit, zone_scope.zone()); |
| 6322 | 6322 |
| 6323 if (static_cast<uint32_t>(indices.length()) < limit) { | 6323 if (static_cast<uint32_t>(indices.length()) < limit) { |
| 6324 indices.Add(subject_length, &zone); | 6324 indices.Add(subject_length, zone_scope.zone()); |
| 6325 } | 6325 } |
| 6326 | 6326 |
| 6327 // The list indices now contains the end of each part to create. | 6327 // The list indices now contains the end of each part to create. |
| 6328 | 6328 |
| 6329 // Create JSArray of substrings separated by separator. | 6329 // Create JSArray of substrings separated by separator. |
| 6330 int part_count = indices.length(); | 6330 int part_count = indices.length(); |
| 6331 | 6331 |
| 6332 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); | 6332 Handle<JSArray> result = isolate->factory()->NewJSArray(part_count); |
| 6333 MaybeObject* maybe_result = result->EnsureCanContainHeapObjectElements(); | 6333 MaybeObject* maybe_result = result->EnsureCanContainHeapObjectElements(); |
| 6334 if (maybe_result->IsFailure()) return maybe_result; | 6334 if (maybe_result->IsFailure()) return maybe_result; |
| (...skipping 7610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13945 // Handle last resort GC and make sure to allow future allocations | 13945 // Handle last resort GC and make sure to allow future allocations |
| 13946 // to grow the heap without causing GCs (if possible). | 13946 // to grow the heap without causing GCs (if possible). |
| 13947 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13947 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13948 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13948 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13949 "Runtime::PerformGC"); | 13949 "Runtime::PerformGC"); |
| 13950 } | 13950 } |
| 13951 } | 13951 } |
| 13952 | 13952 |
| 13953 | 13953 |
| 13954 } } // namespace v8::internal | 13954 } } // namespace v8::internal |
| OLD | NEW |