Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular References are not handled #25

Closed
gilbert opened this issue Jul 26, 2011 · 5 comments
Closed

Circular References are not handled #25

gilbert opened this issue Jul 26, 2011 · 5 comments

Comments

@gilbert
Copy link
Contributor

gilbert commented Jul 26, 2011

The call stack maximum exceeds instead. Example:

a = { val:1 };
b = { a:a };
a.circular = b;
@remy
Copy link
Owner

remy commented Jul 26, 2011

It's failing because it's trying to stringify the object back out to you - which is where the stack exception is kicking in.

I guess the best I could do is to limit the depth of the stringify action - but that doesn't seem like a very elegant solution. Not quite sure there is a solution...! :-\

@benatkin
Copy link

All you need to do to eliminate circular references is to traverse each node of the tree, keep a stack of the parent nodes, and for each node check to see if there is a copy (===) in the parent nodes. The tricky part that made me think it wasn't simple earlier was keeping a stack of the parent nodes. It doesn't sound so tricky now.

@substack's js-traverse does this. You could use that to make a deep copy of an object with circular references scrubbed. It's in the README.

@gilbert
Copy link
Contributor Author

gilbert commented Jul 28, 2011

Is a fix in the works for this, or should I fork and submit a patch?

@remy
Copy link
Owner

remy commented Jul 30, 2011

@mindeavor feel free to send a pull request - I'll certainly want to fix it - but I don't have the time right this mo.

@remy
Copy link
Owner

remy commented Aug 6, 2011

live and fixed (thank you!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants