Debian Codegraph @

js/src/tests/test262/built-ins/JSON/stringify/value-number-non-finite.js

raw
1 // Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-serializejsonproperty
5 description: >
6 Non-finite numbers as serialized as null.
7 info: |
8 JSON.stringify ( value [ , replacer [ , space ] ] )
9
10 [...]
11 12. Return ? SerializeJSONProperty(the empty String, wrapper).
12
13 SerializeJSONProperty ( key, holder )
14
15 [...]
16 4. If Type(value) is Object, then
17 a. If value has a [[NumberData]] internal slot, then
18 i. Set value to ? ToNumber(value).
19 [...]
20 9. If Type(value) is Number, then
21 a. If value is finite, return ! ToString(value).
22 b. Return "null".
23 ---*/
24
25 assert.sameValue(JSON.stringify(Infinity), 'null');
26 assert.sameValue(JSON.stringify({key: -Infinity}), '{"key":null}');
27 assert.sameValue(JSON.stringify([NaN]), '[null]');
28
29 reportCompare(0, 0);