Index: src/regexp-delay.js |
diff --git a/src/regexp-delay.js b/src/regexp-delay.js |
index e2492f7245b24ba8d1082d0bbcf94a99e309add7..dc1b0429f7094c5c4fe80d5af5515c8fd2e5fb91 100644 |
--- a/src/regexp-delay.js |
+++ b/src/regexp-delay.js |
@@ -344,6 +344,7 @@ function RegExpToString() { |
// on the captures array of the last successful match and the subject string |
// of the last successful match. |
function RegExpGetLastMatch() { |
+ if (lastMatchInfoOverride) { return lastMatchInfoOverride[0]; } |
var regExpSubject = LAST_SUBJECT(lastMatchInfo); |
return SubString(regExpSubject, |
lastMatchInfo[CAPTURE0], |
@@ -352,6 +353,11 @@ function RegExpGetLastMatch() { |
function RegExpGetLastParen() { |
+ if (lastMatchInfoOverride) { |
+ var override = lastMatchInfoOverride; |
+ if (override.length <= 3) return ''; |
+ return override[override.length - 3]; |
+ } |
var length = NUMBER_OF_CAPTURES(lastMatchInfo); |
if (length <= 2) return ''; // There were no captures. |
// We match the SpiderMonkey behavior: return the substring defined by the |
@@ -368,17 +374,32 @@ function RegExpGetLastParen() { |
function RegExpGetLeftContext() { |
- return SubString(LAST_SUBJECT(lastMatchInfo), |
- 0, |
- lastMatchInfo[CAPTURE0]); |
+ var start_index; |
+ var subject; |
+ if (!lastMatchInfoOverride) { |
+ start_index = lastMatchInfo[CAPTURE0]; |
+ subject = LAST_SUBJECT(lastMatchInfo); |
+ } else { |
+ var override = lastMatchInfoOverride; |
+ start_index = override[override.length - 2]; |
+ subject = override[override.length - 1]; |
+ } |
+ return SubString(subject, 0, start_index); |
} |
function RegExpGetRightContext() { |
- var subject = LAST_SUBJECT(lastMatchInfo); |
- return SubString(subject, |
- lastMatchInfo[CAPTURE1], |
- subject.length); |
+ var start_index; |
+ var subject; |
+ if (!lastMatchInfoOverride) { |
+ start_index = lastMatchInfo[CAPTURE1]; |
+ subject = LAST_SUBJECT(lastMatchInfo); |
+ } else { |
+ var override = lastMatchInfoOverride; |
+ subject = override[override.length - 1]; |
+ start_index = override[override.length - 2] + subject.length; |
+ } |
+ return SubString(subject, start_index, subject.length); |
} |
@@ -387,6 +408,10 @@ function RegExpGetRightContext() { |
// called with indices from 1 to 9. |
function RegExpMakeCaptureGetter(n) { |
return function() { |
+ if (lastMatchInfoOverride) { |
+ if (n < lastMatchInfoOverride.length - 2) return lastMatchInfoOverride[n]; |
+ return ''; |
+ } |
var index = n * 2; |
if (index >= NUMBER_OF_CAPTURES(lastMatchInfo)) return ''; |
var matchStart = lastMatchInfo[CAPTURE(index)]; |
@@ -411,6 +436,12 @@ var lastMatchInfo = [ |
0, // REGEXP_FIRST_CAPTURE + 1 |
]; |
+// Override last match info with an array of actual substrings. |
+// Used internally by replace regexp with function. |
+// The array has the format of an "apply" argument for a replacement |
+// function. |
+var lastMatchInfoOverride = null; |
+ |
// ------------------------------------------------------------------- |
function SetupRegExp() { |