illegal-empty-and-start-end-chars.js (931B)
1 // Copyright (C) 2023 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: sec-json.rawjson 6 description: Throw SyntaxError on empty string, or illegal start/end chars 7 info: | 8 JSON.rawJSON ( text ) 9 10 1. Let jsonString be ? ToString(text). 11 2. Throw a SyntaxError exception if jsonString is the empty String, or if 12 either the first or last code unit of jsonString is any of 0x0009 13 (CHARACTER TABULATION), 0x000A (LINE FEED), 0x000D (CARRIAGE RETURN), or 14 0x0020 (SPACE). 15 16 features: [json-parse-with-source] 17 ---*/ 18 19 const ILLEGAL_END_CHARS = ['\n', '\t', '\r', ' ']; 20 for (const char of ILLEGAL_END_CHARS) { 21 assert.throws(SyntaxError, () => { 22 JSON.rawJSON(`${char}123`); 23 }); 24 assert.throws(SyntaxError, () => { 25 JSON.rawJSON(`123${char}`); 26 }); 27 } 28 29 assert.throws(SyntaxError, () => { 30 JSON.rawJSON(''); 31 }); 32 33 reportCompare(0, 0);