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

Unified Diff: src/regexp.js

Issue 286203010: Harden builtins BuildResultFromMatchInfo and URIDecodeOctets (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comments Created 6 years, 7 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 | « src/hydrogen.cc ('k') | src/uri.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 d58ca2634bd03f313e1326ca2c5b5542dbb00139..76d6a9649c191bc057fccdc5d702c5fd8a47e2e6 100644
--- a/src/regexp.js
+++ b/src/regexp.js
@@ -108,23 +108,26 @@ function DoRegExpExec(regexp, string, index) {
}
-function BuildResultFromMatchInfo(lastMatchInfo, s) {
- var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1;
- var start = lastMatchInfo[CAPTURE0];
- var end = lastMatchInfo[CAPTURE1];
- var result = %_RegExpConstructResult(numResults, start, s);
- result[0] = %_SubString(s, start, end);
+// This is kind of performance sensitive, so we want to avoid unnecessary
+// type checks on inputs. But we also don't want to inline it several times
+// manually, so we use a macro :-)
+macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING)
+ var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1;
+ var start = MATCHINFO[CAPTURE0];
+ var end = MATCHINFO[CAPTURE1];
+ var result = %_RegExpConstructResult(numResults, start, STRING);
+ result[0] = %_SubString(STRING, start, end);
var j = REGEXP_FIRST_CAPTURE + 2;
for (var i = 1; i < numResults; i++) {
- start = lastMatchInfo[j++];
+ start = MATCHINFO[j++];
if (start != -1) {
- end = lastMatchInfo[j];
- result[i] = %_SubString(s, start, end);
+ end = MATCHINFO[j];
+ result[i] = %_SubString(STRING, start, end);
}
j++;
}
return result;
-}
+endmacro
function RegExpExecNoTests(regexp, string, start) {
@@ -132,7 +135,7 @@ function RegExpExecNoTests(regexp, string, start) {
var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo);
if (matchInfo !== null) {
lastMatchInfoOverride = null;
- return BuildResultFromMatchInfo(matchInfo, string);
+ RETURN_NEW_RESULT_FROM_MATCH_INFO(matchInfo, string);
}
regexp.lastIndex = 0;
return null;
@@ -175,7 +178,7 @@ function RegExpExec(string) {
if (global) {
this.lastIndex = lastMatchInfo[CAPTURE1];
}
- return BuildResultFromMatchInfo(matchIndices, string);
+ RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string);
}
« no previous file with comments | « src/hydrogen.cc ('k') | src/uri.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698