summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/JSON/stringify/value-number-non-finite.js
blob: 1109b956ea551fdbf26b4841bc3d4e6a515715ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-serializejsonproperty
description: >
  Non-finite numbers as serialized as null.
info: |
  JSON.stringify ( value [ , replacer [ , space ] ] )

  [...]
  12. Return ? SerializeJSONProperty(the empty String, wrapper).

  SerializeJSONProperty ( key, holder )

  [...]
  4. If Type(value) is Object, then
    a. If value has a [[NumberData]] internal slot, then
      i. Set value to ? ToNumber(value).
  [...]
  9. If Type(value) is Number, then
    a. If value is finite, return ! ToString(value).
    b. Return "null".
---*/

assert.sameValue(JSON.stringify(Infinity), 'null');
assert.sameValue(JSON.stringify({key: -Infinity}), '{"key":null}');
assert.sameValue(JSON.stringify([NaN]), '[null]');

reportCompare(0, 0);