Debian Codegraph @

js/src/tests/test262/built-ins/JSON/rawJSON/invalid-JSON-text.js

raw
1 // |reftest| shell-option(--enable-json-parse-with-source) skip-if(!JSON.hasOwnProperty('isRawJSON')||!xulRuntime.shell) -- json-parse-with-source is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2023 the V8 project authors. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-json.rawjson
7 description: >
8 Inputs not convertible to string, or convertible to invalid JSON string
9 info: |
10 JSON.rawJSON ( text )
11
12 1. Let jsonString be ? ToString(text).
13 ...
14 3. Parse StringToCodePoints(jsonString) as a JSON text as specified in
15 ECMA-404. Throw a SyntaxError exception if it is not a valid JSON text as
16 defined in that specification, or if its outermost value is an object or
17 array as defined in that specification.
18
19 features: [json-parse-with-source]
20 ---*/
21
22 assert.throws(TypeError, () => {
23 JSON.rawJSON(Symbol('123'));
24 });
25
26 assert.throws(SyntaxError, () => {
27 JSON.rawJSON(undefined);
28 });
29
30 assert.throws(SyntaxError, () => {
31 JSON.rawJSON({});
32 });
33
34 assert.throws(SyntaxError, () => {
35 JSON.rawJSON([]);
36 });
37
38 reportCompare(0, 0);