2017-10-03 23:00:31 +02:00
|
|
|
// 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
|
2018-01-05 18:26:51 +01:00
|
|
|
info: |
|
2017-10-03 23:00:31 +02:00
|
|
|
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)
|
|
|
|
{
|
2018-02-09 18:09:47 +01:00
|
|
|
if (typeof v === "bigint")
|
|
|
|
return "bigint";
|
|
|
|
else
|
|
|
|
return v;
|
2017-10-03 23:00:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.sameValue(JSON.stringify(0n, replacer), '"bigint"');
|
2018-02-09 18:09:47 +01:00
|
|
|
assert.sameValue(JSON.stringify({x: 0n}, replacer), '{"x":"bigint"}');
|