value-object-circular.js (974B)
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-serializejsonobject 5 description: > 6 Circular object 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 [...] 18 c. Return ? SerializeJSONObject(value). 19 20 SerializeJSONObject ( value ) 21 22 1. If stack contains value, throw a TypeError exception because the structure is cyclical. 23 ---*/ 24 25 var direct = {}; 26 direct.prop = direct; 27 28 assert.throws(TypeError, function() { 29 JSON.stringify(direct); 30 }); 31 32 var indirect = { 33 p1: { 34 p2: { 35 get p3() { 36 return indirect; 37 }, 38 }, 39 }, 40 }; 41 42 assert.throws(TypeError, function() { 43 JSON.stringify(indirect); 44 }); 45 46 reportCompare(0, 0);