value-array-circular.js (963B)
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-serializejsonarray 5 description: > 6 Circular array value throws a TypeError. 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 10. If Type(value) is Object and IsCallable(value) is false, then 17 a. Let isArray be ? IsArray(value). 18 b. If isArray is true, return ? SerializeJSONArray(value). 19 20 SerializeJSONArray ( value ) 21 22 1. If stack contains value, throw a TypeError exception because the structure is cyclical. 23 ---*/ 24 25 var direct = []; 26 direct.push(direct); 27 28 assert.throws(TypeError, function() { 29 JSON.stringify(direct); 30 }); 31 32 var indirect = []; 33 indirect.push([[indirect]]); 34 35 assert.throws(TypeError, function() { 36 JSON.stringify(indirect); 37 }); 38 39 reportCompare(0, 0);