summaryrefslogtreecommitdiff
path: root/test/built-ins/JSON/stringify/bigint-replacer.js
blob: 9e17698867d6dec789c211d316d5ecf6fe612c3a (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
// Copyright (C) 2017 Robin Templeton. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: JSON serialization of BigInt values with replacer
esid: sec-serializejsonproperty
info: >
  Runtime Semantics: SerializeJSONProperty ( key, holder )

  3. If ReplacerFunction is not undefined, then
    a. Set value to ? Call(ReplacerFunction, holder, « key, value »).
features: [BigInt]
---*/

function replacer(k, v)
{
    if (typeof v === "bigint")
        return "bigint";
    else
        return v;
}

assert.sameValue(JSON.stringify(0n, replacer), '"bigint"');
assert.sameValue(JSON.stringify({x: 0n}, replacer), '{"x":"bigint"}');