| function shouldBe(actual, expected) |
| throw new Error('bad value: ' + actual); |
| function shouldThrow(func, errorMessage) { |
| throw new Error('not thrown'); |
| if (String(error) !== errorMessage) |
| throw new Error(`bad error: ${String(error)}`); |
| BigInt.prototype.toJSON = function () { |
| return Number(String(this)); |
| shouldBe(JSON.stringify(0n), `0`); |
| shouldBe(JSON.stringify([0n]), `[0]`); |
| shouldBe(JSON.stringify({hello:0n}), `{"hello":0}`); |
| var bigIntObject = Object(0n); |
| shouldBe(JSON.stringify(bigIntObject), `0`); |
| shouldBe(JSON.stringify([bigIntObject]), `[0]`); |
| shouldBe(JSON.stringify({hello:bigIntObject}), `{"hello":0}`); |