tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

value-bigint-order.js (1325B)


      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: BigInt stringify order of steps
      6 esid: sec-serializejsonproperty
      7 info: |
      8  Runtime Semantics: SerializeJSONProperty ( key, holder )
      9 
     10  2. If Type(value) is Object or BigInt, then
     11    a. Let toJSON be ? GetGetV(value, "toJSON").
     12    b. If IsCallable(toJSON) is true, then
     13      i. Set value to ? Call(toJSON, value, « key »).
     14  3. If ReplacerFunction is not undefined, then
     15    a. Set value to ? Call(ReplacerFunction, holder, « key, value »).
     16  4. If Type(value) is Object, then
     17    [...]
     18    d. Else if value has a [[BigIntData]] internal slot, then
     19      i. Set value to value.[[BigIntData]].
     20  [...]
     21  10. If Type(value) is BigInt, throw a TypeError exception
     22 features: [BigInt, arrow-function]
     23 ---*/
     24 
     25 let step;
     26 
     27 function replacer(x, k, v)
     28 {
     29  assert.sameValue(step++, 1);
     30  assert.sameValue(v, 1n);
     31  return x;
     32 }
     33 
     34 BigInt.prototype.toJSON = function () { assert.sameValue(step++, 0); return 1n; };
     35 
     36 step = 0;
     37 assert.throws(TypeError, () => JSON.stringify(0n, (k, v) => replacer(2n, k, v)));
     38 assert.sameValue(step, 2);
     39 
     40 step = 0;
     41 assert.throws(TypeError, () => JSON.stringify(0n, (k, v) => replacer(Object(2n), k, v)));
     42 assert.sameValue(step, 2);
     43 
     44 reportCompare(0, 0);