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