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

Unified Diff: src/runtime.cc

Issue 10454032: Fix creating substring in string.replace(<global regexp>, <function>). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regexp-global.js » ('j') | test/mjsunit/regexp-global.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index af9cef575b5a96c46062520aec63226241151c7c..d18a158c44d0442eb42ec67c5bea514031c15b48 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -3955,7 +3955,6 @@ static int SearchRegExpMultiple(
match = isolate->factory()->NewSubString(subject,
match_start,
match_end);
- first = false;
}
elements->set(0, *match);
for (int i = 1; i <= capture_count; i++) {
@@ -3963,8 +3962,14 @@ static int SearchRegExpMultiple(
if (start >= 0) {
int end = current_match[i * 2 + 1];
ASSERT(start <= end);
- Handle<String> substring =
- isolate->factory()->NewProperSubString(subject, start, end);
+ Handle<String> substring;
+ if (!first) {
Lasse Reichstein Nielsen 2012/05/29 09:06:52 Perhaps drop "first" and just check if start > 0 h
+ substring =
+ isolate->factory()->NewProperSubString(subject, start, end);
+ } else {
+ substring =
+ isolate->factory()->NewSubString(subject, start, end);
+ }
elements->set(i, *substring);
} else {
ASSERT(current_match[i * 2 + 1] < 0);
@@ -3975,6 +3980,7 @@ static int SearchRegExpMultiple(
elements->set(capture_count + 2, *subject);
builder->Add(*isolate->factory()->NewJSArrayWithElements(elements));
}
+ first = false;
}
// If we did not get the maximum number of matches, we can stop here
« no previous file with comments | « no previous file | test/mjsunit/regexp-global.js » ('j') | test/mjsunit/regexp-global.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698