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

Issue 73 - primitive wrapper support #75

Merged
merged 5 commits into from
Apr 29, 2022

Conversation

planttheidea
Copy link
Owner

Reason for change

Using primitive wrappers, such as new Number(1) instead of just 1 provide false success comparisons, which can cause edge case incorrectness.

Change

As the penultimate fallback for object comparisons, check if the valueOf on the object is not the same as the standard Object.prototype.valueOf. For primitive wrappers (Number, Boolean, etc.), these are different, therefore allowing appropriate comparisons.

Should fix #73 .

@@ -87,6 +101,10 @@ export function createComparator(createIsEqual?: EqualityComparatorCreator): Equ
}
}

if (a.valueOf !== valueOf || b.valueOf !== valueOf) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real change, doing SMZ if the valueOf differs from the default on all objects.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I'm sure you could tell from the issue I filed, I was really wondering how/where you could possibly detect this without a large number of checks. This is a clever solution, I like it a lot.

@planttheidea planttheidea merged commit 648b235 into master Apr 29, 2022
@planttheidea planttheidea deleted the issue-73-primitive-wrapper-support branch April 29, 2022 13:53
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

Successfully merging this pull request may close these issues.

Primitive wrappers are always considered equal
2 participants