Commit 1cb2a70c authored by jgruber's avatar jgruber Committed by Commit bot

[regexp] Remove dead code

Remove dead code, and drop the legacy RegExp.prototype.exec implementation (the
only differences are TO_BOOLEAN on global and sticky).

BUG=v8:5339

Review-Url: https://codereview.chromium.org/2301803003
Cr-Commit-Position: refs/heads/master@{#39121}
parent 7e5b8fee
...@@ -162,46 +162,6 @@ function RegExpSubclassExecJS(string) { ...@@ -162,46 +162,6 @@ function RegExpSubclassExecJS(string) {
%FunctionRemovePrototype(RegExpSubclassExecJS); %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);
}
// ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S ) // ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S )
// Also takes an optional exec method in case our caller // Also takes an optional exec method in case our caller
// has already fetched exec. // has already fetched exec.
...@@ -216,70 +176,11 @@ function RegExpSubclassExec(regexp, string, exec) { ...@@ -216,70 +176,11 @@ function RegExpSubclassExec(regexp, string, exec) {
} }
return result; return result;
} }
return %_Call(RegExpExecJS, regexp, string); return %_Call(RegExpSubclassExecJS, regexp, string);
} }
%SetForceInlineFlag(RegExpSubclassExec); %SetForceInlineFlag(RegExpSubclassExec);
// One-element cache for the simplified test regexp.
var regexp_key;
var regexp_val;
// Legacy implementation of RegExp.prototype.test
// Section 15.10.6.3 doesn't actually make sense, but the intention seems to be
// that test is defined in terms of String.prototype.exec. However, it probably
// means the original value of String.prototype.exec, which is what everybody
// else implements.
function RegExpTest(string) {
if (!IS_REGEXP(this)) {
throw %make_type_error(kIncompatibleMethodReceiver,
'RegExp.prototype.test', 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);
if (REGEXP_GLOBAL(this) || REGEXP_STICKY(this)) {
if (i < 0 || i > string.length) {
this.lastIndex = 0;
return false;
}
// matchIndices is either null or the RegExpLastMatchInfo array.
var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo);
if (IS_NULL(matchIndices)) {
this.lastIndex = 0;
return false;
}
this.lastIndex = RegExpLastMatchInfo[CAPTURE1];
return true;
} else {
// Non-global, non-sticky regexp.
// Remove irrelevant preceeding '.*' in a test regexp. The expression
// checks whether this.source starts with '.*' and that the third char is
// not a '?'. But see https://code.google.com/p/v8/issues/detail?id=3560
var regexp = this;
var source = REGEXP_SOURCE(regexp);
if (source.length >= 3 &&
%_StringCharCodeAt(source, 0) == 46 && // '.'
%_StringCharCodeAt(source, 1) == 42 && // '*'
%_StringCharCodeAt(source, 2) != 63) { // '?'
regexp = TrimRegExp(regexp);
}
// matchIndices is either null or the RegExpLastMatchInfo array.
var matchIndices = %_RegExpExec(regexp, string, 0, RegExpLastMatchInfo);
if (IS_NULL(matchIndices)) {
this.lastIndex = 0;
return false;
}
return true;
}
}
// ES#sec-regexp.prototype.test RegExp.prototype.test ( S ) // ES#sec-regexp.prototype.test RegExp.prototype.test ( S )
function RegExpSubclassTest(string) { function RegExpSubclassTest(string) {
if (!IS_RECEIVER(this)) { if (!IS_RECEIVER(this)) {
...@@ -292,18 +193,6 @@ function RegExpSubclassTest(string) { ...@@ -292,18 +193,6 @@ function RegExpSubclassTest(string) {
} }
%FunctionRemovePrototype(RegExpSubclassTest); %FunctionRemovePrototype(RegExpSubclassTest);
function TrimRegExp(regexp) {
if (regexp_key !== regexp) {
regexp_key = regexp;
regexp_val =
new GlobalRegExp(
%_SubString(REGEXP_SOURCE(regexp), 2, REGEXP_SOURCE(regexp).length),
(REGEXP_IGNORE_CASE(regexp) ? REGEXP_MULTILINE(regexp) ? "im" : "i"
: REGEXP_MULTILINE(regexp) ? "m" : ""));
}
return regexp_val;
}
function AtSurrogatePair(subject, index) { function AtSurrogatePair(subject, index) {
if (index + 1 >= subject.length) return false; if (index + 1 >= subject.length) return false;
...@@ -927,10 +816,7 @@ utils.Export(function(to) { ...@@ -927,10 +816,7 @@ utils.Export(function(to) {
to.InternalRegExpMatch = InternalRegExpMatch; to.InternalRegExpMatch = InternalRegExpMatch;
to.InternalRegExpReplace = InternalRegExpReplace; to.InternalRegExpReplace = InternalRegExpReplace;
to.IsRegExp = IsRegExp; to.IsRegExp = IsRegExp;
to.RegExpExec = DoRegExpExec;
to.RegExpInitialize = RegExpInitialize; to.RegExpInitialize = RegExpInitialize;
to.RegExpLastMatchInfo = RegExpLastMatchInfo;
to.RegExpTest = RegExpTest;
}); });
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment