Index: src/regexp.js |
diff --git a/src/regexp.js b/src/regexp.js |
index 566a96c3489ed6c525ac836338ae99c3dae73c74..faa525d62da27ca518e3b4fa8ec12f6ab2cbdaa8 100644 |
--- a/src/regexp.js |
+++ b/src/regexp.js |
@@ -186,6 +186,10 @@ function RegExpExec(string) { |
%_IsRegExpEquivalent(cache.regExp, this) && |
%_ObjectEquals(cache.subject, string)) { |
if (cache.answerSaved) { |
+ // If this regexp is not global, cache.lastIndex is zero, so we only get |
+ // here if this.lastIndex is zero, and resulting this.lastIndex |
+ // must be zero too, so no change is necessary. |
+ if (this.global) this.lastIndex = lastMatchInfo[CAPTURE1]; |
return %_RegExpCloneResult(cache.answer); |
} else { |
saveAnswer = true; |
@@ -282,6 +286,10 @@ function RegExpTest(string) { |
%_IsRegExpEquivalent(cache.regExp, this) && |
%_ObjectEquals(cache.subject, string) && |
%_ObjectEquals(cache.lastIndex, lastIndex)) { |
+ // If this regexp is not global, cache.lastIndex is zero, so we only get |
+ // here if this.lastIndex is zero, and resulting this.lastIndex |
+ // must be zero too, so no change is necessary. |
+ if (this.global) this.lastIndex = lastMatchInfo[CAPTURE1]; |
return cache.answer; |
} |