Reviewers: Jakob,
Description:
Merged r11661, r11662 into trunk branch.
Fix creating substring in string.replace(<global regexp>, <function>).
[email protected]
Please review this at https://chromiumcodereview.appspot.com/10445038/
SVN Base: https://v8.googlecode.com/svn/trunk
Affected files:
M src/runtime.cc
M src/version.cc
M test/mjsunit/regexp-global.js
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
a3c159a47f0b2e1555e59df94c2449472f796405..4deaabac184f9ef5fbc614788ede4058326020b6
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -3946,7 +3946,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++) {
@@ -3954,8 +3953,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) {
+ 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);
@@ -3966,6 +3971,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
Index: src/version.cc
diff --git a/src/version.cc b/src/version.cc
index
bc23ba69a91b8a685da4737d2f3f57a06ef0a569..ec6287084fa94ecf15d487e3fb5db09d88a1d124
100644
--- a/src/version.cc
+++ b/src/version.cc
@@ -35,7 +35,7 @@
#define MAJOR_VERSION 3
#define MINOR_VERSION 11
#define BUILD_NUMBER 6
-#define PATCH_LEVEL 1
+#define PATCH_LEVEL 2
// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
#define IS_CANDIDATE_VERSION 0
Index: test/mjsunit/regexp-global.js
diff --git a/test/mjsunit/regexp-global.js b/test/mjsunit/regexp-global.js
index
fac5c6af03fd11dfcb3a4527d948c0e56b47315d..12f857859648cdab2c7f9be94f9e1344f2c3e466
100644
--- a/test/mjsunit/regexp-global.js
+++ b/test/mjsunit/regexp-global.js
@@ -125,3 +125,8 @@ str = str.replace(/(FOUR|TWO) \u817f (GOOD|BAD)/g,
return match.length - 7;
});
assertEquals("4, 2!", str);
+
+// Test capture that is a real substring.
+var str = "Beasts of England, beasts of Ireland";
+str = str.replace(/(.*)/g, function(match) { return '~'; });
+assertEquals("~~", str);
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev