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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/js/regexp.js ('k') | test/mjsunit/es6/string-search.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
11 11
12 var ArrayIndexOf; 12 var ArrayIndexOf;
13 var ArrayJoin; 13 var ArrayJoin;
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var GlobalString = global.String; 15 var GlobalString = global.String;
16 var InternalArray = utils.InternalArray; 16 var InternalArray = utils.InternalArray;
17 var InternalPackedArray = utils.InternalPackedArray; 17 var InternalPackedArray = utils.InternalPackedArray;
18 var MakeRangeError; 18 var MakeRangeError;
19 var MakeTypeError; 19 var MakeTypeError;
20 var MathMax; 20 var MathMax;
21 var MathMin; 21 var MathMin;
22 var matchSymbol = utils.ImportNow("match_symbol"); 22 var matchSymbol = utils.ImportNow("match_symbol");
23 var RegExpExec; 23 var RegExpExec;
24 var RegExpExecNoTests; 24 var RegExpExecNoTests;
25 var RegExpLastMatchInfo; 25 var RegExpLastMatchInfo;
26 var searchSymbol = utils.ImportNow("search_symbol");
26 var splitSymbol = utils.ImportNow("split_symbol"); 27 var splitSymbol = utils.ImportNow("split_symbol");
27 28
28 utils.Import(function(from) { 29 utils.Import(function(from) {
29 ArrayIndexOf = from.ArrayIndexOf; 30 ArrayIndexOf = from.ArrayIndexOf;
30 ArrayJoin = from.ArrayJoin; 31 ArrayJoin = from.ArrayJoin;
31 MakeRangeError = from.MakeRangeError; 32 MakeRangeError = from.MakeRangeError;
32 MakeTypeError = from.MakeTypeError; 33 MakeTypeError = from.MakeTypeError;
33 MathMax = from.MathMax; 34 MathMax = from.MathMax;
34 MathMin = from.MathMin; 35 MathMin = from.MathMin;
35 RegExpExec = from.RegExpExec; 36 RegExpExec = from.RegExpExec;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // 149 //
149 // This function is implementation specific. For now, we do not 150 // This function is implementation specific. For now, we do not
150 // do anything locale specific. 151 // do anything locale specific.
151 function StringLocaleCompareJS(other) { 152 function StringLocaleCompareJS(other) {
152 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare"); 153 CHECK_OBJECT_COERCIBLE(this, "String.prototype.localeCompare");
153 154
154 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other)); 155 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other));
155 } 156 }
156 157
157 158
158 // ECMA-262 section 15.5.4.10 159 // ES6 21.1.3.11.
159 function StringMatchJS(pattern) { 160 function StringMatchJS(pattern) {
160 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); 161 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
161 162
162 if (!IS_NULL_OR_UNDEFINED(pattern)) { 163 if (!IS_NULL_OR_UNDEFINED(pattern)) {
163 var matcher = pattern[matchSymbol]; 164 var matcher = pattern[matchSymbol];
164 if (!IS_UNDEFINED(matcher)) { 165 if (!IS_UNDEFINED(matcher)) {
165 if (!IS_CALLABLE(matcher)) { 166 if (!IS_CALLABLE(matcher)) {
166 throw MakeTypeError(kCalledNonCallable, matcher); 167 throw MakeTypeError(kCalledNonCallable, matcher);
167 } 168 }
168 return %_Call(matcher, pattern, this); 169 return %_Call(matcher, pattern, this);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 replacement = %Apply(replace, UNDEFINED, parameters, 0, j + 2); 499 replacement = %Apply(replace, UNDEFINED, parameters, 0, j + 2);
499 } 500 }
500 501
501 result += replacement; // The add method converts to string if necessary. 502 result += replacement; // The add method converts to string if necessary.
502 // Can't use matchInfo any more from here, since the function could 503 // Can't use matchInfo any more from here, since the function could
503 // overwrite it. 504 // overwrite it.
504 return result + %_SubString(subject, endOfMatch, subject.length); 505 return result + %_SubString(subject, endOfMatch, subject.length);
505 } 506 }
506 507
507 508
508 // ECMA-262 section 15.5.4.12 509 // ES6 21.1.3.15.
509 function StringSearch(re) { 510 function StringSearch(pattern) {
510 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search"); 511 CHECK_OBJECT_COERCIBLE(this, "String.prototype.search");
511 512
512 var regexp; 513 if (!IS_NULL_OR_UNDEFINED(pattern)) {
513 if (IS_REGEXP(re)) { 514 var searcher = pattern[searchSymbol];
514 regexp = re; 515 if (!IS_UNDEFINED(searcher)) {
515 } else { 516 return %_Call(searcher, pattern, this);
516 regexp = new GlobalRegExp(re); 517 }
517 } 518 }
518 var match = RegExpExec(regexp, TO_STRING(this), 0); 519
519 if (match) { 520 var subject = TO_STRING(this);
520 return match[CAPTURE0]; 521 var regexp = new GlobalRegExp(pattern);
521 } 522 return %_Call(regexp[searchSymbol], regexp, subject);
522 return -1;
523 } 523 }
524 524
525 525
526 // ECMA-262 section 15.5.4.13 526 // ECMA-262 section 15.5.4.13
527 function StringSlice(start, end) { 527 function StringSlice(start, end) {
528 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice"); 528 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice");
529 529
530 var s = TO_STRING(this); 530 var s = TO_STRING(this);
531 var s_len = s.length; 531 var s_len = s.length;
532 var start_i = TO_INTEGER(start); 532 var start_i = TO_INTEGER(start);
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 to.StringLastIndexOf = StringLastIndexOfJS; 1109 to.StringLastIndexOf = StringLastIndexOfJS;
1110 to.StringMatch = StringMatchJS; 1110 to.StringMatch = StringMatchJS;
1111 to.StringReplace = StringReplace; 1111 to.StringReplace = StringReplace;
1112 to.StringSlice = StringSlice; 1112 to.StringSlice = StringSlice;
1113 to.StringSplit = StringSplitJS; 1113 to.StringSplit = StringSplitJS;
1114 to.StringSubstr = StringSubstr; 1114 to.StringSubstr = StringSubstr;
1115 to.StringSubstring = StringSubstring; 1115 to.StringSubstring = StringSubstring;
1116 }); 1116 });
1117 1117
1118 }) 1118 })
OLDNEW
« 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