space-number.js (876B)
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-json.stringify 5 description: > 6 Numeric space parameter (integer in range 0..10) is equivalent 7 to string of spaces of that length. 8 info: | 9 JSON.stringify ( value [ , replacer [ , space ] ] ) 10 11 [...] 12 6. If Type(space) is Number, then 13 [...] 14 b. If space < 1, let gap be the empty String; otherwise let gap be the 15 String value containing space occurrences of the code unit 0x0020 (SPACE). 16 ---*/ 17 18 var obj = { 19 a1: { 20 b1: [1, 2, 3, 4], 21 b2: { 22 c1: 1, 23 c2: 2, 24 }, 25 }, 26 a2: 'a2', 27 }; 28 29 assert.sameValue( 30 JSON.stringify(obj, null, 0), 31 JSON.stringify(obj, null, '') 32 ); 33 34 assert.sameValue( 35 JSON.stringify(obj, null, 4), 36 JSON.stringify(obj, null, ' ') // 4 spaces 37 ); 38 39 reportCompare(0, 0);