tor-browser

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

replacer-array-order.js (922B)


      1 // Copyright (C) 2019 Aleksey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: sec-serializejsonobject
      5 description: >
      6  Keys order of serialized objects is determined by replacer array.
      7 info: |
      8  JSON.stringify ( value [ , replacer [ , space ] ] )
      9 
     10  [...]
     11  12. Return ? SerializeJSONProperty(the empty String, wrapper).
     12 
     13  SerializeJSONProperty ( key, holder )
     14 
     15  [...]
     16  10. If Type(value) is Object and IsCallable(value) is false, then
     17    [...]
     18    c. Return ? SerializeJSONObject(value).
     19 
     20  SerializeJSONObject ( value )
     21 
     22  [...]
     23  5. If PropertyList is not undefined, then
     24    a. Let K be PropertyList.
     25 ---*/
     26 
     27 var replacer = ['c', 'b', 'a'];
     28 
     29 assert.sameValue(
     30  JSON.stringify({b: 1, a: 2, c: 3}, replacer),
     31  '{"c":3,"b":1,"a":2}'
     32 );
     33 
     34 assert.sameValue(
     35  JSON.stringify({a: {b: 2, c: 3}}, replacer),
     36  '{"a":{"c":3,"b":2}}'
     37 );
     38 
     39 reportCompare(0, 0);