replacer-array-number.js (772B)
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 primitives from replacer array to strings. 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 d. Else if Type(v) is Number, set item to ! ToString(v). 17 ---*/ 18 19 var obj = { 20 '0': 0, 21 '1': 1, 22 '-4': 2, 23 '0.3': 3, 24 '-Infinity': 4, 25 'NaN': 5, 26 }; 27 28 var replacer = [ 29 -0, 30 1, 31 -4, 32 0.3, 33 -Infinity, 34 NaN, 35 ]; 36 37 assert.sameValue( 38 JSON.stringify(obj, replacer), 39 JSON.stringify(obj) 40 ); 41 42 reportCompare(0, 0);