Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(855)

Unified Diff: src/regexp.js

Issue 3389022: RegExp: Fix caching to correctly set lastIndex. (Closed)
Patch Set: Address review comment. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-52801.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-52801.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698