Sample code:
let x = {};
x.a = x;
try {
JSON.stringify(x);
} catch(e) {}
delete x.a;
print('Number of keys: ' + Object.keys(x).length);
JSON.stringify(x); //throws here
It seems like the engine 'remembers' that an object had a circular reference and subsequent calls to JSON.stringify fail even if the object is not circular anymore.
Steps to reproduce:
- Save the above sample code to file "circular.js".
- Run
./xst -s circular.js
- Observe output:
Number of keys: 0
TypeError: JSON.stringify: cyclic value