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

Side by Side Diff: src/string.js

Issue 11451005: Fix spec violations related to regexp.lastIndex (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/regress/regress-2437.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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 180
181 // ECMA-262 section 15.5.4.10 181 // ECMA-262 section 15.5.4.10
182 function StringMatch(regexp) { 182 function StringMatch(regexp) {
183 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 183 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
184 throw MakeTypeError("called_on_null_or_undefined", 184 throw MakeTypeError("called_on_null_or_undefined",
185 ["String.prototype.match"]); 185 ["String.prototype.match"]);
186 } 186 }
187 var subject = TO_STRING_INLINE(this); 187 var subject = TO_STRING_INLINE(this);
188 if (IS_REGEXP(regexp)) { 188 if (IS_REGEXP(regexp)) {
189 // Emulate RegExp.prototype.exec's side effect in step 5, even though
190 // value is discarded.
191 ToInteger(regexp.lastIndex);
189 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); 192 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
190 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); 193 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]);
191 // lastMatchInfo is defined in regexp.js. 194 // lastMatchInfo is defined in regexp.js.
192 var result = %StringMatch(subject, regexp, lastMatchInfo); 195 var result = %StringMatch(subject, regexp, lastMatchInfo);
193 if (result !== null) lastMatchInfoOverride = null; 196 if (result !== null) lastMatchInfoOverride = null;
194 return result; 197 return result;
195 } 198 }
196 // Non-regexp argument. 199 // Non-regexp argument.
197 regexp = new $RegExp(regexp); 200 regexp = new $RegExp(regexp);
198 return RegExpExecNoTests(regexp, subject, 0); 201 return RegExpExecNoTests(regexp, subject, 0);
(...skipping 21 matching lines...) Expand all
220 // ECMA-262, section 15.5.4.11 223 // ECMA-262, section 15.5.4.11
221 function StringReplace(search, replace) { 224 function StringReplace(search, replace) {
222 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 225 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
223 throw MakeTypeError("called_on_null_or_undefined", 226 throw MakeTypeError("called_on_null_or_undefined",
224 ["String.prototype.replace"]); 227 ["String.prototype.replace"]);
225 } 228 }
226 var subject = TO_STRING_INLINE(this); 229 var subject = TO_STRING_INLINE(this);
227 230
228 // Delegate to one of the regular expression variants if necessary. 231 // Delegate to one of the regular expression variants if necessary.
229 if (IS_REGEXP(search)) { 232 if (IS_REGEXP(search)) {
233 // Emulate RegExp.prototype.exec's side effect in step 5, even though
234 // value is discarded.
235 ToInteger(search.lastIndex);
230 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); 236 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]);
231 if (IS_SPEC_FUNCTION(replace)) { 237 if (IS_SPEC_FUNCTION(replace)) {
232 if (search.global) { 238 if (search.global) {
233 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); 239 return StringReplaceGlobalRegExpWithFunction(subject, search, replace);
234 } else { 240 } else {
235 return StringReplaceNonGlobalRegExpWithFunction(subject, 241 return StringReplaceNonGlobalRegExpWithFunction(subject,
236 search, 242 search,
237 replace); 243 replace);
238 } 244 }
239 } else { 245 } else {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 var resultBuilder = new ReplaceResultBuilder(subject, res); 450 var resultBuilder = new ReplaceResultBuilder(subject, res);
445 var result = resultBuilder.generate(); 451 var result = resultBuilder.generate();
446 resultArray.length = 0; 452 resultArray.length = 0;
447 reusableReplaceArray = resultArray; 453 reusableReplaceArray = resultArray;
448 return result; 454 return result;
449 } 455 }
450 456
451 457
452 function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) { 458 function StringReplaceNonGlobalRegExpWithFunction(subject, regexp, replace) {
453 var matchInfo = DoRegExpExec(regexp, subject, 0); 459 var matchInfo = DoRegExpExec(regexp, subject, 0);
454 if (IS_NULL(matchInfo)) return subject; 460 if (IS_NULL(matchInfo)) {
461 regexp.lastIndex = 0;
462 return subject;
463 }
455 var index = matchInfo[CAPTURE0]; 464 var index = matchInfo[CAPTURE0];
456 var result = SubString(subject, 0, index); 465 var result = SubString(subject, 0, index);
457 var endOfMatch = matchInfo[CAPTURE1]; 466 var endOfMatch = matchInfo[CAPTURE1];
458 // Compute the parameter list consisting of the match, captures, index, 467 // Compute the parameter list consisting of the match, captures, index,
459 // and subject for the replace function invocation. 468 // and subject for the replace function invocation.
460 // The number of captures plus one for the match. 469 // The number of captures plus one for the match.
461 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; 470 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1;
462 var replacement; 471 var replacement;
463 var receiver = %GetDefaultReceiver(replace); 472 var receiver = %GetDefaultReceiver(replace);
464 if (m == 1) { 473 if (m == 1) {
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 "fixed", StringFixed, 992 "fixed", StringFixed,
984 "italics", StringItalics, 993 "italics", StringItalics,
985 "small", StringSmall, 994 "small", StringSmall,
986 "strike", StringStrike, 995 "strike", StringStrike,
987 "sub", StringSub, 996 "sub", StringSub,
988 "sup", StringSup 997 "sup", StringSup
989 )); 998 ));
990 } 999 }
991 1000
992 SetUpString(); 1001 SetUpString();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/regress/regress-2437.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698