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
Max call stack on objects with circular reference #1709
Comments
Any idea on how we should approach this issue? I would think that adding a cache of identifiers would be We could add an exception handler that we could explicitly configure to ignore such errors, but I think that would make for unexpected results and should affect performance negatively as well. |
We could use the https://github.com/sinonjs/samsam/blob/master/lib/samsam.js#L166-L181 |
for instance, the following is a problem:
we would do all the previous checks in sinon's deepEqual and then, if both types are object, we use samsam. as a side note, both of @fatso83's points would be introduced by using samsam's deepEqual as it uses a path cache. that being said, this does fix the problem, from the test cases i've written. |
I agree that the first line of your example is a problem. I don't understand why the second line would be considered a problem. Could you help me understand it? Recently, the We are working towards re-releasing There's nothing to stop us from fixing issues in Since you understand the problem well, perhaps you could create issues on https://github.com/sinonjs/samsam for where |
@mroderick apologies for the confusion, the second line was just there for comparative reasons. Interesting about the breaking change. Would be a good time to get I'll create the issue over on samsam to get some feedback. |
Thanks 🍨 |
@scripter-co do you want to do the honours of importing Would you mind writing a test that shows that it can now deal with circular structures? |
@mroderick of course 👍 |
@mroderick I've added a PR. It's a bit of a weird one, Edit: In fact, still seems a case where it can get into a loop when there is a matcher provided. Going to take a further look. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@scripter-co this is a rather long running issue. Would you mind if someone else finishes it? |
I'll try take a look in the next few days but sure, if someone else can look into it I don't mind. |
This has been fixed with #1853 and published to NPM as |
mocha
What did you expect to happen?
Sinon does not throw an error when it comes across a circular reference
What actually happens
Sinon fails with the following:
How to reproduce
https://github.com/scripter-co/sinon-circular-reference
simply:
Additional information:
I have tracked it down to here: https://github.com/sinonjs/sinon/blob/master/lib/sinon/util/core/deep-equal.js#L84. The problem is that when you are comparing the two objects, you will always fall into this condition and continue to send
a[prop], b[prop]
toarguments[2]
. It's worth nothing that if the circular reference key names are different, this problem does not exists due toprop
not existing on botha
andb
.The use case that this is a problem is when using React within something like JSDOM. React adds a
__reactInternalInstance$ID_HERE
(e.g.__reactInternalInstance$upckzz9n7m
) key to elements that it renders on the page. Within this key you get a circular reference and therefore under the correct conditions, you will get this error.The text was updated successfully, but these errors were encountered: