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

Unified Diff: src/js/string.js

Issue 1434523002: [es6] Implement @@match subclassing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 1 month 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/harmony/string-match.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 d58a91883e6d30b01158a5ff3a6a15790a6c05af..c838064112f4543dda4e9dc2fb97c0b55d5f6bd3 100644
--- a/src/js/string.js
+++ b/src/js/string.js
@@ -19,6 +19,7 @@ var MakeRangeError;
var MakeTypeError;
var MathMax;
var MathMin;
+var matchSymbol = utils.ImportNow("match_symbol");
var RegExpExec;
var RegExpExecNoTests;
var RegExpLastMatchInfo;
@@ -155,18 +156,23 @@ function StringLocaleCompareJS(other) {
// ECMA-262 section 15.5.4.10
-function StringMatchJS(regexp) {
+function StringMatchJS(pattern) {
CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
- var subject = TO_STRING(this);
- if (IS_REGEXP(regexp)) {
- if (!REGEXP_GLOBAL(regexp)) return RegExpExecNoTests(regexp, subject, 0);
- var result = %StringMatch(subject, regexp, RegExpLastMatchInfo);
- regexp.lastIndex = 0;
- return result;
+ if (!IS_NULL_OR_UNDEFINED(pattern)) {
+ var matcher = pattern[matchSymbol];
+ if (!IS_UNDEFINED(matcher)) {
+ if (!IS_CALLABLE(matcher)) {
+ throw MakeTypeError(kCalledNonCallable, matcher);
+ }
+ return %_Call(matcher, pattern, this);
+ }
}
+
+ var subject = TO_STRING(this);
+
// Non-regexp argument.
- regexp = new GlobalRegExp(regexp);
+ var regexp = new GlobalRegExp(pattern);
return RegExpExecNoTests(regexp, subject, 0);
}
« no previous file with comments | « src/js/regexp.js ('k') | test/mjsunit/harmony/string-match.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698