Repository navigation
Conversation
Previously, boxed positive/negative zeroes and NaN values had the same equality semantics as primitives, which is incorrect for Java. Among other things, this now allows boxed Doubles to be correctly found in collections via Object.equals() calls. Fixes gwtproject#9568
This reverts commit de00214.
This reverts commit b6d3d50. The optimizer can rewrite Object/Object comparisons to Double/String and the like, which violates these assumptions. Arguably, we should instead statically evaluate those comparisons to false, but cases where the optimization loop ends early could still leave these intact.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, boxed positive/negative zeroes and NaN values had the same equality semantics as primitives, which is incorrect for boxed Double/Float values in Java.
Among other things, this now allows boxed Double/Float values to be correctly found in collections via Object.equals() calls.
This also modifies how Java == is handled for Double instances - arguably this is still "wrong", in the same way that it is wrong for String to be compared via == and be true, but it happens to reflect the new reality that JEP 401 will bring.
By itself, this cases a small size regression, as a method call is larger than ===, but nearly all of the JS === compares are wrapped with maskUndefined, so we could fold that in for these specific cases, since we must have a method call anyway. Doing so brings this change from about +0.1% increase to -0.01% decrease.
BoxedDoubleIdentityTest was generated by an LLM based on the range of valid Java comparisons and their JS counterparts, the rest was written by hand.
Js's Object.is() would be a more concise fix for this, but has subtle int/float bugs until HtmlUnit 5.6, we can consider a slightly smaller approach once we update that far.
Fixes #9568