replacer-array-string-object.js (921B)
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 String 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 str = new String('str'); 22 str.toString = function() { return 'toString'; }; 23 str.valueOf = function() { throw new Test262Error('should not be called'); }; 24 25 var value = { 26 str: 1, 27 toString: 2, 28 valueOf: 3, 29 }; 30 31 assert.sameValue(JSON.stringify(value, [str]), '{"toString":2}'); 32 33 reportCompare(0, 0);