Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --harmony-unicode-regexps | |
| 6 | |
| 7 var L = "\ud800"; | |
| 8 var T = "\udc00"; | |
| 9 var x = "x"; | |
| 10 | |
| 11 var r = /()/g; // Global, but not unicode. | |
| 12 // Zero-length matches do not advance lastIndex. | |
| 13 assertEquals(["", ""], r.exec(L + T + L + T)); | |
| 14 assertEquals(0, r.lastIndex); | |
| 15 r.lastIndex = 1; | |
| 16 assertEquals(["", ""], r.exec(L + T + L + T)); | |
| 17 assertEquals(1, r.lastIndex); | |
| 18 | |
| 19 var u = /()/ug; // Global and unicode. | |
| 20 // Zero-length matches do not advance lastIndex. | |
| 21 assertEquals(["", ""], u.exec(L + T + L + T)); | |
| 22 assertEquals(0, u.lastIndex); | |
| 23 u.lastIndex = 1; | |
| 24 assertEquals(["", ""], u.exec(L + T + L + T)); | |
| 25 assertEquals(1, u.lastIndex); | |
| 26 | |
| 27 // However, with repeating matches, lastIndex does not matter. | |
| 28 // We do advance from match to match. | |
| 29 r.lastIndex = 2; | |
| 30 assertEquals(x + L + x + T + x + L + x + T + x, | |
| 31 (L + T + L + T).replace(r, "x")); | |
| 32 | |
| 33 // With unicode flag, we advance code point by code point. | |
| 34 u.lastIndex = 3; | |
| 35 assertEquals(x + L + T + x + L + T + x, | |
| 36 (L + T + L + T).replace(u, "x")); | |
| 37 | |
| 38 // Test that exhausting the global match cache is fine. | |
| 39 assertEquals((x + L + T).repeat(1000) + x, | |
| 40 (L + T).repeat(1000).replace(u, "x")); | |
| 41 | |
| 42 // Same thing for RegExp.prototype.match. | |
| 43 r.lastIndex = 2; | |
| 44 assertEquals(["","","","",""], (L + T + L + T).match(r)); | |
| 45 | |
| 46 u.lastIndex = 2; | |
| 47 assertEquals(["","",""], (L + T + L + T).match(u)); | |
|
erikcorry
2016/01/27 10:31:31
Try these last two again, but setting lastIndex to
Yang
2016/01/27 12:19:21
Done.
| |
| 48 | |
| 49 var expected = []; | |
| 50 for (var i = 0; i <= 1000; i++) expected.push(""); | |
| 51 assertEquals(expected, (L + T).repeat(1000).match(u)); | |
| OLD | NEW |