Revision: 11669
Author: [email protected]
Date: Fri May 25 09:01:35 2012
Log: Merged r11661, r11662 into trunk branch.
Fix creating substring in string.replace(<global regexp>, <function>).
[email protected]
Review URL: https://chromiumcodereview.appspot.com/10445038
http://code.google.com/p/v8/source/detail?r=11669
Modified:
/trunk/src/runtime.cc
/trunk/src/version.cc
/trunk/test/mjsunit/regexp-global.js
=======================================
--- /trunk/src/runtime.cc Thu May 24 09:42:53 2012
+++ /trunk/src/runtime.cc Fri May 25 09:01:35 2012
@@ -3946,7 +3946,6 @@
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 @@
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 @@
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
=======================================
--- /trunk/src/version.cc Thu May 24 09:42:53 2012
+++ /trunk/src/version.cc Fri May 25 09:01:35 2012
@@ -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
=======================================
--- /trunk/test/mjsunit/regexp-global.js Wed May 23 05:04:37 2012
+++ /trunk/test/mjsunit/regexp-global.js Fri May 25 09:01:35 2012
@@ -125,3 +125,8 @@
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