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

Unified Diff: src/js/regexp.js

Issue 2404223002: Revert of [regexp] Port test, match, and search (Closed)
Patch Set: Created 4 years, 2 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/heap-symbols.h ('k') | src/objects.h » ('j') | 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 915a44f0b54daec86f4f005660aa9383c988e34d..b5574877ec3a19f16dd1fdbd5efbe9762e05b99f 100644
--- a/src/js/regexp.js
+++ b/src/js/regexp.js
@@ -103,6 +103,7 @@
endmacro
+
// ES#sec-regexpexec Runtime Semantics: RegExpExec ( R, S )
// Also takes an optional exec method in case our caller
// has already fetched exec.
@@ -120,6 +121,19 @@
return %_Call(RegExpExecJS, regexp, string);
}
%SetForceInlineFlag(RegExpSubclassExec);
+
+
+// ES#sec-regexp.prototype.test RegExp.prototype.test ( S )
+function RegExpSubclassTest(string) {
+ if (!IS_RECEIVER(this)) {
+ throw %make_type_error(kIncompatibleMethodReceiver,
+ 'RegExp.prototype.test', this);
+ }
+ string = TO_STRING(string);
+ var match = RegExpSubclassExec(this, string);
+ return !IS_NULL(match);
+}
+%FunctionRemovePrototype(RegExpSubclassTest);
function AtSurrogatePair(subject, index) {
@@ -273,6 +287,39 @@
return array;
}
%FunctionRemovePrototype(RegExpSubclassSplit);
+
+
+// ES#sec-regexp.prototype-@@match
+// RegExp.prototype [ @@match ] ( string )
+function RegExpSubclassMatch(string) {
+ if (!IS_RECEIVER(this)) {
+ throw %make_type_error(kIncompatibleMethodReceiver,
+ "RegExp.prototype.@@match", this);
+ }
+ string = TO_STRING(string);
+ var global = this.global;
+ if (!global) return RegExpSubclassExec(this, string);
+ var unicode = this.unicode;
+ this.lastIndex = 0;
+ var array = new InternalArray();
+ var n = 0;
+ var result;
+ while (true) {
+ result = RegExpSubclassExec(this, string);
+ if (IS_NULL(result)) {
+ if (n === 0) return null;
+ break;
+ }
+ var matchStr = TO_STRING(result[0]);
+ array[n] = matchStr;
+ if (matchStr === "") SetAdvancedStringIndex(this, string, unicode);
+ n++;
+ }
+ var resultArray = [];
+ %MoveArrayContents(array, resultArray);
+ return resultArray;
+}
+%FunctionRemovePrototype(RegExpSubclassMatch);
// Legacy implementation of RegExp.prototype[Symbol.replace] which
@@ -669,11 +716,32 @@
%FunctionRemovePrototype(RegExpSubclassReplace);
+// ES#sec-regexp.prototype-@@search
+// RegExp.prototype [ @@search ] ( string )
+function RegExpSubclassSearch(string) {
+ if (!IS_RECEIVER(this)) {
+ throw %make_type_error(kIncompatibleMethodReceiver,
+ "RegExp.prototype.@@search", this);
+ }
+ string = TO_STRING(string);
+ var previousLastIndex = this.lastIndex;
+ if (previousLastIndex != 0) this.lastIndex = 0;
+ var result = RegExpSubclassExec(this, string);
+ var currentLastIndex = this.lastIndex;
+ if (currentLastIndex != previousLastIndex) this.lastIndex = previousLastIndex;
+ if (IS_NULL(result)) return -1;
+ return result.index;
+}
+%FunctionRemovePrototype(RegExpSubclassSearch);
+
// -------------------------------------------------------------------
utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [
+ "test", RegExpSubclassTest,
+ matchSymbol, RegExpSubclassMatch,
replaceSymbol, RegExpSubclassReplace,
+ searchSymbol, RegExpSubclassSearch,
splitSymbol, RegExpSubclassSplit,
]);
« no previous file with comments | « src/heap-symbols.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698