-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robin Templeton
committed
Sep 26, 2017
1 parent
3b7ffd2
commit 79b0b96
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (C) 2017 Robin Templeton. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
description: BigInt stringify order of steps | ||
esid: sec-serializejsonproperty | ||
info: > | ||
Runtime Semantics: SerializeJSONProperty ( key, holder ) | ||
2. If Type(value) is Object or BigInt, then | ||
a. Let toJSON be ? GetGetV(value, "toJSON"). | ||
b. If IsCallable(toJSON) is true, then | ||
i. Set value to ? Call(toJSON, value, « key »). | ||
3. If ReplacerFunction is not undefined, then | ||
a. Set value to ? Call(ReplacerFunction, holder, « key, value »). | ||
4. If Type(value) is Object, then | ||
a. If value has a [[NumberData]] internal slot, then | ||
i. Set value to ? ToNumber(value). | ||
[...] | ||
10. If Type(value) is BigInt, throw a TypeError exception | ||
features: [BigInt, arrow-function] | ||
---*/ | ||
|
||
let step = 0; | ||
|
||
function replacer(k, v) | ||
{ | ||
assert.sameValue(step++, 1); | ||
if (v === 1n) { | ||
let x = Object(1); | ||
x.valueOf = function () { assert.sameValue(step++, 2); return 2n; }; | ||
return x; | ||
} else { | ||
return v; | ||
} | ||
} | ||
|
||
BigInt.prototype.toJSON = function () { assert.sameValue(step++, 0); return 1n; }; | ||
assert.throws(TypeError, () => JSON.stringify(0n, replacer)); | ||
assert.sameValue(step, 3); |