Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/runtime.cc

Issue 12033099: Fix additional spec violations wrt RegExp.lastIndex. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects-inl.h ('k') | src/string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2894 matching lines...) Expand 10 before | Expand all | Expand 10 after
2905 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); 2905 String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex));
2906 int subject_len = subject->length(); 2906 int subject_len = subject->length();
2907 int pattern_len = pattern->length(); 2907 int pattern_len = pattern->length();
2908 int replacement_len = replacement->length(); 2908 int replacement_len = replacement->length();
2909 2909
2910 FindStringIndicesDispatch( 2910 FindStringIndicesDispatch(
2911 isolate, *subject, pattern, &indices, 0xffffffff, zone); 2911 isolate, *subject, pattern, &indices, 0xffffffff, zone);
2912 2912
2913 int matches = indices.length(); 2913 int matches = indices.length();
2914 if (matches == 0) { 2914 if (matches == 0) {
2915 JSRegExp::ResetLastIndex(isolate, pattern_regexp); 2915 return isolate->heap()->undefined_value();
2916 return *subject;
2917 } 2916 }
2918 2917
2919 // Detect integer overflow. 2918 // Detect integer overflow.
2920 int64_t result_len_64 = 2919 int64_t result_len_64 =
2921 (static_cast<int64_t>(replacement_len) - 2920 (static_cast<int64_t>(replacement_len) -
2922 static_cast<int64_t>(pattern_len)) * 2921 static_cast<int64_t>(pattern_len)) *
2923 static_cast<int64_t>(matches) + 2922 static_cast<int64_t>(matches) +
2924 static_cast<int64_t>(subject_len); 2923 static_cast<int64_t>(subject_len);
2925 if (result_len_64 > INT_MAX) return Failure::OutOfMemoryException(0x11); 2924 if (result_len_64 > INT_MAX) return Failure::OutOfMemoryException(0x11);
2926 int result_len = static_cast<int>(result_len_64); 2925 int result_len = static_cast<int>(result_len_64);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 isolate, subject, regexp, replacement, last_match_info); 3007 isolate, subject, regexp, replacement, last_match_info);
3009 } 3008 }
3010 } 3009 }
3011 3010
3012 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); 3011 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate);
3013 if (global_cache.HasException()) return Failure::Exception(); 3012 if (global_cache.HasException()) return Failure::Exception();
3014 3013
3015 int32_t* current_match = global_cache.FetchNext(); 3014 int32_t* current_match = global_cache.FetchNext();
3016 if (current_match == NULL) { 3015 if (current_match == NULL) {
3017 if (global_cache.HasException()) return Failure::Exception(); 3016 if (global_cache.HasException()) return Failure::Exception();
3018 JSRegExp::ResetLastIndex(isolate, regexp); 3017 return isolate->heap()->undefined_value();
3019 return *subject;
3020 } 3018 }
3021 3019
3022 // Guessing the number of parts that the final result string is built 3020 // Guessing the number of parts that the final result string is built
3023 // from. Global regexps can match any number of times, so we guess 3021 // from. Global regexps can match any number of times, so we guess
3024 // conservatively. 3022 // conservatively.
3025 int expected_parts = 3023 int expected_parts =
3026 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; 3024 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1;
3027 ReplacementStringBuilder builder(isolate->heap(), 3025 ReplacementStringBuilder builder(isolate->heap(),
3028 subject, 3026 subject,
3029 expected_parts); 3027 expected_parts);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3107 last_match_info); 3105 last_match_info);
3108 } 3106 }
3109 } 3107 }
3110 3108
3111 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate); 3109 RegExpImpl::GlobalCache global_cache(regexp, subject, is_global, isolate);
3112 if (global_cache.HasException()) return Failure::Exception(); 3110 if (global_cache.HasException()) return Failure::Exception();
3113 3111
3114 int32_t* current_match = global_cache.FetchNext(); 3112 int32_t* current_match = global_cache.FetchNext();
3115 if (current_match == NULL) { 3113 if (current_match == NULL) {
3116 if (global_cache.HasException()) return Failure::Exception(); 3114 if (global_cache.HasException()) return Failure::Exception();
3117 JSRegExp::ResetLastIndex(isolate, regexp); 3115 return isolate->heap()->undefined_value();
3118 return *subject;
3119 } 3116 }
3120 3117
3121 int start = current_match[0]; 3118 int start = current_match[0];
3122 int end = current_match[1]; 3119 int end = current_match[1];
3123 int capture_count = regexp->CaptureCount(); 3120 int capture_count = regexp->CaptureCount();
3124 int subject_length = subject->length(); 3121 int subject_length = subject->length();
3125 3122
3126 int new_length = subject_length - (end - start); 3123 int new_length = subject_length - (end - start);
3127 if (new_length == 0) return isolate->heap()->empty_string(); 3124 if (new_length == 0) return isolate->heap()->empty_string();
3128 3125
(...skipping 10391 matching lines...) Expand 10 before | Expand all | Expand 10 after
13520 // Handle last resort GC and make sure to allow future allocations 13517 // Handle last resort GC and make sure to allow future allocations
13521 // to grow the heap without causing GCs (if possible). 13518 // to grow the heap without causing GCs (if possible).
13522 isolate->counters()->gc_last_resort_from_js()->Increment(); 13519 isolate->counters()->gc_last_resort_from_js()->Increment();
13523 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13520 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13524 "Runtime::PerformGC"); 13521 "Runtime::PerformGC");
13525 } 13522 }
13526 } 13523 }
13527 13524
13528 13525
13529 } } // namespace v8::internal 13526 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698