| 1 |
// Copyright (C) 2017 Robin Templeton. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: JSON serialization of BigInt values with replacer |
| 6 |
esid: sec-serializejsonproperty |
| 7 |
info: | |
| 8 |
Runtime Semantics: SerializeJSONProperty ( key, holder ) |
| 9 |
|
| 10 |
3. If ReplacerFunction is not undefined, then |
| 11 |
a. Set value to ? Call(ReplacerFunction, holder, « key, value »). |
| 12 |
features: [BigInt] |
| 13 |
---*/ |
| 14 |
|
| 15 |
function replacer(k, v) |
| 16 |
{ |
| 17 |
if (typeof v === "bigint") |
| 18 |
return "bigint"; |
| 19 |
else |
| 20 |
return v; |
| 21 |
} |
| 22 |
|
| 23 |
assert.sameValue(JSON.stringify(0n, replacer), '"bigint"'); |
| 24 |
assert.sameValue(JSON.stringify({x: 0n}, replacer), '{"x":"bigint"}'); |