| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 // Flags: --harmony-regexp-named-captures --harmony-regexp-lookbehind | 5 // Flags: --harmony-regexp-named-captures --harmony-regexp-lookbehind |
| 6 | 6 |
| 7 // Malformed named captures. | 7 // Malformed named captures. |
| 8 assertThrows("/(?<>a)/u", SyntaxError); // Empty name. | 8 assertThrows("/(?<>a)/u", SyntaxError); // Empty name. |
| 9 assertThrows("/(?<aa)/u", SyntaxError); // Unterminated name. | 9 assertThrows("/(?<aa)/u", SyntaxError); // Unterminated name. |
| 10 assertThrows("/(?<42a>a)/u", SyntaxError); // Name starting with digits. | 10 assertThrows("/(?<42a>a)/u", SyntaxError); // Name starting with digits. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 // Properties created on result.groups. | 171 // Properties created on result.groups. |
| 172 assertEquals(["fst", "snd"], | 172 assertEquals(["fst", "snd"], |
| 173 Object.getOwnPropertyNames( | 173 Object.getOwnPropertyNames( |
| 174 /(?<fst>.)|(?<snd>.)/u.exec("abcd").groups)); | 174 /(?<fst>.)|(?<snd>.)/u.exec("abcd").groups)); |
| 175 | 175 |
| 176 // The '__proto__' property on the groups object. | 176 // The '__proto__' property on the groups object. |
| 177 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); | 177 assertEquals(undefined, /(?<a>.)/u.exec("a").groups.__proto__); |
| 178 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); | 178 assertEquals("a", /(?<__proto__>a)/u.exec("a").groups.__proto__); |
| 179 | 179 |
| 180 // Backslash as ID_Start and ID_Continue (v8:5868). |
| 181 assertThrows("/(?<\\>.)/", SyntaxError); // '\' misclassified as ID_Start. |
| 182 assertThrows("/(?<a\\>.)/", SyntaxError); // '\' misclassified as ID_Continue. |
| 183 |
| 180 // Backreference before the group (exercises the capture mini-parser). | 184 // Backreference before the group (exercises the capture mini-parser). |
| 181 assertThrows("/\\1(?:.)/u", SyntaxError); | 185 assertThrows("/\\1(?:.)/u", SyntaxError); |
| 182 assertThrows("/\\1(?<=a)./u", SyntaxError); | 186 assertThrows("/\\1(?<=a)./u", SyntaxError); |
| 183 assertThrows("/\\1(?<!a)./u", SyntaxError); | 187 assertThrows("/\\1(?<!a)./u", SyntaxError); |
| 184 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); | 188 assertEquals(["a", "a"], /\1(?<a>.)/u.exec("abcd")); |
| 185 | 189 |
| 186 // @@replace with a callable replacement argument (no named captures). | 190 // @@replace with a callable replacement argument (no named captures). |
| 187 { | 191 { |
| 188 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { | 192 let result = "abcd".replace(/(.)(.)/u, (match, fst, snd, offset, str) => { |
| 189 assertEquals("ab", match); | 193 assertEquals("ab", match); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // named captures). | 366 // named captures). |
| 363 { | 367 { |
| 364 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); | 368 let re = toSlowMode(/(?<fst>.)(?<snd>.)/u); |
| 365 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); | 369 assertEquals("bacd", "abcd".replace(re, "$<snd>$<fst>")); |
| 366 assertEquals("bacd", "abcd".replace(re, "$2$1")); | 370 assertEquals("bacd", "abcd".replace(re, "$2$1")); |
| 367 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); | 371 assertThrows(() => "abcd".replace(re, "$<snd"), SyntaxError); |
| 368 assertEquals("cd", "abcd".replace(re, "$<42$1>")); | 372 assertEquals("cd", "abcd".replace(re, "$<42$1>")); |
| 369 assertEquals("cd", "abcd".replace(re, "$<thd>")); | 373 assertEquals("cd", "abcd".replace(re, "$<thd>")); |
| 370 assertEquals("cd", "abcd".replace(re, "$<$1>")); | 374 assertEquals("cd", "abcd".replace(re, "$<$1>")); |
| 371 } | 375 } |
| OLD | NEW |