OLD | NEW |
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 assertEquals("axc", "abc".replace(/b/g, replace_obj)); |
220 | 220 |
221 var search_obj = { length: 1, toString: function() { return "b"; }}; | 221 var search_obj = { length: 1, toString: function() { return "b"; }}; |
222 assertEquals("axc", "abc".replace(search_obj, function() { return "x"; })); | 222 assertEquals("axc", "abc".replace(search_obj, function() { return "x"; })); |
223 | 223 |
224 var side_effect_flag = false; | 224 var side_effect_flag = false; |
225 var replace_obj_side_effects = { | 225 var replace_obj_side_effects = { |
226 toString: function() { side_effect_flag = true; return "x" } | 226 toString: function() { side_effect_flag = true; return "x" } |
227 } | 227 } |
228 assertEquals("abc", "abc".replace(/z/g, function() { return "x"; })); | 228 assertEquals("abc", "abc".replace(/z/g, replace_obj_side_effects)); |
229 assertTrue(side_effect_flag); // Side effect triggers even without a match. | 229 assertTrue(side_effect_flag); // Side effect triggers even without a match. |
230 | 230 |
231 var regexp99pattern = ""; | 231 var regexp99pattern = ""; |
232 var subject = ""; | 232 var subject = ""; |
233 for (var i = 0; i < 99; i++) { | 233 for (var i = 0; i < 99; i++) { |
234 regexp99pattern += "(.)"; | 234 regexp99pattern += "(.)"; |
235 subject += String.fromCharCode(i + 24); | 235 subject += String.fromCharCode(i + 24); |
236 } | 236 } |
237 | 237 |
238 function testIndices99(re) { | 238 function testIndices99(re) { |
(...skipping 27 matching lines...) Expand all Loading... |
266 // 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. |
267 var tail = subject.substr(59); | 267 var tail = subject.substr(59); |
268 for (var i = 60; i < 100; i++) { | 268 for (var i = 60; i < 100; i++) { |
269 assertEquals(String.fromCharCode(i / 10 + 23) + (i % 10) + tail, | 269 assertEquals(String.fromCharCode(i / 10 + 23) + (i % 10) + tail, |
270 subject.replace(re, "$" + i)); | 270 subject.replace(re, "$" + i)); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 testIndices59(new RegExp(regexp59pattern)); | 274 testIndices59(new RegExp(regexp59pattern)); |
275 testIndices59(new RegExp(regexp59pattern, "g")); | 275 testIndices59(new RegExp(regexp59pattern, "g")); |
OLD | NEW |