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

Verify immutability with Object.freeze #10

Open
curran opened this issue Apr 10, 2019 · 1 comment
Open

Verify immutability with Object.freeze #10

curran opened this issue Apr 10, 2019 · 1 comment

Comments

@curran
Copy link
Contributor

curran commented Apr 10, 2019

This issue is about improving the approach taken in the tests for checking immutability.

A quote from the original discussion of this idea in #8:

A better way to verify immutability would be to recursively call Object.freeze on all inputs to all the functions in all tests. The nice thing about that approach is that if any tests inappropriately modify data, the stack trace will point to the exact source of the error. If we do that, we probably shouldn't need special immutability test cases at all. --@josephg

@josephg
Copy link
Member

josephg commented Jul 11, 2020

This is a good idea, but its worth noting that modifying something frozen with Object.freeze will only throw an exception in a strict context. I think this should be ok since the json1 library is in a strict context now we're using typescript; but I'm still slightly nervous that the tests might silently pass.

I've inlined a small fuzzer into test.js which uses this approach. (It should probably be moved out)

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

2 participants