Skip to content

XS: JSON.stringify incorrectly considers object cyclic #60

@tevador

Description

@tevador

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:

  1. Save the above sample code to file "circular.js".
  2. Run ./xst -s circular.js
  3. Observe output:
Number of keys: 0
TypeError: JSON.stringify: cyclic value

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions