You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've checked with Node.js 0.12.0, and their assert.deepEqual() is able to compare objects with circular references, without running on forever or hitting stack limits.
@kuraga that's not a very helpful thing to suggest. If you are in urgent need for a fix, you could always submit a PR that includes the fix yourself, or find an alternative project that has the functionality you need.
There's probably a better approach, but I would probably keep track the objects I have visited whilst traversing the structure. If I ever encounter the same object twice, then I would stop early.
Alternatively, a simpler approach could be to just have a maximum depth, stopping if traversal reaches a depth of maybe 50 or 100 (or some other reasonable number). This isn't a guarantee that the structure is circular, but would stop the stack errors.
It'll mean we might be able to adjust the algorithm to take advantage of tail calls, so we won't have stack overflow issues with deep recursion. Probably still don't want to have infinite loops, of course.
@kuraga it's probably fine, and possible the best. I'm just highlighting that we'll have new techniques available to us in the near future that may help for this sort of thing.
Activity
kuraga commentedon Jan 4, 2016
👍
kuraga commentedon Jan 30, 2016
@substack don't you know how to fix that?..
jokeyrhyme commentedon Jan 30, 2016
@kuraga that's not a very helpful thing to suggest. If you are in urgent need for a fix, you could always submit a PR that includes the fix yourself, or find an alternative project that has the functionality you need.
kuraga commentedon Jan 30, 2016
@jokeyrhyme you're right but maybe, do you (or Substack) know some approach to handle circular deps? I say about an advice not code...
jokeyrhyme commentedon Jan 30, 2016
There's probably a better approach, but I would probably keep track the objects I have visited whilst traversing the structure. If I ever encounter the same object twice, then I would stop early.
Alternatively, a simpler approach could be to just have a maximum depth, stopping if traversal reaches a depth of maybe 50 or 100 (or some other reasonable number). This isn't a guarantee that the structure is circular, but would stop the stack errors.
jokeyrhyme commentedon Jan 30, 2016
Also, I came across this, but I haven't tested it to see if it has the same problem: https://github.com/chaijs/deep-eql
kuraga commentedon Jan 30, 2016
Thanks!
deep-eqlhasn't an exception there but it returns a wrong result.kuraga commentedon Apr 27, 2016
Huh! NodeJS itself isn't exception, too! nodejs/node#6416
kuraga commentedon Apr 30, 2016
Update: Solved in NodeJS, nodejs/node@d3aafd0
jokeyrhyme commentedon Apr 30, 2016
This may or may not change again once we have tail call optimisation in v8.
kuraga commentedon Apr 30, 2016
@jokeyrhyme what do you mean?
jokeyrhyme commentedon Apr 30, 2016
It'll mean we might be able to adjust the algorithm to take advantage of tail calls, so we won't have stack overflow issues with deep recursion. Probably still don't want to have infinite loops, of course.
kuraga commentedon Apr 30, 2016
Why NodeJS solution is not good?
jokeyrhyme commentedon Apr 30, 2016
@kuraga it's probably fine, and possible the best. I'm just highlighting that we'll have new techniques available to us in the near future that may help for this sort of thing.
ljharb commentedon Aug 3, 2019
The solution to this issue is to implement nodejs/node@d3aafd0, which will fix both this issue and tape-testing/tape#434.