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

Unified Diff: src/js/regexp.js

Issue 1506353009: [es6] implement RegExp.@@search. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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 | src/js/string.js » ('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 889c6b0acfad5231e6f0e66f967acffaf7a56f81..7119fdba01ba3f30318b3e096b2c8e72c347a474 100644
--- a/src/js/regexp.js
+++ b/src/js/regexp.js
@@ -16,6 +16,7 @@ var InternalArray = utils.InternalArray;
var InternalPackedArray = utils.InternalPackedArray;
var MakeTypeError;
var matchSymbol = utils.ImportNow("match_symbol");
+var searchSymbol = utils.ImportNow("search_symbol");
var splitSymbol = utils.ImportNow("split_symbol");
utils.ImportFromExperimental(function(from) {
@@ -117,8 +118,7 @@ function RegExpCompileJS(pattern, flags) {
function DoRegExpExec(regexp, string, index) {
- var result = %_RegExpExec(regexp, string, index, RegExpLastMatchInfo);
- return result;
+ return %_RegExpExec(regexp, string, index, RegExpLastMatchInfo);
}
@@ -357,6 +357,7 @@ function RegExpSplit(string, limit) {
// ES6 21.2.5.6.
function RegExpMatch(string) {
+ // TODO(yangguo): allow non-regexp receivers.
if (!IS_REGEXP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
"RegExp.prototype.@@match", this);
@@ -370,6 +371,19 @@ function RegExpMatch(string) {
}
+// ES6 21.2.5.9.
+function RegExpSearch(string) {
+ // TODO(yangguo): allow non-regexp receivers.
+ if (!IS_REGEXP(this)) {
+ throw MakeTypeError(kIncompatibleMethodReceiver,
+ "RegExp.prototype.@@search", this);
+ }
+ var match = DoRegExpExec(this, TO_STRING(string), 0);
+ if (match) return match[CAPTURE0];
+ return -1;
+}
+
+
// Getters for the static properties lastMatch, lastParen, leftContext, and
// rightContext of the RegExp constructor. The properties are computed based
// on the captures array of the last successful match and the subject string
@@ -488,6 +502,7 @@ utils.InstallFunctions(GlobalRegExp.prototype, DONT_ENUM, [
"toString", RegExpToString,
"compile", RegExpCompileJS,
matchSymbol, RegExpMatch,
+ searchSymbol, RegExpSearch,
splitSymbol, RegExpSplit,
]);
« no previous file with comments | « no previous file | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698