RegExp-invalid-control-escape-character-class.js (1610B)
1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: prod-annexB-ClassAtomNoDash 6 description: > 7 Character classes containing an invalid control escape behave like [\\c] 8 info: | 9 ClassAtomNoDash :: `\` 10 11 The production ClassAtomNoDash :: `\` evaluates as follows: 12 1. Return the CharSet containing the single character `\`. 13 features: [generators] 14 ---*/ 15 16 function* invalidControls() { 17 // Check ASCII characters which are not in the extended range or syntax 18 // characters 19 for (let alpha = 0x00; alpha <= 0x7F; alpha++) { 20 let letter = String.fromCharCode(alpha); 21 if (!letter.match(/[0-9A-Za-z_\$(|)\[\]\/\\^]/)) { 22 yield letter; 23 } 24 } 25 yield ""; 26 } 27 28 for (let letter of invalidControls()) { 29 var source = "[\\c" + letter + "]"; 30 var re = new RegExp(source); 31 32 if (letter.length > 0) { 33 var char = letter.charCodeAt(0); 34 var str = String.fromCharCode(char % 32); 35 var arr = re.exec(str); 36 if (str !== letter && arr !== null) { 37 throw new Test262Error(`Character ${letter} unreasonably wrapped around as a control character`); 38 } 39 40 arr = re.exec(letter); 41 if (arr === null) { 42 throw new Test262Error(`Character ${letter} missing from character class ${source}`); 43 } 44 } 45 arr = re.exec("\\") 46 if (arr === null) { 47 throw new Test262Error(`Character \\ missing from character class ${source}`); 48 } 49 arr = re.exec("c") 50 if (arr === null) { 51 throw new Test262Error(`Character c missing from character class ${source}`); 52 } 53 } 54 55 56 reportCompare(0, 0);