Debian Codegraph @

js/src/tests/test262/built-ins/JSON/rawJSON/basic.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: Basic functionality of JSON.rawJSON().
8 info: |
9 JSON.rawJSON ( text )
10
11 1. Let jsonString be ? ToString(text).
12 ...
13 4. Let internalSlotsList be « [[IsRawJSON]] ».
14 5. Let obj be OrdinaryObjectCreate(null, internalSlotsList).
15 6. Perform ! CreateDataPropertyOrThrow(obj, "rawJSON", jsonString).
16 7. Perform ! SetIntegrityLevel(obj, frozen).
17 8. Return obj.
18
19 features: [json-parse-with-source]
20 ---*/
21
22 assert.sameValue(JSON.stringify(JSON.rawJSON(1)), '1');
23 assert.sameValue(JSON.stringify(JSON.rawJSON(1.1)), '1.1');
24 assert.sameValue(JSON.stringify(JSON.rawJSON(-1)), '-1');
25 assert.sameValue(JSON.stringify(JSON.rawJSON(-1.1)), '-1.1');
26 assert.sameValue(JSON.stringify(JSON.rawJSON(1.1e1)), '11');
27 assert.sameValue(JSON.stringify(JSON.rawJSON(1.1e-1)), '0.11');
28
29 assert.sameValue(JSON.stringify(JSON.rawJSON(null)), 'null');
30 assert.sameValue(JSON.stringify(JSON.rawJSON(true)), 'true');
31 assert.sameValue(JSON.stringify(JSON.rawJSON(false)), 'false');
32 assert.sameValue(JSON.stringify(JSON.rawJSON('"foo"')), '"foo"');
33
34 assert.sameValue(JSON.stringify({ 42: JSON.rawJSON(37) }), '{"42":37}');
35 assert.sameValue(
36 JSON.stringify({ x: JSON.rawJSON(1), y: JSON.rawJSON(2) }),
37 '{"x":1,"y":2}'
38 );
39 assert.sameValue(
40 JSON.stringify({ x: { x: JSON.rawJSON(1), y: JSON.rawJSON(2) } }),
41 '{"x":{"x":1,"y":2}}'
42 );
43
44 assert.sameValue(JSON.stringify([JSON.rawJSON(1), JSON.rawJSON(1.1)]), '[1,1.1]');
45 assert.sameValue(
46 JSON.stringify([
47 JSON.rawJSON('"1"'),
48 JSON.rawJSON(true),
49 JSON.rawJSON(null),
50 JSON.rawJSON(false),
51 ]),
52 '["1",true,null,false]'
53 );
54 assert.sameValue(
55 JSON.stringify([{ x: JSON.rawJSON(1), y: JSON.rawJSON(1) }]),
56 '[{"x":1,"y":1}]'
57 );
58
59 reportCompare(0, 0);