tor-browser

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

replacer-array-number-object.js (917B)


      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-json.stringify
      5 description: >
      6  Converts Number objects from replacer array to primitives using ToString.
      7 info: |
      8  JSON.stringify ( value [ , replacer [ , space ] ] )
      9 
     10  [...]
     11  4. If Type(replacer) is Object, then
     12    [...]
     13    4. Repeat, while k < len,
     14      a. Let v be ? Get(replacer, ! ToString(k)).
     15      [...]
     16      e. Else if Type(v) is Object, then
     17        i. If v has a [[StringData]] or [[NumberData]] internal slot,
     18        set item to ? ToString(v).
     19 ---*/
     20 
     21 var num = new Number(10);
     22 num.toString = function() { return 'toString'; };
     23 num.valueOf = function() { throw new Test262Error('should not be called'); };
     24 
     25 var value = {
     26  10: 1,
     27  toString: 2,
     28  valueOf: 3,
     29 };
     30 
     31 assert.sameValue(JSON.stringify(value, [num]), '{"toString":2}');
     32 
     33 reportCompare(0, 0);