replacer-function-result-undefined.js (1068B)
1 // Copyright (C) 2012 Ecma International. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-serializejsonproperty 5 description: > 6 Result of replacer function is stringified. 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 3. If ReplacerFunction is not undefined, then 17 a. Set value to ? Call(ReplacerFunction, holder, « key, value »). 18 ---*/ 19 20 assert.sameValue(JSON.stringify(1, function() {}), undefined); 21 assert.sameValue(JSON.stringify([1], function() {}), undefined); 22 assert.sameValue(JSON.stringify({prop: 1}, function() {}), undefined); 23 24 var replacer = function(_key, value) { 25 return value === 1 ? undefined : value; 26 }; 27 28 assert.sameValue(JSON.stringify([1], replacer), '[null]'); 29 assert.sameValue(JSON.stringify({prop: 1}, replacer), '{}'); 30 assert.sameValue(JSON.stringify({ 31 a: { 32 b: [1], 33 }, 34 }, replacer), '{"a":{"b":[null]}}'); 35 36 reportCompare(0, 0);