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

Side by Side Diff: src/js/string.js

Issue 1432683002: Revert of Implement flag and source getters on RegExp.prototype. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@rproto
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « src/js/regexp.js ('k') | src/js/symbol.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 RegExpExec; 20 var RegExpExec;
21 var RegExpExecNoTests; 21 var RegExpExecNoTests;
22 var regExpFlagsSymbol = utils.ImportNow("regexp_flags_symbol");
23 var RegExpLastMatchInfo; 22 var RegExpLastMatchInfo;
24 23
25 utils.Import(function(from) { 24 utils.Import(function(from) {
26 ArrayIndexOf = from.ArrayIndexOf; 25 ArrayIndexOf = from.ArrayIndexOf;
27 ArrayJoin = from.ArrayJoin; 26 ArrayJoin = from.ArrayJoin;
28 MakeRangeError = from.MakeRangeError; 27 MakeRangeError = from.MakeRangeError;
29 MakeTypeError = from.MakeTypeError; 28 MakeTypeError = from.MakeTypeError;
30 RegExpExec = from.RegExpExec; 29 RegExpExec = from.RegExpExec;
31 RegExpExecNoTests = from.RegExpExecNoTests; 30 RegExpExecNoTests = from.RegExpExecNoTests;
32 RegExpLastMatchInfo = from.RegExpLastMatchInfo; 31 RegExpLastMatchInfo = from.RegExpLastMatchInfo;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other)); 148 return %StringLocaleCompare(TO_STRING(this), TO_STRING(other));
150 } 149 }
151 150
152 151
153 // ECMA-262 section 15.5.4.10 152 // ECMA-262 section 15.5.4.10
154 function StringMatchJS(regexp) { 153 function StringMatchJS(regexp) {
155 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match"); 154 CHECK_OBJECT_COERCIBLE(this, "String.prototype.match");
156 155
157 var subject = TO_STRING(this); 156 var subject = TO_STRING(this);
158 if (IS_REGEXP(regexp)) { 157 if (IS_REGEXP(regexp)) {
159 if (!REGEXP_GLOBAL(regexp)) return RegExpExecNoTests(regexp, subject, 0); 158 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
160 var result = %StringMatch(subject, regexp, RegExpLastMatchInfo); 159 var result = %StringMatch(subject, regexp, RegExpLastMatchInfo);
161 regexp.lastIndex = 0; 160 regexp.lastIndex = 0;
162 return result; 161 return result;
163 } 162 }
164 // Non-regexp argument. 163 // Non-regexp argument.
165 regexp = new GlobalRegExp(regexp); 164 regexp = new GlobalRegExp(regexp);
166 return RegExpExecNoTests(regexp, subject, 0); 165 return RegExpExecNoTests(regexp, subject, 0);
167 } 166 }
168 167
169 168
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // ...... non-global search 218 // ...... non-global search
220 // .. string search 219 // .. string search
221 // .... special case that replaces with one single character 220 // .... special case that replaces with one single character
222 // ...... function replace 221 // ...... function replace
223 // ...... string replace (with $-expansion) 222 // ...... string replace (with $-expansion)
224 223
225 if (IS_REGEXP(search)) { 224 if (IS_REGEXP(search)) {
226 if (!IS_CALLABLE(replace)) { 225 if (!IS_CALLABLE(replace)) {
227 replace = TO_STRING(replace); 226 replace = TO_STRING(replace);
228 227
229 if (!REGEXP_GLOBAL(search)) { 228 if (!search.global) {
230 // Non-global regexp search, string replace. 229 // Non-global regexp search, string replace.
231 var match = RegExpExec(search, subject, 0); 230 var match = RegExpExec(search, subject, 0);
232 if (match == null) { 231 if (match == null) {
233 search.lastIndex = 0 232 search.lastIndex = 0
234 return subject; 233 return subject;
235 } 234 }
236 if (replace.length == 0) { 235 if (replace.length == 0) {
237 return %_SubString(subject, 0, match[CAPTURE0]) + 236 return %_SubString(subject, 0, match[CAPTURE0]) +
238 %_SubString(subject, match[CAPTURE1], subject.length) 237 %_SubString(subject, match[CAPTURE1], subject.length)
239 } 238 }
240 return ExpandReplacement(replace, subject, RegExpLastMatchInfo, 239 return ExpandReplacement(replace, subject, RegExpLastMatchInfo,
241 %_SubString(subject, 0, match[CAPTURE0])) + 240 %_SubString(subject, 0, match[CAPTURE0])) +
242 %_SubString(subject, match[CAPTURE1], subject.length); 241 %_SubString(subject, match[CAPTURE1], subject.length);
243 } 242 }
244 243
245 // Global regexp search, string replace. 244 // Global regexp search, string replace.
246 search.lastIndex = 0; 245 search.lastIndex = 0;
247 return %StringReplaceGlobalRegExpWithString( 246 return %StringReplaceGlobalRegExpWithString(
248 subject, search, replace, RegExpLastMatchInfo); 247 subject, search, replace, RegExpLastMatchInfo);
249 } 248 }
250 249
251 if (REGEXP_GLOBAL(search)) { 250 if (search.global) {
252 // Global regexp search, function replace. 251 // Global regexp search, function replace.
253 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); 252 return StringReplaceGlobalRegExpWithFunction(subject, search, replace);
254 } 253 }
255 // Non-global regexp search, function replace. 254 // Non-global regexp search, function replace.
256 return StringReplaceNonGlobalRegExpWithFunction(subject, search, replace); 255 return StringReplaceNonGlobalRegExpWithFunction(subject, search, replace);
257 } 256 }
258 257
259 search = TO_STRING(search); 258 search = TO_STRING(search);
260 259
261 if (search.length == 1 && 260 if (search.length == 1 &&
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 to.StringLastIndexOf = StringLastIndexOfJS; 1170 to.StringLastIndexOf = StringLastIndexOfJS;
1172 to.StringMatch = StringMatchJS; 1171 to.StringMatch = StringMatchJS;
1173 to.StringReplace = StringReplace; 1172 to.StringReplace = StringReplace;
1174 to.StringSlice = StringSlice; 1173 to.StringSlice = StringSlice;
1175 to.StringSplit = StringSplitJS; 1174 to.StringSplit = StringSplitJS;
1176 to.StringSubstr = StringSubstr; 1175 to.StringSubstr = StringSubstr;
1177 to.StringSubstring = StringSubstring; 1176 to.StringSubstring = StringSubstring;
1178 }); 1177 });
1179 1178
1180 }) 1179 })
OLDNEW
« no previous file with comments | « src/js/regexp.js ('k') | src/js/symbol.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698