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

Unified Diff: src/js/regexp.js

Issue 2337923002: [regexp] Merge exec implementations (Closed)
Patch Set: Rename RegExpSubclassExecJS->RegExpExecJS Created 4 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/regexp.js
diff --git a/src/js/regexp.js b/src/js/regexp.js
index f4101556b21dca293fd3c2c87a113bf1f6e4de99..a542b34f27c0227788e097e326a3c4a8eefd0a35 100644
--- a/src/js/regexp.js
+++ b/src/js/regexp.js
@@ -178,7 +178,7 @@ function RegExpExecNoTests(regexp, string, start) {
// ES#sec-regexp.prototype.exec
// RegExp.prototype.exec ( string )
-function RegExpSubclassExecJS(string) {
+function RegExpExecJS(string) {
if (!IS_REGEXP(this)) {
throw %make_type_error(kIncompatibleMethodReceiver,
'RegExp.prototype.exec', this);
@@ -217,47 +217,7 @@ function RegExpSubclassExecJS(string) {
}
RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string);
}
-%FunctionRemovePrototype(RegExpSubclassExecJS);
-
-
-// Legacy implementation of RegExp.prototype.exec
-function RegExpExecJS(string) {
- if (!IS_REGEXP(this)) {
- throw %make_type_error(kIncompatibleMethodReceiver,
- 'RegExp.prototype.exec', this);
- }
-
- string = TO_STRING(string);
- var lastIndex = this.lastIndex;
-
- // Conversion is required by the ES2015 specification (RegExpBuiltinExec
- // algorithm, step 4) even if the value is discarded for non-global RegExps.
- var i = TO_LENGTH(lastIndex);
-
- var updateLastIndex = REGEXP_GLOBAL(this) || REGEXP_STICKY(this);
- if (updateLastIndex) {
- if (i < 0 || i > string.length) {
- this.lastIndex = 0;
- return null;
- }
- } else {
- i = 0;
- }
-
- // matchIndices is either null or the RegExpLastMatchInfo array.
- var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo);
-
- if (IS_NULL(matchIndices)) {
- this.lastIndex = 0;
- return null;
- }
-
- // Successful match.
- if (updateLastIndex) {
- this.lastIndex = RegExpLastMatchInfo[CAPTURE1];
- }
- RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string);
-}
+%FunctionRemovePrototype(RegExpExecJS);
// ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S )
@@ -474,7 +434,7 @@ function RegExpSubclassSplit(string, limit) {
var exec;
if (IS_REGEXP(this) && constructor === GlobalRegExp) {
exec = this.exec;
- if (exec === RegExpSubclassExecJS) {
+ if (exec === RegExpExecJS) {
return %_Call(RegExpSplit, this, string, limit);
}
}
@@ -867,7 +827,7 @@ function RegExpSubclassReplace(string, replace) {
var exec;
if (IS_REGEXP(this)) {
exec = this.exec;
- if (exec === RegExpSubclassExecJS) {
+ if (exec === RegExpExecJS) {
return %_Call(RegExpReplace, this, string, replace);
}
}
@@ -1119,7 +1079,7 @@ GlobalRegExpPrototype = new GlobalObject();
utils.InstallGetter(GlobalRegExp, speciesSymbol, RegExpSpecies);
utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [
- "exec", RegExpSubclassExecJS,
+ "exec", RegExpExecJS,
"test", RegExpSubclassTest,
"toString", RegExpToString,
"compile", RegExpCompileJS,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698