Revision: 11661
Author: [email protected]
Date: Fri May 25 03:52:38 2012
Log: Fix creating substring in string.replace(<global regexp>,
<function>).
BUG=
TEST=regexp-global.js
Review URL: https://chromiumcodereview.appspot.com/10454032
http://code.google.com/p/v8/source/detail?r=11661
Modified:
/branches/bleeding_edge/src/runtime.cc
/branches/bleeding_edge/test/mjsunit/regexp-global.js
=======================================
--- /branches/bleeding_edge/src/runtime.cc Wed May 23 07:24:29 2012
+++ /branches/bleeding_edge/src/runtime.cc Fri May 25 03:52:38 2012
@@ -3955,7 +3955,6 @@
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 @@
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);
@@ -3975,6 +3980,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
=======================================
--- /branches/bleeding_edge/test/mjsunit/regexp-global.js Tue May 22
07:05:44 2012
+++ /branches/bleeding_edge/test/mjsunit/regexp-global.js Fri May 25
03:52:38 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("~~");
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev