| 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 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 // If we still have the original map, set in-object properties directly. | 1784 // If we still have the original map, set in-object properties directly. |
| 1785 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, source); | 1785 regexp->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, source); |
| 1786 // Both true and false are immovable immortal objects so no need for write | 1786 // Both true and false are immovable immortal objects so no need for write |
| 1787 // barrier. | 1787 // barrier. |
| 1788 regexp->InObjectPropertyAtPut( | 1788 regexp->InObjectPropertyAtPut( |
| 1789 JSRegExp::kGlobalFieldIndex, global, SKIP_WRITE_BARRIER); | 1789 JSRegExp::kGlobalFieldIndex, global, SKIP_WRITE_BARRIER); |
| 1790 regexp->InObjectPropertyAtPut( | 1790 regexp->InObjectPropertyAtPut( |
| 1791 JSRegExp::kIgnoreCaseFieldIndex, ignoreCase, SKIP_WRITE_BARRIER); | 1791 JSRegExp::kIgnoreCaseFieldIndex, ignoreCase, SKIP_WRITE_BARRIER); |
| 1792 regexp->InObjectPropertyAtPut( | 1792 regexp->InObjectPropertyAtPut( |
| 1793 JSRegExp::kMultilineFieldIndex, multiline, SKIP_WRITE_BARRIER); | 1793 JSRegExp::kMultilineFieldIndex, multiline, SKIP_WRITE_BARRIER); |
| 1794 regexp->ResetLastIndex(); | 1794 regexp->InObjectPropertyAtPut( |
| 1795 JSRegExp::kLastIndexFieldIndex, Smi::FromInt(0), SKIP_WRITE_BARRIER); |
| 1795 return regexp; | 1796 return regexp; |
| 1796 } | 1797 } |
| 1797 | 1798 |
| 1798 // Map has changed, so use generic, but slower, method. | 1799 // Map has changed, so use generic, but slower, method. |
| 1799 PropertyAttributes final = | 1800 PropertyAttributes final = |
| 1800 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE); | 1801 static_cast<PropertyAttributes>(READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 1801 PropertyAttributes writable = | 1802 PropertyAttributes writable = |
| 1802 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | 1803 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 1803 Heap* heap = isolate->heap(); | 1804 Heap* heap = isolate->heap(); |
| 1804 MaybeObject* result; | 1805 MaybeObject* result; |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2897 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); | 2898 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); |
| 2898 int subject_len = subject->length(); | 2899 int subject_len = subject->length(); |
| 2899 int pattern_len = pattern->length(); | 2900 int pattern_len = pattern->length(); |
| 2900 int replacement_len = replacement->length(); | 2901 int replacement_len = replacement->length(); |
| 2901 | 2902 |
| 2902 FindStringIndicesDispatch( | 2903 FindStringIndicesDispatch( |
| 2903 isolate, *subject, pattern, &indices, 0xffffffff, zone); | 2904 isolate, *subject, pattern, &indices, 0xffffffff, zone); |
| 2904 | 2905 |
| 2905 int matches = indices.length(); | 2906 int matches = indices.length(); |
| 2906 if (matches == 0) { | 2907 if (matches == 0) { |
| 2907 pattern_regexp->ResetLastIndex(); | 2908 return isolate->heap()->undefined_value(); |
| 2908 return *subject; | |
| 2909 } | 2909 } |
| 2910 | 2910 |
| 2911 // Detect integer overflow. | 2911 // Detect integer overflow. |
| 2912 int64_t result_len_64 = | 2912 int64_t result_len_64 = |
| 2913 (static_cast<int64_t>(replacement_len) - | 2913 (static_cast<int64_t>(replacement_len) - |
| 2914 static_cast<int64_t>(pattern_len)) * | 2914 static_cast<int64_t>(pattern_len)) * |
| 2915 static_cast<int64_t>(matches) + | 2915 static_cast<int64_t>(matches) + |
| 2916 static_cast<int64_t>(subject_len); | 2916 static_cast<int64_t>(subject_len); |
| 2917 if (result_len_64 > INT_MAX) return Failure::OutOfMemoryException(); | 2917 if (result_len_64 > INT_MAX) return Failure::OutOfMemoryException(); |
| 2918 int result_len = static_cast<int>(result_len_64); | 2918 int result_len = static_cast<int>(result_len_64); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2999 isolate, subject, regexp, replacement, last_match_info); | 2999 isolate, subject, regexp, replacement, last_match_info); |
| 3000 } | 3000 } |
| 3001 } | 3001 } |
| 3002 | 3002 |
| 3003 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); | 3003 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); |
| 3004 if (global_cache.HasException()) return Failure::Exception(); | 3004 if (global_cache.HasException()) return Failure::Exception(); |
| 3005 | 3005 |
| 3006 int32_t* current_match = global_cache.FetchNext(); | 3006 int32_t* current_match = global_cache.FetchNext(); |
| 3007 if (current_match == NULL) { | 3007 if (current_match == NULL) { |
| 3008 if (global_cache.HasException()) return Failure::Exception(); | 3008 if (global_cache.HasException()) return Failure::Exception(); |
| 3009 regexp->ResetLastIndex(); | 3009 return isolate->heap()->undefined_value(); |
| 3010 return *subject; | |
| 3011 } | 3010 } |
| 3012 | 3011 |
| 3013 // Guessing the number of parts that the final result string is built | 3012 // Guessing the number of parts that the final result string is built |
| 3014 // from. Global regexps can match any number of times, so we guess | 3013 // from. Global regexps can match any number of times, so we guess |
| 3015 // conservatively. | 3014 // conservatively. |
| 3016 int expected_parts = | 3015 int expected_parts = |
| 3017 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; | 3016 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; |
| 3018 ReplacementStringBuilder builder(isolate->heap(), | 3017 ReplacementStringBuilder builder(isolate->heap(), |
| 3019 subject, | 3018 subject, |
| 3020 expected_parts); | 3019 expected_parts); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3098 last_match_info); | 3097 last_match_info); |
| 3099 } | 3098 } |
| 3100 } | 3099 } |
| 3101 | 3100 |
| 3102 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); | 3101 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); |
| 3103 if (global_cache.HasException()) return Failure::Exception(); | 3102 if (global_cache.HasException()) return Failure::Exception(); |
| 3104 | 3103 |
| 3105 int32_t* current_match = global_cache.FetchNext(); | 3104 int32_t* current_match = global_cache.FetchNext(); |
| 3106 if (current_match == NULL) { | 3105 if (current_match == NULL) { |
| 3107 if (global_cache.HasException()) return Failure::Exception(); | 3106 if (global_cache.HasException()) return Failure::Exception(); |
| 3108 regexp->ResetLastIndex(); | 3107 return isolate->heap()->undefined_value(); |
| 3109 return *subject; | |
| 3110 } | 3108 } |
| 3111 | 3109 |
| 3112 int start = current_match[0]; | 3110 int start = current_match[0]; |
| 3113 int end = current_match[1]; | 3111 int end = current_match[1]; |
| 3114 int capture_count = regexp->CaptureCount(); | 3112 int capture_count = regexp->CaptureCount(); |
| 3115 int subject_length = subject->length(); | 3113 int subject_length = subject->length(); |
| 3116 | 3114 |
| 3117 int new_length = subject_length - (end - start); | 3115 int new_length = subject_length - (end - start); |
| 3118 if (new_length == 0) return isolate->heap()->empty_string(); | 3116 if (new_length == 0) return isolate->heap()->empty_string(); |
| 3119 | 3117 |
| (...skipping 10385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13505 // Handle last resort GC and make sure to allow future allocations | 13503 // Handle last resort GC and make sure to allow future allocations |
| 13506 // to grow the heap without causing GCs (if possible). | 13504 // to grow the heap without causing GCs (if possible). |
| 13507 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13505 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13508 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13506 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13509 "Runtime::PerformGC"); | 13507 "Runtime::PerformGC"); |
| 13510 } | 13508 } |
| 13511 } | 13509 } |
| 13512 | 13510 |
| 13513 | 13511 |
| 13514 } } // namespace v8::internal | 13512 } } // namespace v8::internal |
| OLD | NEW |