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

Unified Diff: src/js/string.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 | « src/js/regexp.js ('k') | test/mjsunit/es6/string-search.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/string.js
diff --git a/src/js/string.js b/src/js/string.js
index c838064112f4543dda4e9dc2fb97c0b55d5f6bd3..0830059a522d5c76e28f51d739c433eff08c52cb 100644
--- a/src/js/string.js
+++ b/src/js/string.js
@@ -23,6 +23,7 @@ var matchSymbol = utils.ImportNow("match_symbol");
var RegExpExec;
var RegExpExecNoTests;
var RegExpLastMatchInfo;
+var searchSymbol = utils.ImportNow("search_symbol");
var splitSymbol = utils.ImportNow("split_symbol");
utils.Import(function(from) {
@@ -155,7 +156,7 @@ function StringLocaleCompareJS(other) {
}
-// ECMA-262 section 15.5.4.10
+// ES6 21.1.3.11.
function StringMatchJS(pattern) {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
@@ -505,21 +506,20 @@ function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) {
}
-// ECMA-262 section 15.5.4.12
-function StringSearch(re) {
+// ES6 21.1.3.15.
+function StringSearch(pattern) {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.search");
- var regexp;
- if (IS_REGEXP(re)) {
- regexp = re;
- } else {
- regexp = new GlobalRegExp(re);
- }
- var match = RegExpExec(regexp, TO_STRING(this), 0);
- if (match) {
- return match[CAPTURE0];
+ if (!IS_NULL_OR_UNDEFINED(pattern)) {
+ var searcher = pattern[searchSymbol];
+ if (!IS_UNDEFINED(searcher)) {
+ return %_Call(searcher, pattern, this);
+ }
}
- return -1;
+
+ var subject = TO_STRING(this);
+ var regexp = new GlobalRegExp(pattern);
+ return %_Call(regexp[searchSymbol], regexp, subject);
}
« no previous file with comments | « src/js/regexp.js ('k') | test/mjsunit/es6/string-search.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698