-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Simplify the number unboxing logic #43271
Conversation
7356423
to
4d7e20a
Compare
This stops being a good idea once i64/u64 support is added, though, because those aren't Number |
longs will have to be handled specially in any case. This preserves the current behavior while simplifying code. |
63faddc
to
576cd53
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than my comments, seems fine - let's wait until my bindings optimizations are landed before landing this since they will conflict.
....Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/Runtime.cs
Show resolved
Hide resolved
if (d >= int.MinValue && d <= int.MaxValue) | ||
return (int)d; | ||
else if (d >= uint.MinValue && d <= uint.MaxValue) | ||
return (uint)d; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this. We're arbitrarily deciding whether a number should be signed or not based on ranges, this is going to cause reflective code like x = (int)obj
to break for no obvious reason. I guess we could tell the end-user to just use Convert.xxx
methods...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like it either, this works in more cases than the current code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, this code is only called by the number boxing code on the js side which does an even less effective check and would require another method binding to achieve the same result (while this removes one),
blocked against #41808 which is prefered |
From the js binding perspective all of these types are numbers (see the method binding) so treat them that way.