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

Side by Side Diff: test/mjsunit/string-replace.js

Issue 12316158: Insert conversion to string in string.replace. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 months 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/string.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 "abaz", /a(.)/g, replacer); 209 "abaz", /a(.)/g, replacer);
210 210
211 var str = 'She sells seashells by the seashore.'; 211 var str = 'She sells seashells by the seashore.';
212 var re = /sh/g; 212 var re = /sh/g;
213 assertEquals('She sells sea$schells by the sea$schore.', 213 assertEquals('She sells sea$schells by the sea$schore.',
214 str.replace(re,"$$" + 'sch')) 214 str.replace(re,"$$" + 'sch'))
215 215
216 216
217 var replace_obj = { length: 0, toString: function() { return "x"; }}; 217 var replace_obj = { length: 0, toString: function() { return "x"; }};
218 assertEquals("axc", "abc".replace(/b/, replace_obj)); 218 assertEquals("axc", "abc".replace(/b/, replace_obj));
219 assertEquals("axc", "abc".replace(/b/g, replace_obj));
219 220
220 var search_obj = { length: 1, toString: function() { return "b"; }}; 221 var search_obj = { length: 1, toString: function() { return "b"; }};
221 assertEquals("axc", "abc".replace(search_obj, function() { return "x"; })); 222 assertEquals("axc", "abc".replace(search_obj, function() { return "x"; }));
222 223
224 var side_effect_flag = false;
225 var replace_obj_side_effects = {
226 toString: function() { side_effect_flag = true; return "x" }
227 }
228 assertEquals("abc", "abc".replace(/z/g, function() { return "x"; }));
229 assertTrue(side_effect_flag); // Side effect triggers even without a match.
230
223 var regexp99pattern = ""; 231 var regexp99pattern = "";
224 var subject = ""; 232 var subject = "";
225 for (var i = 0; i < 99; i++) { 233 for (var i = 0; i < 99; i++) {
226 regexp99pattern += "(.)"; 234 regexp99pattern += "(.)";
227 subject += String.fromCharCode(i + 24); 235 subject += String.fromCharCode(i + 24);
228 } 236 }
229 237
230 function testIndices99(re) { 238 function testIndices99(re) {
231 // Test $1 .. $99 239 // Test $1 .. $99
232 for (var i = 1; i < 100; i++) { 240 for (var i = 1; i < 100; i++) {
(...skipping 25 matching lines...) Expand all
258 // followed by "0", $61 as $6, followed by "1" and so on. 266 // followed by "0", $61 as $6, followed by "1" and so on.
259 var tail = subject.substr(59); 267 var tail = subject.substr(59);
260 for (var i = 60; i < 100; i++) { 268 for (var i = 60; i < 100; i++) {
261 assertEquals(String.fromCharCode(i / 10 + 23) + (i % 10) + tail, 269 assertEquals(String.fromCharCode(i / 10 + 23) + (i % 10) + tail,
262 subject.replace(re, "$" + i)); 270 subject.replace(re, "$" + i));
263 } 271 }
264 } 272 }
265 273
266 testIndices59(new RegExp(regexp59pattern)); 274 testIndices59(new RegExp(regexp59pattern));
267 testIndices59(new RegExp(regexp59pattern, "g")); 275 testIndices59(new RegExp(regexp59pattern, "g"));
OLDNEW
« no previous file with comments | « src/string.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698